Documentation

Selection

get #

Returns the selection object:

  • is Boolean
    • selection is in the editor.
  • selection Boolean, Object
    • selection object
  • range Boolean, Object
    • range object
  • collapsed Boolean
    • selection is collapsed or not
  • current Boolean, Node
    • current selected node
  • parent Boolean, Node
    • parent selected node
var selection = this.app.create('selection');
var sel = selection.get();

getNodes #

Returns the array of the selected block, inline and text nodes.

var selection = this.app.create('selection');
var nodes = selection.getNodes();
var inlines = selection.getNodes({ type: 'inline' });
var nodes = selection.getNodes({ tags: ['a', 'b'] });

getElement #

Arguments
element (optional) Node, Element, Dom

Returns the first element (not text node) relative to the caret or the specified element. Return false if the editor does not have a focus.

var selection = this.app.create('selection');
var node = selection.getElement();
var node = selection.getElement(element);

getInline #

Arguments
element (optional) Node, Element, Dom

Returns the parent inline tag relative to the caret position or the specified element. If the inline tag has nested inline tags, returns the first level inline. Returns false if the parent inline tag is not found or the editor does not have a focus.

var selection = this.app.create('selection');
var node = selection.getInline();
var node = selection.getInline(element);

getBlock #

Arguments
element (optional) Node, Element, Dom

Returns the first block tag relative to the caret or the specified element. Returns false if the editor does not have a focus.

var selection = this.app.create('selection');
var node = selection.getBlock();
var node = selection.getBlock(element);

getHtml #

Returns the selection as a HTML string.

var selection = this.app.create('selection');
var html = selection.getHtml();

getText #

Returns the selection as a text string.

var selection = this.app.create('selection');
var text = selection.getText();

setRange #

Arguments
range Object

Updates the selection by the specified range object.

var selection = this.app.create('selection');
var node = document.createTextNode('My node');
var sel = selection.get();
sel.range.collapse(true);
sel.range.insertNode(node);
sel.range.setEndBefore(node);
selection.setRange(sel.range);

is #

Checks if the selection is in the editor.

var selection = this.app.create('selection');
var is = selection.is();

isAll #

Arguments
element (optional) Node, Element, Dom

Checks if all content of the element is selected.

var selection = this.app.create('selection');
var is = selection.isAll(element);

save #

Arguments
element Node, Element, Dom

Saves the current selection.

var selection = this.app.create('selection');
selection.save(this.app.$block);

restore #

Arguments
element Node, Element, Dom

Restores the selection if it was saved before by the save method.

var selection = this.app.create('selection');
selection.restore(this.app.$block);