Giter VIP home page Giter VIP logo

selection.js's Introduction

selection.js

A simple (4kb) library for manipulating cursor selections across all browsers:

  • Modern browsers, using DOM Selection/Ranges
  • IE5โ€”8, using TextRanges

This library adds a window.Selection object with static methods for retrieving, setting, and clearing a user selection. By manipulating the DOM, you can replicate most DOM Range functionality (like extract/clone/deleteContents, etc.) or just implement what your application actually needs.

Usage

Include "selection.js" in your project. The global window.Selection object is has the following static methods. As a shorthand, new Selection(window) instantiates an object with the same methods, but the window argument is no longer necessary.

  • Selection.supported -- This property is true if the browser supports the Selection object.
  • Selection.hasSelection(window) -- Returns true if anything is currently selected.
  • Selection.getOrigin(window) -- Returns an array [anchorNode, anchorOffset] of the current selection's starting anchor (in IE, returns leftmost anchor)
  • Selection.getFocus(window) -- Returns an array [focusNode, focusOffset] of the current selection's focus anchor (in IE, returns rightmost anchor)
  • Selection.getStart(window) -- Returns an array [node, offset] for the leftmost anchor.
  • Selection.getEnd(window) -- Returns an array [node, offset] for the rightmost anchor.
  • Selection.setSelection(window, originNode, originOffset, focusNode, focusOffset) -- Sets the selection to include the new origin anchor and focus anchor (in IE, origin will be leftmost anchor, focus rightmost)
  • Selection.clearSelection(window) -- Deselects all content.

License

Released under the MIT license.

selection.js's People

Contributors

joshduck avatar tcr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.