Print Friendly

# Class YAHOO.widget.TextNode

Package: | YAHOO.widget
Class: | TextNode
Extends: | Node
Subclasses: | MenuNode
Defined In: | treeview.js

The default node presentation. The first parameter should be either a string that will be used as the node's label, or an object that has a string propery called label. By default, the clicking the label will toggle the expanded/collapsed state of the node. By changing the href property of the instance, this behavior can be changed so that the label will go to the specified href.

## Public Properties

Property | Defined By
--- | ---
| children : Node[] | Node
This node's child node collection.
| childrenRendered : boolean | Node
This flag is set to true when the html is generated for this node's children, and set to false when new children are ...
| data : object | Node
The data linked to this node. This can be any object or primitive value, and the data can be used in getNodeHtml().
| dataLoader : function | Node
Function to execute when we need to get this node's child data.
| depth : int | Node
The depth of this node. We start at -1 for the root node.
| dynamicLoadComplete : boolean | Node
Dynamically loaded nodes only fetch the data the first time they are expanded. This flag is set to true once the dat...
| expanded : boolean | Node
The node's expanded/collapsed state
| hasIcon : boolean | Node
The toggle/branch icon will not show if this is set to false. This could be useful if the implementer wants to have ...
| href : string | Node
The href for the node's label. If one is not specified, the href will be set so that it toggles the node.
| iconMode : int | Node
Used to configure what happens when a dynamic load node is expanded and we discover that it does not have children. ...
| index : int | Node
The index for this instance obtained from global counter in YAHOO.widget.TreeView.
| isLoading : boolean | Node
This is true for dynamically loading nodes while waiting for the callback to return.
| label : string | TextNode
The text for the label. It is assumed that the oData parameter will either be a string that will be used as the labe...
| labelElId : string | TextNode
The derived element id of the label for this node
| labelStyle : string | TextNode
The CSS class for the label href. Defaults to ygtvlabel, but can be overridden to provide a custom presentation for ...
| multiExpand : boolean | Node
Can multiple children be expanded at once?
| nextSibling : Node | Node
This node's next sibling
| parent : Node | Node
Parent node
| previousSibling : Node | Node
This node's previous sibling
| renderHidden : boolean | Node
Should we render children for a collapsed node? It is possible that the implementer will want to render the hidden d...
| target : string | Node
The label href target, defaults to current window
| tree : TreeView | Node
Tree instance this node is part of

## Public Methods

Method | Defined By
--- | ---
| TextNode(`oData {object}`, `oParent {YAHOO.widget.Node}`, `expanded {boolean}`) | TextNode
| appendTo(`parentNode {Node}`) : Node | Node
Appends this node to the supplied node's child collection
| applyParent(`Node parentNode`) : boolean | Node
Certain properties for the node cannot be set until the parent is known. This is called after the node is inserted in...
| collapse() : void | Node
Hides this nodes children (creating them if necessary), changes the toggle style.
| collapseAll() : void | Node
Recursively collapses all of this node's children.
| completeRender() : string | Node
Called when we know we have all the child data.
| expand() : void | Node
Shows this nodes children (creating them if necessary), changes the toggle style, and collapses its siblings if multi...
| expandAll() : void | Node
Recursively expands all of this node's children.
| getAncestor(`int depth`) : Node | Node
Returns this node's ancestor at the specified depth.
| getChildrenEl() : HTMLElement | Node
Returns the div that was generated for this node's children
| getChildrenElId() : string | Node
Returns the id for this node's children div
| getDepthStyle(`int depth`) : string | Node
Returns the css class for the spacer at the specified depth for this node. If this node's ancestor at the specified ...
| getEl() : HTMLElement | Node
Returns this node's container html element
| getElId() : string | Node
Returns the id for this node's container div
| getHoverStyle() : string | Node
Returns the hover style for the icon
| getHtml() : string | Node
Returns the markup for this node and its children.
| getIconMode() : int | Node
Returns the current icon mode. This refers to the way childless dynamic load nodes appear.
| getLabelEl() : object | TextNode
Returns the label element @for YAHOO.widget.TextNode
| getNodeHtml() : string | Node
Get the markup for the node. This is designed to be overrided so that we can support different types of nodes.
| getSiblings() : Node[] | Node
Returns a node array of this node's siblings, null if none.
| getStyle() : string | Node
Returns the css style name for the toggle
| getToggleEl() : HTMLElement | Node
Returns the element that is being used for this node's toggle.
| getToggleElId() : string | Node
Returns the id for this node's toggle element
| getToggleLink() : string | Node
Generates the link that will invoke this node's toggle method
| hasChildren(`checkForLazyLoad {boolean}`) : boolean | Node
Checks if this node has children. If this node is lazy-loading and the children have not been rendered, we do not kn...
| hideChildren() : void | Node
Hides this node's children
| init(`oData {object}`, `oParent {Node}`, `expanded {boolean}`) : void | Node
Initializes this node, gets some of the properties from the parent
| insertAfter(`node {Node}`) : Node | Node
Inserts this node after the supplied node
| insertBefore(`node {Node}`) : Node | Node
Inserts this node before this supplied node
| isDynamic() : boolean | Node
Evaluates if this node's children should be loaded dynamically. Looks for the property both in this instance and the...
| isRoot() : boolean | Node
Evaluates if this node is the root node of the tree
| loadComplete() : void | Node
Load complete is the callback function we pass to the data provider in dynamic load situations.
| onLabelClick(`me {Node}`) : false | TextNode
Executed when the label is clicked. Fires the labelClick custom event.
| refresh() : void | Node
Regenerates the html for this node and its children. To be used when the node is expanded and new children have been...
| setDynamicLoad(`fmDataLoader {function}`, `iconMode {int}`) : void | Node
Configures this node for dynamically obtaining the child data when the node is first expanded. Calling it without th...
| setUpLabel(`oData string`) : void | TextNode
Sets up the node label
| showChildren() : void | Node
Shows this node's children
| toString() : string | Node
Node toString
| toggle() : void | Node
Expands if node is collapsed, collapses otherwise.

## Public Events

Event | Defined By
--- | ---
| labelClick : (`YAHOO.widget.Node node`) | TextNode
Custom event that is fired when the text node label is clicked. The custom event is defined on the tree instance, so...
| parentChange : () | Node
The parentChange event is fired when a parent element is applied to the node. This is useful if you need to apply tr...

## Property Details

### children

`public Node[] children`
This node's child node collection.
This property is defined by Node.

### childrenRendered

`public boolean childrenRendered`
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.
This property is defined by Node.

### data

`public object data`
The data linked to this node. This can be any object or primitive value, and the data can be used in getNodeHtml().
This property is defined by Node.

### dataLoader

`public function dataLoader`
Function to execute when we need to get this node's child data.
This property is defined by Node.

### depth

`public int depth`
The depth of this node. We start at -1 for the root node.
This property is defined by Node.

### dynamicLoadComplete

`public boolean dynamicLoadComplete`
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.
This property is defined by Node.

### expanded

`public boolean expanded`
The node's expanded/collapsed state
This property is defined by Node.

### hasIcon

`public boolean hasIcon`
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.
This property is defined by Node.

### href

`public string href`
The href for the node's label. If one is not specified, the href will be set so that it toggles the node.
This property is defined by Node.

### iconMode

`public int iconMode`
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.
This property is defined by Node.

### index

`public int index`
The index for this instance obtained from global counter in YAHOO.widget.TreeView.
This property is defined by Node.

### isLoading

`public boolean isLoading`
This is true for dynamically loading nodes while waiting for the callback to return.
This property is defined by Node.

### label

`public string label`
The text for the label. It is assumed that the oData parameter will either be a string that will be used as the label, or an object that has a property called "label" that we will use.
This property is defined by TextNode.

### labelElId

`public string labelElId`
The derived element id of the label for this node
This property is defined by TextNode.

### labelStyle

`public string labelStyle`
The CSS class for the label href. Defaults to ygtvlabel, but can be overridden to provide a custom presentation for a specific node.
This property is defined by TextNode.

### multiExpand

`public boolean multiExpand`
Can multiple children be expanded at once?
This property is defined by Node.

### nextSibling

`public Node nextSibling`
This node's next sibling
This property is defined by Node.

### parent

`public Node parent`
Parent node
This property is defined by Node.

### previousSibling

`public Node previousSibling`
This node's previous sibling
This property is defined by Node.

### renderHidden

`public boolean renderHidden`
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.
This property is defined by Node.

### target

`public string target`
The label href target, defaults to current window
This property is defined by Node.

### tree

`public TreeView tree`
Tree instance this node is part of
This property is defined by Node.

## Constructor Details

### TextNode

`public function TextNode(`oData {object}`, `oParent {YAHOO.widget.Node}`, `expanded {boolean}`)`
Parameters:

- `{object}` : oData
  a string or object containing the data that will be used to render this node
- `{YAHOO.widget.Node}` : oParent
  this node's parent node
- `{boolean}` : expanded
  the initial expanded/collapsed state

## Method Details

### appendTo

`public function appendTo(`parentNode {Node}`)`
Appends this node to the supplied node's child collection
Parameters:

- `{Node}` : parentNode
  the node to append to.

Returns:

- `Node`
  The appended node

This method is defined by Node.

### applyParent

`public function applyParent(`Node 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

This method is defined by Node.

### collapse

`public function collapse()`
Hides this nodes children (creating them if necessary), changes the toggle style.
Parameters:

- None.

Returns:

- `void`

This method is defined by Node.

### collapseAll

`public function collapseAll()`
Recursively collapses all of this node's children.
Parameters:

- None.

Returns:

- `void`

This method is defined by Node.

### completeRender

`public function completeRender()`
Called when we know we have all the child data.
Parameters:

- None.

Returns:

- `string`
  children html

This method is defined by Node.

### expand

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

- None.

Returns:

- `void`

This method is defined by Node.

### expandAll

`public function expandAll()`
Recursively expands all of this node's children.
Parameters:

- None.

Returns:

- `void`

This method is defined by Node.

### getAncestor

`public function getAncestor(`int depth`)`
Returns this node's ancestor at the specified depth.
Parameters:

- `depth` : int
  the depth of the ancestor.

Returns:

- `Node`
  the ancestor

This method is defined by Node.

### getChildrenEl

`public function getChildrenEl()`
Returns the div that was generated for this node's children
Parameters:

- None.

Returns:

- `HTMLElement`
  this node's children div

This method is defined by Node.

### getChildrenElId

`public function getChildrenElId()`
Returns the id for this node's children div
Parameters:

- None.

Returns:

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

This method is defined by Node.

### getDepthStyle

`public function getDepthStyle(`int 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

This method is defined by Node.

### getEl

`public function getEl()`
Returns this node's container html element
Parameters:

- None.

Returns:

- `HTMLElement`
  the container html element

This method is defined by Node.

### getElId

`public function getElId()`
Returns the id for this node's container div
Parameters:

- None.

Returns:

- `string`
  the element id

This method is defined by Node.

### getHoverStyle

`public function getHoverStyle()`
Returns the hover style for the icon
Parameters:

- None.

Returns:

- `string`
  the css class hover state

This method is defined by Node.

### getHtml

`public function getHtml()`
Returns the markup for this node and its children.
Parameters:

- None.

Returns:

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

This method is defined by Node.

### getIconMode

`public function getIconMode()`
Returns the current icon mode. This refers to the way childless dynamic load nodes appear.
Parameters:

- None.

Returns:

- `int`
  0 for collapse style, 1 for leaf node style

This method is defined by Node.

### getLabelEl

`public function getLabelEl()`
Returns the label element @for YAHOO.widget.TextNode
Parameters:

- None.

Returns:

- `object`
  the element

This method is defined by TextNode.

### getNodeHtml

`public function getNodeHtml()`
Get the markup for the node. This is designed to be overrided so that we can support different types of nodes.
Parameters:

- None.

Returns:

- `string`
  The HTML that will render this node.

This method is defined by Node.

### getSiblings

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

- None.

Returns:

- `Node[]`

This method is defined by Node.

### getStyle

`public function getStyle()`
Returns the css style name for the toggle
Parameters:

- None.

Returns:

- `string`
  the css class for this node's toggle

This method is defined by Node.

### getToggleEl

`public function getToggleEl()`
Returns the element that is being used for this node's toggle.
Parameters:

- None.

Returns:

- `HTMLElement`
  this node's toggle html element

This method is defined by Node.

### getToggleElId

`public function getToggleElId()`
Returns the id for this node's toggle element
Parameters:

- None.

Returns:

- `string`
  the toggel element id

This method is defined by Node.

### getToggleLink

`public function getToggleLink()`
Generates the link that will invoke this node's toggle method
Parameters:

- None.

Returns:

- `string`
  the javascript url for toggling this node

This method is defined by Node.

### hasChildren

`public function hasChildren(`checkForLazyLoad {boolean}`)`
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:

- `{boolean}` : checkForLazyLoad
  should we check for unloaded children?

Returns:

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

This method is defined by Node.

### hideChildren

`public function hideChildren()`
Hides this node's children
Parameters:

- None.

Returns:

- `void`

This method is defined by Node.

### init

`public function init(`oData {object}`, `oParent {Node}`, `expanded {boolean}`)`
Initializes this node, gets some of the properties from the parent
Parameters:

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

Returns:

- `void`

This method is defined by Node.

### insertAfter

`public function insertAfter(`node {Node}`)`
Inserts this node after the supplied node
Parameters:

- `{Node}` : node
  the node to insert after

Returns:

- `Node`
  the inserted node

This method is defined by Node.

### insertBefore

`public function insertBefore(`node {Node}`)`
Inserts this node before this supplied node
Parameters:

- `{Node}` : node
  the node to insert this node before

Returns:

- `Node`
  the inserted node

This method is defined by Node.

### isDynamic

`public function 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
Parameters:

- None.

Returns:

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

This method is defined by Node.

### isRoot

`public function isRoot()`
Evaluates if this node is the root node of the tree
Parameters:

- None.

Returns:

- `boolean`
  true if this is the root node

This method is defined by Node.

### loadComplete

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

- None.

Returns:

- `void`

This method is defined by Node.

### onLabelClick

`public function onLabelClick(`me {Node}`)`
Executed when the label is clicked. Fires the labelClick custom event.
Parameters:

- `{Node}` : me
  this node @scope the anchor tag clicked

Returns:

- `false`
  to cancel the anchor click

This method is defined by TextNode.

### refresh

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

- None.

Returns:

- `void`

This method is defined by Node.

### setDynamicLoad

`public function setDynamicLoad(`fmDataLoader {function}`, `iconMode {int}`)`
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:

- `{function}` : fmDataLoader
  the function that will be used to get the data.
- `{int}` : iconMode
  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.

Returns:

- `void`

This method is defined by Node.

### setUpLabel

`public function setUpLabel(`oData string`)`
Sets up the node label
Parameters:

- `string` : oData
  containing the label, or an object with a label property

Returns:

- `void`

This method is defined by TextNode.

### showChildren

`public function showChildren()`
Shows this node's children
Parameters:

- None.

Returns:

- `void`

This method is defined by Node.

### toString

`public function toString()`
Node toString
Parameters:

- None.

Returns:

- `string`
  string representation of the node

This method is defined by Node.

### toggle

`public function toggle()`
Expands if node is collapsed, collapses otherwise.
Parameters:

- None.

Returns:

- `void`

This method is defined by Node.

## Event Details

### labelClick

`public event labelClick`
Custom event that is fired when the text node label is clicked. The custom event is defined on the tree instance, so there is a single event that handles all nodes in the tree. The node clicked is provided as an argument @for YAHOO.widget.TreeView
Subscribers will be called with the following parameters:

- `node` : YAHOO.widget.Node
  the node clicked

This event is defined by TextNode.

### parentChange

`public event 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 tre to another.
Subscribers will be called with the following parameters:

- None.

This event is defined by Node.

Copyright © 2006 Jack Slocum. All rights reserved.