Class Selection
Wraps some common Selection/Range functionality into a simple object
Properties
The actual Selection/Range object
ALL
- static object
The selector to use when looking for Nodes to cache the value of: [style],font[face]
A Node instance of the parentNode of the anchorNode of the range
The offset from the range object
A Node instance of the actual textNode of the range.
BLOCKS
- static object
The selector to use when looking for block level items.
The id used to wrap the inner space of the cursor position
CURSOR
- static object
The default HTML used to focus the cursor..
The default tag to use when creating elements: span
A Node instance of the parentNode of the focusNode of the range
The offset from the range object
A Node instance of the actual textNode of the range.
Flag to show if the range is collapsed or not
Regular Expression to determine if a string has a character in it
Regular Expression to remove all HTML from a string
REG_NON
- static object
Regular Expression to determine if a string has a non-character in it
TMP
- static object
The temporary fontname applied to a selection to retrieve their values: yui-tmp
Methods
private
HTMLElement
_swap
(
n
,
tag
)
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
private
HTMLElement
_wrap
(
n
,
tag
)
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
private
static
void
_wrapBlock
(
)
Wraps an array of elements in a Block level tag
static
void
cleanCursor
(
)
Called from Editor keydown to remove the "extra" space before the cursor.
RangeObject
createRange
(
)
Wrapper for the different range creation methods.
static
void
filter
(
)
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.
static
void
filterBlocks
(
)
Method attempts to replace all "orphined" text nodes in the main body by wrapping them with a
. Called from filter.
Node
focusCursor
(
)
Gets a stored cursor and focuses it for editing, must be called sometime after setCursor
Node
getCursor
(
)
Get the placeholder in the DOM at the current cursor position.
NodeList
getSelected
(
)
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.
static
String
getText
(
node
)
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
Node
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:
-
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.
Node
insertContent
(
html
)
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.
Y.Selection
remove
(
)
Destroy the range.
Chainable: This method is chainable.
Node
removeCursor
(
keep
)
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.
Node
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.
- Parameters:
-
se
<String>
The string to search for.
-
re
<String>
The string of HTML to replace it with.
- Returns:
Node
- The node inserted.
static
Node
resolve
(
n
)
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
Y.Selection
selectNode
(
node
,
collapse
)
Select a Node (hilighting it).
- Parameters:
-
node
<Node>
The node to select
-
collapse
<Boolean>
Should the range be collapsed after insertion. default: false
Chainable: This method is chainable.
Node
setCursor
(
)
Put a placeholder in the DOM at the current cursor position.
String
toString
(
)
Generic toString for logging.
static
String
unfilter
(
)
Undoes what filter does enough to return the HTML from the Editor, then re-applies the filter.
- Returns:
String
- The filtered HTML
NodeList
wrapContent
(
tag
)
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.