CzSelection - JS library

Example

Browsers support

Library tested in

API

Cz.Selection.getText(textarea)

Gets selected text. Returns String.

Cz.Selection.getLines(textarea)

Gets selected lines. Returns array of strings.

Cz.Selection.getLength(textarea)

Gets length of selected text. Returns int.


Cz.Selection.wrap(textarea, prefix, suffix, selectAll = FALSE)

Wraps selected text. Returns void.

Cz.Selection.unwrap(textarea, prefix, suffix)

Unwraps selected text. Returns void.

Cz.Selection.wrapLines(textarea, prefix, suffix, ignoreSpaces = FALSE)

Wraps selected lines. Returns void.

Cz.Selection.unwrapLines(textarea, prefix, suffix, ignoreSpaces = FALSE)

Unwraps selected lines. Returns void.


Cz.Selection.replace(textarea, text, replaceAlways = FALSE, selectReplacedText = TRUE)

Replace selected text. Returns void.

Cz.Selection.insert(textarea, text, position = undefined, selectInsertedText = FALSE)

Insert text at the position (or cursor positon/end current selection for undefined value). Returns void.

TextAreaSelection

var myTextArea = document.getElementById('my-textarea');
var selection = new Cz.TextAreaSelection(myTextArea);

selection.getText();
selection.getLines();
selection.getLength();

selection.wrap(prefix, suffix, selectAll);
selection.unwrap(prefix, suffix);
selection.wrapLines(prefix, suffix, ignoreSpaces);
selection.unwrapLines(prefix, suffix, ignoreSpaces);

selection.replace(text, replaceAlways, selectReplacedText);
selection.insert(text, position, selectInsertedText);
selection.focus();

Require CzTextAreaSelection.js file.

Source

See repository czproject/selection-js on server GitHub.com.

License

Copyright © 2013 Jan Pecha (http://janpecha.iunas.cz/) All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.