# Yahoo! UI Library

### TreeView Widget 2.8.2r1

Yahoo! UI Library > treeview > YAHOO.widget.Node
Search:
Filters
Show Private Show Protected Show Deprecated

## Class YAHOO.widget.Node - uses YAHOO.util.EventProvider

Known Subclasses:
  YAHOO.widget.TextNode YAHOO.widget.HTMLNode YAHOO.widget.RootNode

The base class for all tree nodes. The node's presentation and behavior in response to mouse events is handled in Node subclasses.

### Constructor

YAHOO.widget.Node `( oData , oParent , expanded )`

Parameters:
  `oData <object>` a string or object containing the data that will be used to render this node, and any custom attributes that should be stored with the node (which is available in noderef.data). All values in oData will be used to set equally named properties in the node as long as the node does have such properties, they are not undefined, private or functions, the rest of the values will be stored in noderef.data
  `oParent <Node>` this node's parent node
  `expanded <boolean>` the initial expanded/collapsed state (deprecated, use oData.expanded)

### Properties

#### _dynLoad - `private boolean`

We can set the node up to call an external method to get the child data dynamically.

#### _focusedItem - `private DOM element`

DOM element that actually got the browser focus

#### _focusHighlightedItems - `private Array of DOM elements`

array of items that had the focus set on them so that they can be cleaned when focus is lost

#### _type - `private string`

The node type
Default Value: "Node"

#### children - `Node[]`

This node's child node collection.

#### childrenRendered - `boolean`

This flag is set to true when the html is generated for this node's children, and set to false when new children are added.

#### className - `string`

User-defined className to be added to the Node
Default Value: null

#### contentElId - `string`

The generated id that will contain the data passed in by the implementer.

#### contentStyle - `string`

The CSS class for the html content container. Defaults to ygtvhtml, but can be overridden to provide a custom presentation for a specific node.

#### data - `object`

The data linked to this node. This can be any object or primitive value, and the data can be used in getNodeHtml().

#### dataLoader - `function`

Function to execute when we need to get this node's child data.

#### depth - `int`

The depth of this node. We start at -1 for the root node.

#### dynamicLoadComplete - `boolean`

Dynamically loaded nodes only fetch the data the first time they are expanded. This flag is set to true once the data has been fetched.

#### editable - `boolean`

Signals if the label is editable. (Ignored on TextNodes with href set.)

#### enableHighlight - `boolean`

Enables node highlighting. If true, the node can be highlighted and/or propagate highlighting
Default Value: true

#### expanded - `boolean`

The node's expanded/collapsed state

#### hasIcon - `boolean`

The toggle/branch icon will not show if this is set to false. This could be useful if the implementer wants to have the child contain extra info about the parent, rather than an actual node.

#### highlightState - `integer`

Stores the highlight state. Can be any of:

- 0 - not highlighted
- 1 - highlighted
- 2 - some children highlighted

Default Value: 0

#### iconMode - `int`

Used to configure what happens when a dynamic load node is expanded and we discover that it does not have children. By default, it is treated as if it still could have children (plus/minus icon). Set iconMode to have it display like a leaf node instead.

#### index - `int`

The index for this instance obtained from global counter in YAHOO.widget.TreeView.

#### isLeaf - `boolean`

If true, the node will alway be rendered as a leaf node. This can be used to override the presentation when dynamically loading the entire tree. Setting this to true also disables the dynamic load call for the node.
Default Value: false

#### isLoading - `boolean`

This is true for dynamically loading nodes while waiting for the callback to return.

#### multiExpand - `boolean`

Can multiple children be expanded at once?

#### nextSibling - `Node`

This node's next sibling

#### nowrap - `boolean`

Specifies whether or not the content area of the node should be allowed to wrap.
Default Value: false

#### parent - `Node`

Parent node

#### previousSibling - `Node`

This node's previous sibling

#### propagateHighlightDown - `boolean`

Tells whether highlighting will be propagated down to the children of the clicked node
Default Value: false

#### propagateHighlightUp - `boolean`

Tells whether highlighting will be propagated up to the parents of the clicked node
Default Value: false

#### renderHidden - `boolean`

Should we render children for a collapsed node? It is possible that the implementer will want to render the hidden data... @todo verify that we need this, and implement it if we do.

#### tree - `TreeView`

Tree instance this node is part of

#### Properties inherited from YAHOO.util.EventProvider:

`__yui_events, __yui_subscribers`

### Methods

#### _canHaveFocus

`private boolean _canHaveFocus ( )`
Returns true if there are any elements in the node that can accept the real actual browser focus

Returns: `boolean`
  success

#### _childrenHighlighted

`private void _childrenHighlighted ( )`
Checks whether all or part of the children of a node are highlighted and sets the node highlight to full, none or partial highlight. If set to propagate it will further call the parent

#### _removeFocus

`private void _removeFocus ( )`
Removes the focus of previously selected Node

#### _setHighlightClassName

`private void _setHighlightClassName ( )`
Changes the classNames on the toggle and content containers to reflect the current highlighting

#### appendChild

`private Node appendChild ( childNode )`
Appends a node to the child collection.

Parameters:
  `childNode <Node>` the new node

Returns: `Node`
  the child node

#### appendTo

`Node appendTo ( parentNode )`
Appends this node to the supplied node's child collection

Parameters:
  `parentNode <Node>` the node to append to.

Returns: `Node`
  The appended node

#### applyParent

`boolean applyParent ( parentNode )`
Certain properties for the node cannot be set until the parent is known. This is called after the node is inserted into a tree. the parent is also applied to this node's children in order to make it possible to move a branch from one tree to another.

Parameters:
  `parentNode <Node>` this node's parent node

Returns: `boolean`
  true if the application was successful

#### collapse

`void collapse ( )`
Hides this nodes children (creating them if necessary), changes the toggle style.

#### collapseAll

`void collapseAll ( )`
Recursively collapses all of this node's children.

#### completeRender

`string completeRender ( )`
Called when we know we have all the child data.

Returns: `string`
  children html

#### destroyEditorContents

`void destroyEditorContents ( editorData )`
Node-specific destroy function to empty the contents of the inline editor panel. This function is the worst case alternative that will purge all possible events and remove the editor contents. Method Event.purgeElement is somewhat costly so if it can be replaced by specifc Event.removeListeners, it is better to do so.

Parameters:
  `editorData <YAHOO.widget.TreeView.editorData>` a shortcut to the static object holding editing information

#### displayEditedValue

`void displayEditedValue ( value , editorData )`
Finally displays the newly edited value(s) in the tree. Should be overridden by each node type.

Parameters:
  `value <any>` value to be displayed and stored in the node
  `editorData <YAHOO.widget.TreeView.editorData>` a shortcut to the static object holding editing information

#### editNode

`void editNode ( )`
pops up the contents editor, if there is one and the node is declared editable

#### expand

`void expand ( )`
Shows this nodes children (creating them if necessary), changes the toggle style, and collapses its siblings if multiExpand is not set.

#### expandAll

`void expandAll ( )`
Recursively expands all of this node's children.

#### fillEditorContainer

`fillEditorContainer ( editorData )`
Placeholder for a function that should provide the inline node label editor. Leaving it set to null will indicate that this node type is not editable. It should be overridden by nodes that provide inline editing. The Node-specific editing element (input box, textarea or whatever) should be inserted into editorData.inputContainer.

Parameters:
  `editorData <YAHOO.widget.TreeView.editorData>` a shortcut to the static object holding editing information

Returns: ``
  void

#### focus

`boolean focus ( )`
Sets the focus on the node element. It will only be able to set the focus on nodes that have anchor elements in it. Toggle or branch icons have anchors and can be focused on. If will fail in nodes that have no anchor

Returns: `boolean`
  success

#### getAncestor

`Node getAncestor ( depth )`
Returns this node's ancestor at the specified depth.

Parameters:
  `depth <int>` the depth of the ancestor.

Returns: `Node`
  the ancestor

#### getChildrenEl

`HTMLElement getChildrenEl ( )`
Returns the div that was generated for this node's children

Returns: `HTMLElement`
  this node's children div

#### getChildrenElId

`string getChildrenElId ( )`
Returns the id for this node's children div

Returns: `string`
  the element id for this node's children div

#### getChildrenHtml

`private string getChildrenHtml ( )`
Called when first rendering the tree. We always build the div that will contain this nodes children, but we don't render the children themselves unless this node is expanded.

Returns: `string`
  the children container div html and any expanded children

#### getContentEl

`HTMLElement getContentEl ( )`
Returns the outer html element for this node's content

Returns: `HTMLElement`
  the element

#### getContentHtml

`string getContentHtml ( )`
Get the markup for the contents of the node. This is designed to be overrided so that we can support different types of nodes.

Returns: `string`
  The HTML that will render the content of this node.

#### getDepthStyle

`string getDepthStyle ( depth )`
Returns the css class for the spacer at the specified depth for this node. If this node's ancestor at the specified depth has a next sibling the presentation is different than if it does not have a next sibling

Parameters:
  `depth <int>` the depth of the ancestor.

Returns: `string`
  the css class for the spacer

#### getEditorValue

`any getEditorValue ( editorData )`
Returns the value(s) from the input element(s) . Should be overridden by each node type.

Parameters:
  `editorData <YAHOO.widget.TreeView.editorData>` a shortcut to the static object holding editing information

Returns: `any`
  value entered

#### getEl

`HTMLElement getEl ( )`
Returns this node's container html element

Returns: `HTMLElement`
  the container html element

#### getElId

`string getElId ( )`
Returns the id for this node's container div

Returns: `string`
  the element id

#### getHoverStyle

`string getHoverStyle ( )`
Returns the hover style for the icon

Returns: `string`
  the css class hover state

#### getHtml

`string getHtml ( )`
Returns the markup for this node and its children.

Returns: `string`
  the markup for this node and its expanded children.

#### getIconMode

`int getIconMode ( )`
Returns the current icon mode. This refers to the way childless dynamic load nodes appear (this comes into play only after the initial dynamic load request produced no children).

Returns: `int`
  0 for collapse style, 1 for leaf node style

#### getNodeCount

`int getNodeCount ( )`
Count of nodes in a branch

Returns: `int`
  number of nodes in the branch

#### getNodeDefinition

`Object | false getNodeDefinition ( )`
Returns an object which could be used to build a tree out of this node and its children. It can be passed to the tree constructor to reproduce this node as a tree. It will return false if the node or any children loads dynamically, regardless of whether it is loaded or not.

Returns: `Object | false`
  definition of the tree or false if the node or any children is defined as dynamic

#### getNodeHtml

`string getNodeHtml ( )`
Get the markup for the node. This may be overrided so that we can support different types of nodes.

Returns: `string`
  The HTML that will render this node.

#### getSiblings

`getSiblings ( )`
Returns a node array of this node's siblings, null if none.

Returns: ``
  Node[]

#### getStyle

`string getStyle ( )`
Returns the css style name for the toggle

Returns: `string`
  the css class for this node's toggle

#### getToggleEl

`HTMLElement getToggleEl ( )`
Returns the element that is being used for this node's toggle.

Returns: `HTMLElement`
  this node's toggle html element

#### getToggleElId

`string getToggleElId ( )`
Returns the id for this node's toggle element

Returns: `string`
  the toggel element id

#### getToggleLink

`string getToggleLink ( )`
Generates the link that will invoke this node's toggle method

Returns: `string`
  the javascript url for toggling this node

#### hasChildren

`boolean hasChildren ( checkForLazyLoad )`
Checks if this node has children. If this node is lazy-loading and the children have not been rendered, we do not know whether or not there are actual children. In most cases, we need to assume that there are children (for instance, the toggle needs to show the expandable presentation state). In other times we want to know if there are rendered children. For the latter, "checkForLazyLoad" should be false.

Parameters:
  `checkForLazyLoad <boolean>` should we check for unloaded children?

Returns: `boolean`
  true if this has children or if it might and we are checking for this condition.

#### hideChildren

`void hideChildren ( )`
Hides this node's children

#### highlight

`void highlight ( _silent )`
Turns highlighting on node.

Parameters:
  `_silent <boolean>` optional, don't fire the highlightEvent

#### init

`void init ( oData , oParent , expanded )`
Initializes this node, gets some of the properties from the parent

Parameters:
  `oData <object>` a string or object containing the data that will be used to render this node
  `oParent <Node>` this node's parent node
  `expanded <boolean>` the initial expanded/collapsed state

#### insertAfter

`Node insertAfter ( node )`
Inserts this node after the supplied node

Parameters:
  `node <Node>` the node to insert after

Returns: `Node`
  the inserted node

#### insertBefore

`Node insertBefore ( node )`
Inserts this node before this supplied node

Parameters:
  `node <Node>` the node to insert this node before

Returns: `Node`
  the inserted node

#### isChildOf

`private boolean isChildOf ( parentNode )`
Returns true if the Node is a child of supplied Node

Parameters:
  `parentNode <Node>` the Node to check

Returns: `boolean`
  The node index if this Node is a child of supplied Node, else -1.

#### isDynamic

`boolean isDynamic ( )`
Evaluates if this node's children should be loaded dynamically. Looks for the property both in this instance and the root node. If the tree is defined to load all children dynamically, the data callback function is defined in the root node

Returns: `boolean`
  true if this node's children are to be loaded dynamically

#### isRoot

`boolean isRoot ( )`
Evaluates if this node is the root node of the tree

Returns: `boolean`
  true if this is the root node

#### loadComplete

`void loadComplete ( )`
Load complete is the callback function we pass to the data provider in dynamic load situations.

#### refresh

`void refresh ( )`
Regenerates the html for this node and its children. To be used when the node is expanded and new children have been added.

#### renderChildren

`private string renderChildren ( )`
Generates the markup for the child nodes. This is not done until the node is expanded.

Returns: `string`
  the html for this node's children

#### saveEditorValue

`false or none saveEditorValue ( editorData )`
Saves the value entered into the editor.

Parameters:
  `editorData <YAHOO.widget.TreeView.editorData>` a shortcut to the static object holding editing information

Returns: `false or none`
  a return of exactly false will prevent the editor from closing

#### setDynamicLoad

`void setDynamicLoad ( fmDataLoader , iconMode )`
Configures this node for dynamically obtaining the child data when the node is first expanded. Calling it without the callback will turn off dynamic load for the node.

Parameters:
  `fmDataLoader <function>` the function that will be used to get the data.
  `iconMode <int>` configures the icon that is displayed when a dynamic load node is expanded the first time without children. By default, the "collapse" icon will be used. If set to 1, the leaf node icon will be displayed.

#### setNodesProperty

`void setNodesProperty ( name , value , refresh )`
Sets the value of property for this node and all loaded descendants. Only public and defined properties can be set, not methods. Values for unknown properties will be assigned to the refNode.data object

Parameters:
  `name <string>` Name of the property to be set
  `value <any>` value to be set
  `refresh <boolean>` if present and true, it does a refresh

#### showChildren

`void showChildren ( )`
Shows this node's children

#### toggle

`void toggle ( )`
Expands if node is collapsed, collapses otherwise.

#### toggleHighlight

`void toggleHighlight ( )`
Toggles the highlighted state of a Node

#### toString

`string toString ( )`
Node toString

Returns: `string`
  string representation of the node

#### unhighlight

`void unhighlight ( _silent )`
Turns highlighting off a node.

Parameters:
  `_silent <boolean>` optional, don't fire the highlightEvent

#### Methods inherited from YAHOO.util.EventProvider:

`createEvent, fireEvent, hasEvent, subscribe, unsubscribe, unsubscribeAll`

### Events

#### parentChange

`parentChange ( )`
The parentChange event is fired when a parent element is applied to the node. This is useful if you need to apply tree-level properties to a tree that need to happen if a node is moved from one tree to another.

Copyright © 2010 Yahoo! Inc. All rights reserved.