Version 3.17.2
Show:

EditorSelection Class

Module: selection
Parent Module: editor

Wraps some common Selection/Range functionality into a simple object

Constructor

EditorSelection

()

Methods

_swap

(
  • n
  • tag
)
HTMLElement private

Swap an element, with another element

Parameters:

  • n HTMLElement

    The node to swap

  • tag String

    The tag to use when creating the new element.

Returns:

HTMLElement:

The new node

_wrap

(
  • n
  • tag
)
HTMLElement private

Wrap an element, with another element

Parameters:

  • n HTMLElement

    The node to wrap

  • tag String

    The tag to use when creating the new element.

Returns:

HTMLElement:

The wrapped node

_wrapBlock

() private static

Wraps an array of elements in a Block level tag

cleanCursor

() static

Called from Editor keydown to remove the "extra" space before the cursor.

createRange

() Range

Wrapper for the different range creation methods.

Returns:

Range:

filter

() static

Performs a prefilter on all nodes in the editor. Looks for nodes with a style: fontFamily or font face It then creates a dynamic class assigns it and removed the property. This is so that we don't lose the fontFamily when selecting nodes.

filterBlocks

() static

Method attempts to replace all "orphined" text nodes in the main body by wrapping them with a

. Called from filter.

focusCursor

() Node

Gets a stored cursor and focuses it for editing, must be called sometime after setCursor

Returns:

Node:

getCursor

() Node

Get the placeholder in the DOM at the current cursor position.

Returns:

Node:

getEditorOffset

(
  • [node]
)
public

Defined in editor/js/editor-selection.js:996

Available since 3.13.0

Gets the offset of the selection for the selection within the current editor

Parameters:

  • [node] Y.Node optional

    Element used to measure the offset to

Returns:

Number Number of characters the selection is from the beginning

getSelected

() NodeList

Get all the nodes in the current selection. This method will actually perform a filter first. Then it calls doc.execCommand('fontname', null, 'yui-tmp') to touch all nodes in the selection. The it compiles a list of all nodes affected by the execCommand and builds a NodeList to return.

Returns:

NodeList:

A NodeList of all items in the selection.

getText

(
  • node
)
String static

Returns the innerHTML of a node with all HTML tags removed.

Parameters:

  • node Node

    The Node instance to remove the HTML from

Returns:

String:

The string of text

insertAtCursor

(
  • html
  • node
  • offset
  • collapse
)
Node

Insert HTML at the current cursor position, this method gives you control over the text node to insert into and the offset where to put it.

Parameters:

  • html String

    The HTML to insert.

  • node Node

    The text node to break when inserting.

  • offset Number

    The left offset of the text node to break and insert the new content.

  • collapse Boolean

    Should the range be collapsed after insertion. default: false

Returns:

Node:

The inserted Node.

insertContent

(
  • html
)
Node

Insert HTML at the current cursor position and return a Node instance of the newly inserted element.

Parameters:

  • html String

    The HTML to insert.

Returns:

Node:

The inserted Node.

remove

() EditorSelection chainable

Destroy the range.

Returns:

removeCursor

(
  • keep
)
Node

Remove the cursor placeholder from the DOM.

Parameters:

  • keep Boolean

    Setting this to true will keep the node, but remove the unique parts that make it the cursor.

Returns:

Node:

removeFontFamily

() static

Utility method to remove dead font-family styles from an element.

replace

(
  • se
  • re
)
Node

Find and replace a string inside a text node and replace it with HTML focusing the node after to allow you to continue to type.

Parameters:

  • se String

    The string to search for.

  • re String

    The string of HTML to replace it with.

Returns:

Node:

The node inserted.

resolve

(
  • n
)
Node static

Resolve a node from the selection object and return a Node instance

Parameters:

  • n HTMLElement

    The HTMLElement to resolve. Might be a TextNode, gives parentNode.

Returns:

Node:

The Resolved node

selectNode

(
  • node
  • collapse
)
EditorSelection chainable

Select a Node (hilighting it).

Parameters:

  • node Node

    The node to select

  • collapse Boolean

    Should the range be collapsed after insertion. default: false

Returns:

setCursor

() Node

Put a placeholder in the DOM at the current cursor position.

Returns:

Node:

toString

() String

Generic toString for logging.

Returns:

unfilter

() String static

Undoes what filter does enough to return the HTML from the Editor, then re-applies the filter.

Returns:

String:

The filtered HTML

wrapContent

(
  • tag
)
NodeList

Get all elements inside a selection and wrap them with a new element and return a NodeList of all elements touched.

Parameters:

  • tag String

    The tag to wrap all selected items with.

Returns:

NodeList:

A NodeList of all items in the selection.

Properties

_selection

Unknown private

The actual Selection/Range object

ALL

Unknown static

The selector to use when looking for Nodes to cache the value of: [style],font[face]

anchorNode

Node

A Node instance of the parentNode of the anchorNode of the range

anchorOffset

Number

The offset from the range object

anchorTextNode

Node

A Node instance of the actual textNode of the range.

BLOCKS

Unknown static

The selector to use when looking for block level items.

CUR_WRAPID

Unknown static

The id used to wrap the inner space of the cursor position

CURID

Unknown static

The id of the outer cursor wrapper

CURSOR

Unknown static

The default HTML used to focus the cursor..

DEFAULT_TAG

Unknown static

The default tag to use when creating elements: span

focusNode

Node

A Node instance of the parentNode of the focusNode of the range

focusOffset

Number

The offset from the range object

focusTextNode

Node

A Node instance of the actual textNode of the range.

isCollapsed

Boolean

Flag to show if the range is collapsed or not

REG_CHAR

Unknown static

Regular Expression to determine if a string has a character in it

REG_FONTFAMILY

Unknown static

Regular Expression used to find dead font-family styles

REG_NOHTML

Unknown static

Regular Expression to remove all HTML from a string

REG_NON

Unknown static

Regular Expression to determine if a string has a non-character in it

ROOT

Unknown static

The default HTML element from which data will be retrieved. Default: body

text

String

Range text value

TMP

Unknown static

The temporary fontname applied to a selection to retrieve their values: yui-tmp