EditorSelection Class
Wraps some common Selection/Range functionality into a simple object
Constructor
EditorSelection
()
Item Index
Methods
- _swap
- _wrap
- _wrapBlock static
- cleanCursor static
- createRange
- filter static
- filterBlocks static
- focusCursor
- getCursor
- getEditorOffset
- getSelected
- getText static
- insertAtCursor
- insertContent
- remove
- removeCursor
- removeFontFamily static
- replace
- resolve static
- selectNode
- setCursor
- toString
- unfilter static
- wrapContent
Properties
- _selection
- ALL static
- anchorNode
- anchorOffset
- anchorTextNode
- BLOCKS static
- CUR_WRAPID static
- CURID static
- CURSOR static
- DEFAULT_TAG static
- focusNode
- focusOffset
- focusTextNode
- isCollapsed
- REG_CHAR static
- REG_FONTFAMILY static
- REG_NOHTML static
- REG_NON static
- ROOT static
- text
- TMP static
Methods
_swap
-
n
-
tag
Swap an element, with another element
Parameters:
-
n
HTMLElementThe node to swap
-
tag
StringThe tag to use when creating the new element.
Returns:
The new node
_wrap
-
n
-
tag
Wrap an element, with another element
Parameters:
-
n
HTMLElementThe node to wrap
-
tag
StringThe tag to use when creating the new element.
Returns:
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:
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:
getEditorOffset
-
[node]
Gets the offset of the selection for the selection within the current editor
Parameters:
-
[node]
Y.Node optionalElement 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:
A NodeList of all items in the selection.
getText
-
node
Returns the innerHTML of a node with all HTML tags removed.
Parameters:
-
node
NodeThe Node instance to remove the HTML from
Returns:
The string of text
insertAtCursor
-
html
-
node
-
offset
-
collapse
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:
Returns:
The inserted Node.
insertContent
-
html
Insert HTML at the current cursor position and return a Node instance of the newly inserted element.
Parameters:
-
html
StringThe HTML to insert.
Returns:
The inserted Node.
removeCursor
-
keep
Remove the cursor placeholder from the DOM.
Parameters:
-
keep
BooleanSetting this to true will keep the node, but remove the unique parts that make it the cursor.
Returns:
removeFontFamily
()
static
Utility method to remove dead font-family styles from an element.
replace
-
se
-
re
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.
Returns:
The node inserted.
resolve
-
n
Resolve a node from the selection object and return a Node instance
Parameters:
-
n
HTMLElementThe HTMLElement to resolve. Might be a TextNode, gives parentNode.
Returns:
The Resolved node
selectNode
-
node
-
collapse
Select a Node (hilighting it).
Parameters:
Returns:
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]
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
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
TMP
Unknown
static
The temporary fontname applied to a selection to retrieve their values: yui-tmp