Yahoo! UI Library

editor  3.2.0

Yahoo! UI Library > editor > Selection
Search:
 
Filters

Class Selection

Wraps some common Selection/Range functionality into a simple object

Constructor

Selection ( )

Properties

_selection - private object

The actual Selection/Range object

ALL - static object

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 - static object

The selector to use when looking for block level items.

CUR_WRAPID - static object

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

CURSOR - static object

The default HTML used to focus the cursor..

DEFAULT_TAG - static object

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 - static object

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

REG_NON - static object

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

STRIP_HTML - static object

RegExp used to strip HTML tags from a string

text - String

Range text value

TMP - static object

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

Methods

_swap

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

_wrap

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

_wrapBlock

private static void _wrapBlock ( )
Wraps an array of elements in a Block level tag

cleanCursor

static void cleanCursor ( )
Called from Editor keydown to remove the "extra" space before the cursor.

createRange

RangeObject createRange ( )
Wrapper for the different range creation methods.

filter

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.

filterBlocks

static void filterBlocks ( )
Method attempts to replace all "orphined" text nodes in the main body by wrapping them with a

. Called from filter.


focusCursor

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

getCursor

Node getCursor ( )
Get the placeholder in the DOM at the current cursor position.

getSelected

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.

getText

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

insertAtCursor

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.

insertContent

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.

remove

Y.Selection remove ( )
Destroy the range.
Chainable: This method is chainable.

removeCursor

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.

replace

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.

resolve

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

selectNode

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.

setCursor

Node setCursor ( )
Put a placeholder in the DOM at the current cursor position.

toString

String toString ( )
Generic toString for logging.

unfilter

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

wrapContent

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.


Copyright © 2010 Yahoo! Inc. All rights reserved.