webgui/www/extras/yui/docs/menu/overview-summary-menumoduleitem.js.html
JT Smith 4f68a0933c added YUI and YUI-ext
fixed the resizable text area with IE problem
fixed the ad space with IE problem
merged the 7.2.0 and 7.1.4 change logs
2006-11-07 23:15:57 +00:00

1926 lines
67 KiB
HTML

<html>
<head>
<title>JavaScript Documentation - menumoduleitem.js</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1>JavaScript Documentation</h1>
<h3><a href="./index.html">Yahoo! Menuing Library</a></h3>
<div class="breadcrumbs">
<a href="./index.html">Yahoo! Menuing Library</a>
&gt;
<strong>menumoduleitem.js</strong>
</div>
</div>
<div id="body">
<div class="nav">
<div class="module resources">
<ul class="content">
<li><a href="overview-tree.html">Tree View</a></li>
<li><a href="index-all.html">Element Index</a></li>
</ul>
</div>
<div class="module">
<h4><a href="./allclasses-noframe.html">Classes</a></h4>
<ul class="content">
<li>
<a href="YAHOO.widget.ContextMenu.html">
YAHOO.widget.ContextMenu</a>
</li>
<li>
<a href="YAHOO.widget.ContextMenuItem.html">
YAHOO.widget.ContextMenuItem</a>
</li>
<li>
<a href="YAHOO.widget.Menu.html">
YAHOO.widget.Menu</a>
</li>
<li>
<a href="YAHOO.widget.MenuBar.html">
YAHOO.widget.MenuBar</a>
</li>
<li>
<a href="YAHOO.widget.MenuBarItem.html">
YAHOO.widget.MenuBarItem</a>
</li>
<li>
<a href="YAHOO.widget.MenuItem.html">
YAHOO.widget.MenuItem</a>
</li>
<li>
<a href="YAHOO.widget.MenuModule.html">
YAHOO.widget.MenuModule</a>
</li>
<li>
<a href="YAHOO.widget.MenuModuleItem.html">
YAHOO.widget.MenuModuleItem</a>
</li>
</ul>
</div>
<div class="module">
<h4><a href="./overview-summary.html">Files</a></h4>
<ul class="content">
<li>
<a href="overview-summary-contextmenu.js.html">
contextmenu.js</a>
</li>
<li>
<a href="overview-summary-contextmenuitem.js.html">
contextmenuitem.js</a>
</li>
<li>
<a href="overview-summary-menu.js.html">
menu.js</a>
</li>
<li>
<a href="overview-summary-menubar.js.html">
menubar.js</a>
</li>
<li>
<a href="overview-summary-menubaritem.js.html">
menubaritem.js</a>
</li>
<li>
<a href="overview-summary-menuitem.js.html">
menuitem.js</a>
</li>
<li>
<a href="overview-summary-menumodule.js.html">
menumodule.js</a>
</li>
<li>
<a href="overview-summary-menumoduleitem.js.html">
menumoduleitem.js</a>
</li>
</ul>
</div>
</div>
<div class="main">
<h2>menumoduleitem.js</h2>
<div class="meta">
</div>
<div class="quick-links">
<strong>Quick Links:</strong>&nbsp;
<a href="#classSummary">Class Summary</a> |
<a href="#source">Source Code</a>
</div>
<div class="section class summaries">
<h3><a name="classSummary">Class Summary</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<div class="content">
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td class="name">
<a href="YAHOO.widget.MenuModuleItem.html">YAHOO.widget.MenuModuleItem</a>
</td>
<td class="overview">The MenuModuleItem class allows you to create and modify an item for a MenuModule instance.</td>
</tr>
</table>
</div>
</div>
<div class="section source">
<h3><a name="source">Souce Code</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<pre class="sourceview">
<span class="comment">/**
* <span class="attrib">@class</span> The MenuModuleItem class allows you to create and modify an item for a
* MenuModule instance.
* <span class="attrib">@constructor</span>
* <span class="attrib">@param</span> {String or HTMLElement} p_oObject String or HTMLElement
* (either HTMLLIElement, HTMLOptGroupElement or HTMLOptionElement) of the
* source HTMLElement node.
* <span class="attrib">@param</span> {Object} p_oConfig The configuration object literal containing
* the configuration for a MenuModuleItem instance. See the configuration
* class documentation for more details.
*/</span>
YAHOO.widget.MenuModuleItem = <span class="reserved">function</span>(p_oObject, p_oConfig) {
<span class="reserved">if</span>(p_oObject) {
<span class="reserved">this</span>.init(p_oObject, p_oConfig);
}
};
YAHOO.widget.MenuModuleItem.<span class="reserved">prototype</span> = {
<span class="comment">
// Constants</span>
<span class="comment">/**
* Constant representing the path to the image to be used for the submenu
* arrow indicator.
* <span class="attrib">@final</span>
* <span class="attrib">@type</span> String
*/</span>
SUBMENU_INDICATOR_IMAGE_PATH: <span class="literal">"nt/ic/ut/alt1/menuarorght8_nrm_1.gif"</span>,
<span class="comment">/**
* Constant representing the path to the image to be used for the submenu
* arrow indicator when a MenuModuleItem instance is selected.
* <span class="attrib">@final</span>
* <span class="attrib">@type</span> String
*/</span>
SELECTED_SUBMENU_INDICATOR_IMAGE_PATH:
<span class="literal">"nt/ic/ut/alt1/menuarorght8_hov_1.gif"</span>,
<span class="comment">/**
* Constant representing the path to the image to be used for the submenu
* arrow indicator when a MenuModuleItem instance is disabled.
* <span class="attrib">@final</span>
* <span class="attrib">@type</span> String
*/</span>
DISABLED_SUBMENU_INDICATOR_IMAGE_PATH:
<span class="literal">"nt/ic/ut/alt1/menuarorght8_dim_1.gif"</span>,
<span class="comment">/**
* Constant representing the alt text for the image to be used for the
* submenu arrow indicator.
* <span class="attrib">@final</span>
* <span class="attrib">@type</span> String
*/</span>
COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT: <span class="literal">"Collapsed. Click to expand."</span>,
<span class="comment">/**
* Constant representing the alt text for the image to be used for the
* submenu arrow indicator when the submenu is visible.
* <span class="attrib">@final</span>
* <span class="attrib">@type</span> String
*/</span>
EXPANDED_SUBMENU_INDICATOR_ALT_TEXT: <span class="literal">"Expanded. Click to collapse."</span>,
<span class="comment">/**
* Constant representing the alt text for the image to be used for the
* submenu arrow indicator when a MenuModuleItem instance is disabled.
* <span class="attrib">@final</span>
* <span class="attrib">@type</span> String
*/</span>
DISABLED_SUBMENU_INDICATOR_ALT_TEXT: <span class="literal">"Disabled."</span>,
<span class="comment">/**
* Constant representing the CSS class(es) to be applied to the root
* HTMLLIElement of the MenuModuleItem.
* <span class="attrib">@final</span>
* <span class="attrib">@type</span> String
*/</span>
CSS_CLASS_NAME: <span class="literal">"yuimenuitem"</span>,
<span class="comment">/**
* Constant representing the type of menu to instantiate when creating
* submenu instances from parsing the child nodes (either HTMLSelectElement
* or HTMLDivElement) of the item's DOM. The default
* is YAHOO.widget.MenuModule.
* <span class="attrib">@final</span>
* <span class="attrib">@type</span> YAHOO.widget.MenuModule
*/</span>
SUBMENU_TYPE: null,
<span class="comment">/**
* Constant representing the type of item to instantiate when
* creating item instances from parsing the child nodes (either
* HTMLLIElement, HTMLOptGroupElement or HTMLOptionElement) of the
* submenu's DOM.
* The default is YAHOO.widget.MenuModuleItem.
* <span class="attrib">@final</span>
* <span class="attrib">@type</span> YAHOO.widget.MenuModuleItem
*/</span>
SUBMENU_ITEM_TYPE: null,
<span class="comment">/**
* Constant representing the prefix path to use for non-secure images
* <span class="attrib">@type</span> string
*/</span>
IMG_ROOT: <span class="literal">"http://us.i1.yimg.com/us.yimg.com/i/"</span>,
<span class="comment">/**
* Constant representing the prefix path to use for securely served images
* <span class="attrib">@type</span> string
*/</span>
IMG_ROOT_SSL: <span class="literal">"https://a248.e.akamai.net/sec.yimg.com/i/"</span>,
<span class="comment">
// Private member variables</span>
<span class="comment">/**
* Reference to the HTMLAnchorElement of the MenuModuleItem's core internal
* DOM structure.
* <span class="attrib">@private</span>
* <span class="attrib">@type</span> {HTMLAnchorElement}
*/</span>
_oAnchor: null,
<span class="comment">/**
* Reference to the text node of the MenuModuleItem's core internal
* DOM structure.
* <span class="attrib">@private</span>
* <span class="attrib">@type</span> {Text}
*/</span>
_oText: null,
<span class="comment">/**
* Reference to the HTMLElement (&amp;#60;EM&amp;#60;) used to create the optional
* help text for a MenuModuleItem instance.
* <span class="attrib">@private</span>
* <span class="attrib">@type</span> {HTMLElement}
*/</span>
_oHelpTextEM: null,
<span class="comment">/**
* Reference to the submenu for a MenuModuleItem instance.
* <span class="attrib">@private</span>
* <span class="attrib">@type</span> {YAHOO.widget.MenuModule}
*/</span>
_oSubmenu: null,
<span class="comment">/**
* Reference to the Dom utility singleton.
* <span class="attrib">@private</span>
* <span class="attrib">@type</span> {YAHOO.util.Dom}
*/</span>
_oDom: YAHOO.util.Dom,
<span class="comment">/**
* The current state of a MenuModuleItem instance's "mouseover" event
* <span class="attrib">@private</span>
* <span class="attrib">@type</span> {Boolean}
*/</span>
_bFiredMouseOverEvent: false,
<span class="comment">/**
* The current state of a MenuModuleItem instance's "mouseout" event
* <span class="attrib">@private</span>
* <span class="attrib">@type</span> {Boolean}
*/</span>
_bFiredMouseOutEvent: false,
<span class="comment">
// Public properties</span>
<span class="comment">/**
* The class's constructor function
* <span class="attrib">@type</span> YAHOO.widget.MenuModuleItem
*/</span>
constructor: YAHOO.widget.MenuModuleItem,
<span class="comment">/**
* The string representing the image root
* <span class="attrib">@type</span> string
*/</span>
imageRoot: null,
<span class="comment">/**
* Boolean representing whether or not the current browsing context
* is secure (https)
* <span class="attrib">@type</span> boolean
*/</span>
isSecure: YAHOO.widget.Module.<span class="reserved">prototype</span>.isSecure,
<span class="comment">/**
* Returns the ordinal position of a MenuModuleItem instance in a group.
* <span class="attrib">@type</span> Number
*/</span>
index: null,
<span class="comment">/**
* Returns the index of the group to which a MenuModuleItem instance belongs.
* <span class="attrib">@type</span> Number
*/</span>
groupIndex: null,
<span class="comment">/**
* Returns the parent object for a MenuModuleItem instance.
* <span class="attrib">@type</span> {YAHOO.widget.MenuModule}
*/</span>
parent: null,
<span class="comment">/**
* Returns the HTMLLIElement for a MenuModuleItem instance.
* <span class="attrib">@type</span> {HTMLLIElement}
*/</span>
element: null,
<span class="comment">/**
* Returns the HTMLElement (either HTMLLIElement, HTMLOptGroupElement or
* HTMLOptionElement) used create the MenuModuleItem instance.
* <span class="attrib">@type</span> {HTMLLIElement/HTMLOptGroupElement/HTMLOptionElement}
*/</span>
srcElement: null,
<span class="comment">/**
* Specifies an arbitrary value for a MenuModuleItem instance.
* <span class="attrib">@type</span> {Object}
*/</span>
value: null,
<span class="comment">/**
* Reference to the HTMLImageElement used to create the submenu
* indicator for a MenuModuleItem instance.
* <span class="attrib">@type</span> {HTMLImageElement}
*/</span>
submenuIndicator: null,
<span class="comment">/**
* String representing the browser
* <span class="attrib">@type</span> string
*/</span>
browser: YAHOO.widget.Module.<span class="reserved">prototype</span>.browser,
<span class="comment">
// Events</span>
<span class="comment">/**
* Fires when a MenuModuleItem instances's HTMLLIElement is removed from
* it's parent HTMLUListElement node.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
destroyEvent: null,
<span class="comment">/**
* Fires when the mouse has entered a MenuModuleItem instance. Passes
* back the DOM Event object as an argument.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
mouseOverEvent: null,
<span class="comment">/**
* Fires when the mouse has left a MenuModuleItem instance. Passes back
* the DOM Event object as an argument.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
mouseOutEvent: null,
<span class="comment">/**
* Fires when the user mouses down on a MenuModuleItem instance. Passes
* back the DOM Event object as an argument.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
mouseDownEvent: null,
<span class="comment">/**
* Fires when the user releases a mouse button while the mouse is
* over a MenuModuleItem instance. Passes back the DOM Event object as
* an argument.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
mouseUpEvent: null,
<span class="comment">/**
* Fires when the user clicks the on a MenuModuleItem instance. Passes
* back the DOM Event object as an argument.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
clickEvent: null,
<span class="comment">/**
* Fires when the user presses an alphanumeric key. Passes back the
* DOM Event object as an argument.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
keyPressEvent: null,
<span class="comment">/**
* Fires when the user presses a key. Passes back the DOM Event
* object as an argument.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
keyDownEvent: null,
<span class="comment">/**
* Fires when the user releases a key. Passes back the DOM Event
* object as an argument.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
keyUpEvent: null,
<span class="comment">/**
* Fires when a MenuModuleItem instance receives focus.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
focusEvent: null,
<span class="comment">/**
* Fires when a MenuModuleItem instance loses the input focus.
* <span class="attrib">@type</span> {YAHOO.util.CustomEvent}
* <span class="attrib">@see</span> YAHOO.util.CustomEvent
*/</span>
blurEvent: null,
<span class="comment">/**
* The MenuModuleItem class's initialization method. This method is
* automatically called by the constructor, and sets up all DOM references
* for pre-existing markup, and creates required markup if it is not
* already present.
* <span class="attrib">@param</span> {String or HTMLElement} p_oObject String or HTMLElement
* (either HTMLLIElement, HTMLOptGroupElement or HTMLOptionElement) of the
* source HTMLElement node.
* <span class="attrib">@param</span> {Object} p_oConfig The configuration object literal containing
* the configuration for a MenuModuleItem instance. See the configuration
* class documentation for more details.
*/</span>
init: <span class="reserved">function</span>(p_oObject, p_oConfig) {
<span class="reserved">this</span>.imageRoot = (<span class="reserved">this</span>.isSecure) ? <span class="reserved">this</span>.IMG_ROOT_SSL : <span class="reserved">this</span>.IMG_ROOT;
<span class="reserved">if</span>(!<span class="reserved">this</span>.SUBMENU_TYPE) {
<span class="reserved">this</span>.SUBMENU_TYPE = YAHOO.widget.MenuModule;
}
<span class="reserved">if</span>(!<span class="reserved">this</span>.SUBMENU_ITEM_TYPE) {
<span class="reserved">this</span>.SUBMENU_ITEM_TYPE = YAHOO.widget.MenuModuleItem;
}
<span class="comment">
// Create the config object</span>
<span class="reserved">this</span>.cfg = new YAHOO.util.Config(<span class="reserved">this</span>);
<span class="reserved">this</span>.initDefaultConfig();
var oConfig = <span class="reserved">this</span>.cfg;
<span class="reserved">if</span>(<span class="reserved">this</span>._checkString(p_oObject)) {
<span class="reserved">this</span>._createRootNodeStructure();
oConfig.setProperty(<span class="literal">"text"</span>, p_oObject);
}
<span class="reserved">else</span> <span class="reserved">if</span>(<span class="reserved">this</span>._checkDOMNode(p_oObject)) {
switch(p_oObject.tagName) {
case <span class="literal">"OPTION"</span>:
<span class="reserved">this</span>._createRootNodeStructure();
oConfig.setProperty(<span class="literal">"text"</span>, p_oObject.text);
<span class="reserved">this</span>.srcElement = p_oObject;
break;
case <span class="literal">"OPTGROUP"</span>:
<span class="reserved">this</span>._createRootNodeStructure();
oConfig.setProperty(<span class="literal">"text"</span>, p_oObject.label);
<span class="reserved">this</span>.srcElement = p_oObject;
<span class="reserved">this</span>._initSubTree();
break;
case <span class="literal">"LI"</span>:
<span class="comment">
// Get the anchor node (if it exists)</span>
var oAnchor = <span class="reserved">this</span>._getFirstElement(p_oObject, <span class="literal">"A"</span>);
var sURL = <span class="literal">"#"</span>;
var sTarget = null;
var sText = null;
<span class="comment">
// Capture the "text" and/or the "URL"</span>
<span class="reserved">if</span>(oAnchor) {
sURL = oAnchor.getAttribute(<span class="literal">"href"</span>);
sTarget = oAnchor.getAttribute(<span class="literal">"target"</span>);
<span class="reserved">if</span>(oAnchor.innerText) {
sText = oAnchor.innerText;
}
<span class="reserved">else</span> {
var oRange = oAnchor.ownerDocument.createRange();
oRange.selectNodeContents(oAnchor);
sText = oRange.toString();
}
}
<span class="reserved">else</span> {
var oText = p_oObject.firstChild;
sText = oText.nodeValue;
oAnchor = document.createElement(<span class="literal">"a"</span>);
oAnchor.setAttribute(<span class="literal">"href"</span>, sURL);
p_oObject.replaceChild(oAnchor, oText);
oAnchor.appendChild(oText);
}
<span class="reserved">this</span>.srcElement = p_oObject;
<span class="reserved">this</span>.element = p_oObject;
<span class="reserved">this</span>._oAnchor = oAnchor;
<span class="comment">
// Check if emphasis has been applied to the MenuModuleItem</span>
var oEmphasisNode = <span class="reserved">this</span>._getFirstElement(oAnchor);
var bEmphasis = false;
var bStrongEmphasis = false;
<span class="reserved">if</span>(oEmphasisNode) {
<span class="comment">
// Set a reference to the text node </span>
<span class="reserved">this</span>._oText = oEmphasisNode.firstChild;
switch(oEmphasisNode.tagName) {
case <span class="literal">"EM"</span>:
bEmphasis = true;
break;
case <span class="literal">"STRONG"</span>:
bStrongEmphasis = true;
break;
}
}
<span class="reserved">else</span> {
<span class="comment">
// Set a reference to the text node </span>
<span class="reserved">this</span>._oText = oAnchor.firstChild;
}
<span class="comment">/*
Set these properties silently to sync up the
configuration object without making changes to the
element's DOM
*/</span>
oConfig.setProperty(<span class="literal">"text"</span>, sText, true);
oConfig.setProperty(<span class="literal">"url"</span>, sURL, true);
oConfig.setProperty(<span class="literal">"target"</span>, sTarget, true);
oConfig.setProperty(<span class="literal">"emphasis"</span>, bEmphasis, true);
oConfig.setProperty(
<span class="literal">"strongemphasis"</span>,
bStrongEmphasis,
true
);
<span class="reserved">this</span>._initSubTree();
break;
}
}
<span class="reserved">if</span>(<span class="reserved">this</span>.element) {
<span class="reserved">this</span>._oDom.addClass(<span class="reserved">this</span>.element, <span class="reserved">this</span>.CSS_CLASS_NAME);
<span class="comment">
// Create custom events</span>
var CustomEvent = YAHOO.util.CustomEvent;
<span class="reserved">this</span>.destroyEvent = new CustomEvent(<span class="literal">"destroyEvent"</span>, <span class="reserved">this</span>);
<span class="reserved">this</span>.mouseOverEvent = new CustomEvent(<span class="literal">"mouseOverEvent"</span>, <span class="reserved">this</span>);
<span class="reserved">this</span>.mouseOutEvent = new CustomEvent(<span class="literal">"mouseOutEvent"</span>, <span class="reserved">this</span>);
<span class="reserved">this</span>.mouseDownEvent = new CustomEvent(<span class="literal">"mouseDownEvent"</span>, <span class="reserved">this</span>);
<span class="reserved">this</span>.mouseUpEvent = new CustomEvent(<span class="literal">"mouseUpEvent"</span>, <span class="reserved">this</span>);
<span class="reserved">this</span>.clickEvent = new CustomEvent(<span class="literal">"clickEvent"</span>, <span class="reserved">this</span>);
<span class="reserved">this</span>.keyPressEvent = new CustomEvent(<span class="literal">"keyPressEvent"</span>, <span class="reserved">this</span>);
<span class="reserved">this</span>.keyDownEvent = new CustomEvent(<span class="literal">"keyDownEvent"</span>, <span class="reserved">this</span>);
<span class="reserved">this</span>.keyUpEvent = new CustomEvent(<span class="literal">"keyUpEvent"</span>, <span class="reserved">this</span>);
<span class="reserved">this</span>.focusEvent = new CustomEvent(<span class="literal">"focusEvent"</span>, <span class="reserved">this</span>);
<span class="reserved">this</span>.blurEvent = new CustomEvent(<span class="literal">"blurEvent"</span>, <span class="reserved">this</span>);
<span class="comment">
// Subscribe to custom event</span>
<span class="reserved">this</span>.clickEvent.subscribe(<span class="reserved">this</span>._onMenuModuleItemClick, <span class="reserved">this</span>, true);
<span class="reserved">if</span>(p_oConfig) {
oConfig.applyConfig(p_oConfig);
}
oConfig.fireQueue();
}
},
<span class="comment">
// Private methods</span>
<span class="comment">/**
* Returns an HTMLElement's first HTMLElement node
* <span class="attrib">@private</span>
* <span class="attrib">@param</span> {HTMLElement} p_oElement The element to be evaluated.
* <span class="attrib">@param</span> {String} p_sTagName Optional. The tagname of the element.
* <span class="attrib">@return</span> Returns an HTMLElement node.
* <span class="attrib">@type</span> Boolean
*/</span>
_getFirstElement: <span class="reserved">function</span>(p_oElement, p_sTagName) {
var oElement;
<span class="reserved">if</span>(p_oElement.firstChild &amp;&amp; p_oElement.firstChild.nodeType == 1) {
oElement = p_oElement.firstChild;
}
<span class="reserved">else</span> <span class="reserved">if</span>(
p_oElement.firstChild &amp;&amp;
p_oElement.firstChild.nextSibling &amp;&amp;
p_oElement.firstChild.nextSibling.nodeType == 1
) {
oElement = p_oElement.firstChild.nextSibling;
}
<span class="reserved">if</span>(p_sTagName) {
<span class="reserved">return</span> (oElement &amp;&amp; oElement.tagName == p_sTagName) ?
oElement : false;
}
<span class="reserved">return</span> oElement;
},
<span class="comment">/**
* Determines if an object is a string
* <span class="attrib">@private</span>
* <span class="attrib">@param</span> {Object} p_oObject The object to be evaluated.
* <span class="attrib">@return</span> Returns true if the object is a string.
* <span class="attrib">@type</span> Boolean
*/</span>
_checkString: <span class="reserved">function</span>(p_oObject) {
<span class="reserved">return</span> (typeof p_oObject == <span class="literal">"string"</span>);
},
<span class="comment">/**
* Determines if an object is an HTMLElement.
* <span class="attrib">@private</span>
* <span class="attrib">@param</span> {Object} p_oObject The object to be evaluated.
* <span class="attrib">@return</span> Returns true if the object is an HTMLElement.
* <span class="attrib">@type</span> Boolean
*/</span>
_checkDOMNode: <span class="reserved">function</span>(p_oObject) {
<span class="reserved">return</span> (p_oObject &amp;&amp; p_oObject.tagName);
},
<span class="comment">/**
* Creates the core DOM structure for a MenuModuleItem instance.
* <span class="attrib">@private</span>
*/</span>
_createRootNodeStructure: <span class="reserved">function</span> () {
<span class="reserved">this</span>.element = document.createElement(<span class="literal">"li"</span>);
<span class="reserved">this</span>._oText = document.createTextNode(<span class="literal">""</span>);
<span class="reserved">this</span>._oAnchor = document.createElement(<span class="literal">"a"</span>);
<span class="reserved">this</span>._oAnchor.appendChild(<span class="reserved">this</span>._oText);
<span class="reserved">this</span>.cfg.refireEvent(<span class="literal">"url"</span>);
<span class="reserved">this</span>.element.appendChild(<span class="reserved">this</span>._oAnchor);
},
<span class="comment">/**
* Iterates the source element's childNodes collection and uses the
* child nodes to instantiate other menus.
* <span class="attrib">@private</span>
*/</span>
_initSubTree: <span class="reserved">function</span>() {
var Menu = <span class="reserved">this</span>.SUBMENU_TYPE;
var MenuModuleItem = <span class="reserved">this</span>.SUBMENU_ITEM_TYPE;
var oSrcEl = <span class="reserved">this</span>.srcElement;
var oConfig = <span class="reserved">this</span>.cfg;
<span class="reserved">if</span>(oSrcEl.childNodes.length &gt; 0) {
var oNode = oSrcEl.firstChild;
var aOptions = [];
do {
switch(oNode.tagName) {
case <span class="literal">"DIV"</span>:
oConfig.setProperty(<span class="literal">"submenu"</span>, (new Menu(oNode)));
break;
case <span class="literal">"OPTION"</span>:
aOptions[aOptions.length] = oNode;
break;
}
}
<span class="reserved">while</span>((oNode = oNode.nextSibling));
var nOptions = aOptions.length;
<span class="reserved">if</span>(nOptions &gt; 0) {
oConfig.setProperty(
<span class="literal">"submenu"</span>,
(new Menu(<span class="reserved">this</span>._oDom.generateId()))
);
<span class="reserved">for</span>(var n=0; n&lt;nOptions; n++) {
<span class="reserved">this</span>._oSubmenu.addItem((new MenuModuleItem(aOptions[n])));
}
}
}
},
<span class="comment">/**
* "click" event handler for a MenuModuleItem
* <span class="attrib">@private</span>
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the event
* was fired.
* <span class="attrib">@param</span> {YAHOO.widget.MenuItem} p_oMenuModuleItem The MenuModule instance
* that fired the event.
*/</span>
_onMenuModuleItemClick: <span class="reserved">function</span>(p_sType, p_aArgs, p_oMenuModuleItem) {
var Event = YAHOO.util.Event;
var oEvent = p_aArgs[0];
var oTarget = Event.getTarget(oEvent);
var oSubmenu = <span class="reserved">this</span>.cfg.getProperty(<span class="literal">"submenu"</span>);
<span class="comment">/*
ACCESSIBILITY FEATURE FOR SCREEN READERS: Expand/collapse the
submenu when the user clicks on the submenu indicator image.
*/</span>
<span class="reserved">if</span>(oTarget == <span class="reserved">this</span>.submenuIndicator &amp;&amp; oSubmenu) {
<span class="reserved">if</span>(oSubmenu.cfg.getProperty(<span class="literal">"visible"</span>)) {
oSubmenu.hide();
}
<span class="reserved">else</span> {
var oActiveItem = <span class="reserved">this</span>.parent.activeItem;
<span class="comment">
// Hide any other submenus that might be visible</span>
<span class="reserved">if</span>(oActiveItem &amp;&amp; oActiveItem != <span class="reserved">this</span>) {
<span class="reserved">this</span>.parent.clearActiveItem();
}
<span class="reserved">this</span>.parent.activeItem = <span class="reserved">this</span>;
<span class="reserved">this</span>.cfg.setProperty(<span class="literal">"selected"</span>, true);
oSubmenu.show();
}
}
<span class="reserved">else</span> {
var sURL = <span class="reserved">this</span>.cfg.getProperty(<span class="literal">"url"</span>);
var bCurrentPageURL = (sURL.substr((sURL.length-1),1) == <span class="literal">"#"</span>);
var sTarget = <span class="reserved">this</span>.cfg.getProperty(<span class="literal">"target"</span>);
var bHasTarget = (sTarget &amp;&amp; sTarget.length &gt; 0);
<span class="comment">
// Prevent the browser from following links equal to "#"</span>
<span class="reserved">if</span>(oTarget.tagName == <span class="literal">"A"</span> &amp;&amp; bCurrentPageURL &amp;&amp; !bHasTarget) {
Event.preventDefault(oEvent);
}
<span class="reserved">if</span>(oTarget.tagName != <span class="literal">"A"</span> &amp;&amp; !bCurrentPageURL &amp;&amp; !bHasTarget) {
<span class="comment">/*
Follow the URL of the item regardless of whether or
not the user clicked specifically on the
HTMLAnchorElement (&amp;#60;A&amp;#60;) node.
*/</span>
document.location = sURL;
}
}
},
<span class="comment">
// Event handlers for configuration properties</span>
<span class="comment">/**
* Event handler for when the "text" configuration property of
* a MenuModuleItem instance changes.
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the
* event was fired.
* <span class="attrib">@param</span> {YAHOO.widget.MenuModuleItem} p_oItem The MenuModuleItem instance
* that fired the event.
*/</span>
configText: <span class="reserved">function</span>(p_sType, p_aArgs, p_oItem) {
var sText = p_aArgs[0];
<span class="reserved">if</span>(<span class="reserved">this</span>._oText) {
<span class="reserved">this</span>._oText.nodeValue = sText;
}
},
<span class="comment">/**
* Event handler for when the "helptext" configuration property of
* a MenuModuleItem instance changes.
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the
* event was fired.
* <span class="attrib">@param</span> {YAHOO.widget.MenuModuleItem} p_oItem The MenuModuleItem instance
* that fired the event.
*/</span>
configHelpText: <span class="reserved">function</span>(p_sType, p_aArgs, p_oItem) {
var me = <span class="reserved">this</span>;
var Dom = <span class="reserved">this</span>._oDom;
var oHelpText = p_aArgs[0];
var oEl = <span class="reserved">this</span>.element;
var oConfig = <span class="reserved">this</span>.cfg;
var aNodes = [oEl, <span class="reserved">this</span>._oAnchor];
var oImg = <span class="reserved">this</span>.submenuIndicator;
<span class="comment">/**
* Adds the "hashelptext" class to the necessary nodes and refires the
* "selected" and "disabled" configuration events
* <span class="attrib">@ignore</span>
*/</span>
<span class="reserved">function</span> initHelpText() {
Dom.addClass(aNodes, <span class="literal">"hashelptext"</span>);
<span class="reserved">if</span>(oConfig.getProperty(<span class="literal">"disabled"</span>)) {
oConfig.refireEvent(<span class="literal">"disabled"</span>);
}
<span class="reserved">if</span>(oConfig.getProperty(<span class="literal">"selected"</span>)) {
oConfig.refireEvent(<span class="literal">"selected"</span>);
}
}
<span class="comment">/**
* Removes the "hashelptext" class and corresponding DOM element (EM)
* <span class="attrib">@ignore</span>
*/</span>
<span class="reserved">function</span> removeHelpText() {
Dom.removeClass(aNodes, <span class="literal">"hashelptext"</span>);
oEl.removeChild(me._oHelpTextEM);
me._oHelpTextEM = null;
}
<span class="reserved">if</span>(<span class="reserved">this</span>._checkDOMNode(oHelpText)) {
<span class="reserved">if</span>(<span class="reserved">this</span>._oHelpTextEM) {
<span class="reserved">this</span>._oHelpTextEM.parentNode.replaceChild(
oHelpText,
<span class="reserved">this</span>._oHelpTextEM
);
}
<span class="reserved">else</span> {
<span class="reserved">this</span>._oHelpTextEM = oHelpText;
oEl.insertBefore(<span class="reserved">this</span>._oHelpTextEM, oImg);
}
initHelpText();
}
<span class="reserved">else</span> <span class="reserved">if</span>(<span class="reserved">this</span>._checkString(oHelpText)) {
<span class="reserved">if</span>(oHelpText.length === 0) {
removeHelpText();
}
<span class="reserved">else</span> {
<span class="reserved">if</span>(!<span class="reserved">this</span>._oHelpTextEM) {
<span class="reserved">this</span>._oHelpTextEM = document.createElement(<span class="literal">"em"</span>);
oEl.insertBefore(<span class="reserved">this</span>._oHelpTextEM, oImg);
}
<span class="reserved">this</span>._oHelpTextEM.innerHTML = oHelpText;
initHelpText();
}
}
<span class="reserved">else</span> <span class="reserved">if</span>(!oHelpText &amp;&amp; <span class="reserved">this</span>._oHelpTextEM) {
removeHelpText();
}
},
<span class="comment">/**
* Event handler for when the "url" configuration property of
* a MenuModuleItem instance changes.
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the
* event was fired.
* <span class="attrib">@param</span> {YAHOO.widget.MenuModuleItem} p_oItem The MenuModuleItem instance
* that fired the event.
*/</span>
configURL: <span class="reserved">function</span>(p_sType, p_aArgs, p_oItem) {
var sURL = p_aArgs[0];
<span class="reserved">if</span>(!sURL) {
sURL = <span class="literal">"#"</span>;
}
<span class="reserved">this</span>._oAnchor.setAttribute(<span class="literal">"href"</span>, sURL);
},
<span class="comment">/**
* Event handler for when the "target" configuration property of
* a MenuModuleItem instance changes.
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the
* event was fired.
* <span class="attrib">@param</span> {YAHOO.widget.MenuModuleItem} p_oItem The MenuModuleItem instance
* that fired the event.
*/</span>
configTarget: <span class="reserved">function</span>(p_sType, p_aArgs, p_oItem) {
var sTarget = p_aArgs[0];
var oAnchor = <span class="reserved">this</span>._oAnchor;
<span class="reserved">if</span>(sTarget &amp;&amp; sTarget.length &gt; 0) {
oAnchor.setAttribute(<span class="literal">"target"</span>, sTarget);
}
<span class="reserved">else</span> {
oAnchor.removeAttribute(<span class="literal">"target"</span>);
}
},
<span class="comment">/**
* Event handler for when the "emphasis" configuration property of
* a MenuModuleItem instance changes.
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the
* event was fired.
* <span class="attrib">@param</span> {YAHOO.widget.MenuModuleItem} p_oItem The MenuModuleItem instance
* that fired the event.
*/</span>
configEmphasis: <span class="reserved">function</span>(p_sType, p_aArgs, p_oItem) {
var bEmphasis = p_aArgs[0];
var oAnchor = <span class="reserved">this</span>._oAnchor;
var oText = <span class="reserved">this</span>._oText;
var oConfig = <span class="reserved">this</span>.cfg;
var oEM;
<span class="reserved">if</span>(bEmphasis &amp;&amp; oConfig.getProperty(<span class="literal">"strongemphasis"</span>)) {
oConfig.setProperty(<span class="literal">"strongemphasis"</span>, false);
}
<span class="reserved">if</span>(oAnchor) {
<span class="reserved">if</span>(bEmphasis) {
oEM = document.createElement(<span class="literal">"em"</span>);
oEM.appendChild(oText);
oAnchor.appendChild(oEM);
}
<span class="reserved">else</span> {
oEM = <span class="reserved">this</span>._getFirstElement(oAnchor, <span class="literal">"EM"</span>);
oAnchor.removeChild(oEM);
oAnchor.appendChild(oText);
}
}
},
<span class="comment">/**
* Event handler for when the "strongemphasis" configuration property of
* a MenuModuleItem instance changes.
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the
* event was fired.
* <span class="attrib">@param</span> {YAHOO.widget.MenuModuleItem} p_oItem The MenuModuleItem instance
* that fired the event.
*/</span>
configStrongEmphasis: <span class="reserved">function</span>(p_sType, p_aArgs, p_oItem) {
var bStrongEmphasis = p_aArgs[0];
var oAnchor = <span class="reserved">this</span>._oAnchor;
var oText = <span class="reserved">this</span>._oText;
var oConfig = <span class="reserved">this</span>.cfg;
var oStrong;
<span class="reserved">if</span>(bStrongEmphasis &amp;&amp; oConfig.getProperty(<span class="literal">"emphasis"</span>)) {
oConfig.setProperty(<span class="literal">"emphasis"</span>, false);
}
<span class="reserved">if</span>(oAnchor) {
<span class="reserved">if</span>(bStrongEmphasis) {
oStrong = document.createElement(<span class="literal">"strong"</span>);
oStrong.appendChild(oText);
oAnchor.appendChild(oStrong);
}
<span class="reserved">else</span> {
oStrong = <span class="reserved">this</span>._getFirstElement(oAnchor, <span class="literal">"STRONG"</span>);
oAnchor.removeChild(oStrong);
oAnchor.appendChild(oText);
}
}
},
<span class="comment">/**
* Event handler for when the "disabled" configuration property of
* a MenuModuleItem instance changes.
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the
* event was fired.
* <span class="attrib">@param</span> {YAHOO.widget.MenuModuleItem} p_oItem The MenuModuleItem instance
* that fired the event.
*/</span>
configDisabled: <span class="reserved">function</span>(p_sType, p_aArgs, p_oItem) {
var bDisabled = p_aArgs[0];
var Dom = <span class="reserved">this</span>._oDom;
var oAnchor = <span class="reserved">this</span>._oAnchor;
var aNodes = [<span class="reserved">this</span>.element, oAnchor];
var oEM = <span class="reserved">this</span>._oHelpTextEM;
var oConfig = <span class="reserved">this</span>.cfg;
var oImg = <span class="reserved">this</span>.submenuIndicator;
var sImageSrc;
var sImageAlt;
<span class="reserved">if</span>(oEM) {
aNodes[2] = oEM;
}
<span class="reserved">if</span>(bDisabled) {
<span class="reserved">if</span>(oConfig.getProperty(<span class="literal">"selected"</span>)) {
oConfig.setProperty(<span class="literal">"selected"</span>, false);
}
oAnchor.removeAttribute(<span class="literal">"href"</span>);
Dom.addClass(aNodes, <span class="literal">"disabled"</span>);
sImageSrc = <span class="reserved">this</span>.DISABLED_SUBMENU_INDICATOR_IMAGE_PATH;
sImageAlt = <span class="reserved">this</span>.DISABLED_SUBMENU_INDICATOR_ALT_TEXT;
}
<span class="reserved">else</span> {
oAnchor.setAttribute(<span class="literal">"href"</span>, oConfig.getProperty(<span class="literal">"url"</span>));
Dom.removeClass(aNodes, <span class="literal">"disabled"</span>);
sImageSrc = <span class="reserved">this</span>.SUBMENU_INDICATOR_IMAGE_PATH;
sImageAlt = <span class="reserved">this</span>.COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT;
}
<span class="reserved">if</span>(oImg) {
oImg.src = <span class="reserved">this</span>.imageRoot + sImageSrc;
oImg.alt = sImageAlt;
}
},
<span class="comment">/**
* Event handler for when the "selected" configuration property of
* a MenuModuleItem instance changes.
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the
* event was fired.
* <span class="attrib">@param</span> {YAHOO.widget.MenuModuleItem} p_oItem The MenuModuleItem instance
* that fired the event.
*/</span>
configSelected: <span class="reserved">function</span>(p_sType, p_aArgs, p_oItem) {
<span class="reserved">if</span>(!<span class="reserved">this</span>.cfg.getProperty(<span class="literal">"disabled"</span>)) {
var Dom = <span class="reserved">this</span>._oDom;
var bSelected = p_aArgs[0];
var oEM = <span class="reserved">this</span>._oHelpTextEM;
var aNodes = [<span class="reserved">this</span>.element, <span class="reserved">this</span>._oAnchor];
var oImg = <span class="reserved">this</span>.submenuIndicator;
var sImageSrc;
<span class="reserved">if</span>(oEM) {
aNodes[aNodes.length] = oEM;
}
<span class="reserved">if</span>(oImg) {
aNodes[aNodes.length] = oImg;
}
<span class="reserved">if</span>(bSelected) {
Dom.addClass(aNodes, <span class="literal">"selected"</span>);
sImageSrc = <span class="reserved">this</span>.SELECTED_SUBMENU_INDICATOR_IMAGE_PATH;
}
<span class="reserved">else</span> {
Dom.removeClass(aNodes, <span class="literal">"selected"</span>);
sImageSrc = <span class="reserved">this</span>.SUBMENU_INDICATOR_IMAGE_PATH;
}
<span class="reserved">if</span>(oImg) {
oImg.src = document.images[(<span class="reserved">this</span>.imageRoot + sImageSrc)].src;
}
}
},
<span class="comment">/**
* Event handler for when the "submenu" configuration property of
* a MenuModuleItem instance changes.
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the
* event was fired.
* <span class="attrib">@param</span> {YAHOO.widget.MenuModuleItem} p_oItem The MenuModuleItem instance
* that fired the event.
*/</span>
configSubmenu: <span class="reserved">function</span>(p_sType, p_aArgs, p_oItem) {
var Dom = <span class="reserved">this</span>._oDom;
var oEl = <span class="reserved">this</span>.element;
var oSubmenu = p_aArgs[0];
var oImg = <span class="reserved">this</span>.submenuIndicator;
var oConfig = <span class="reserved">this</span>.cfg;
var aNodes = [<span class="reserved">this</span>.element, <span class="reserved">this</span>._oAnchor];
<span class="reserved">if</span>(oSubmenu) {
<span class="comment">
// Set the submenu's parent to this MenuModuleItem instance</span>
oSubmenu.parent = <span class="reserved">this</span>;
<span class="reserved">this</span>._oSubmenu = oSubmenu;
<span class="reserved">if</span>(!oImg) {
var me = <span class="reserved">this</span>;
<span class="reserved">function</span> preloadImage(p_sPath) {
var sPath = me.imageRoot + p_sPath;
<span class="reserved">if</span>(!document.images[sPath]) {
var oImage = document.createElement(<span class="literal">"img"</span>);
oImage.src = sPath;
oImage.name = sPath;
oImage.id = sPath;
oImage.style.display = <span class="literal">"none"</span>;
document.body.appendChild(oImage);
}
}
preloadImage(<span class="reserved">this</span>.SUBMENU_INDICATOR_IMAGE_PATH);
preloadImage(<span class="reserved">this</span>.SELECTED_SUBMENU_INDICATOR_IMAGE_PATH);
preloadImage(<span class="reserved">this</span>.DISABLED_SUBMENU_INDICATOR_IMAGE_PATH);
oImg = document.createElement(<span class="literal">"img"</span>);
oImg.src = (<span class="reserved">this</span>.imageRoot + <span class="reserved">this</span>.SUBMENU_INDICATOR_IMAGE_PATH);
oImg.alt = <span class="reserved">this</span>.COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT;
oEl.appendChild(oImg);
<span class="reserved">this</span>.submenuIndicator = oImg;
Dom.addClass(aNodes, <span class="literal">"hassubmenu"</span>);
<span class="reserved">if</span>(oConfig.getProperty(<span class="literal">"disabled"</span>)) {
oConfig.refireEvent(<span class="literal">"disabled"</span>);
}
<span class="reserved">if</span>(oConfig.getProperty(<span class="literal">"selected"</span>)) {
oConfig.refireEvent(<span class="literal">"selected"</span>);
}
}
}
<span class="reserved">else</span> {
Dom.removeClass(aNodes, <span class="literal">"hassubmenu"</span>);
<span class="reserved">if</span>(oImg) {
oEl.removeChild(oImg);
}
<span class="reserved">if</span>(<span class="reserved">this</span>._oSubmenu) {
<span class="reserved">this</span>._oSubmenu.destroy();
}
}
},
<span class="comment">
// Public methods</span>
<span class="comment">/**
* Initializes an item's configurable properties.
*/</span>
initDefaultConfig : <span class="reserved">function</span>() {
var oConfig = <span class="reserved">this</span>.cfg;
var CheckBoolean = oConfig.checkBoolean;
<span class="comment">
// Define the config properties</span>
oConfig.addProperty(
<span class="literal">"text"</span>,
{
value: <span class="literal">""</span>,
handler: <span class="reserved">this</span>.configText,
validator: <span class="reserved">this</span>._checkString,
suppressEvent: true
}
);
oConfig.addProperty(<span class="literal">"helptext"</span>, { handler: <span class="reserved">this</span>.configHelpText });
oConfig.addProperty(
<span class="literal">"url"</span>,
{ value: <span class="literal">"#"</span>, handler: <span class="reserved">this</span>.configURL, suppressEvent: true }
);
oConfig.addProperty(
<span class="literal">"target"</span>,
{ handler: <span class="reserved">this</span>.configTarget, suppressEvent: true }
);
oConfig.addProperty(
<span class="literal">"emphasis"</span>,
{
value: false,
handler: <span class="reserved">this</span>.configEmphasis,
validator: CheckBoolean,
suppressEvent: true
}
);
oConfig.addProperty(
<span class="literal">"strongemphasis"</span>,
{
value: false,
handler: <span class="reserved">this</span>.configStrongEmphasis,
validator: CheckBoolean,
suppressEvent: true
}
);
oConfig.addProperty(
<span class="literal">"disabled"</span>,
{
value: false,
handler: <span class="reserved">this</span>.configDisabled,
validator: CheckBoolean,
suppressEvent: true
}
);
oConfig.addProperty(
<span class="literal">"selected"</span>,
{
value: false,
handler: <span class="reserved">this</span>.configSelected,
validator: CheckBoolean,
suppressEvent: true
}
);
oConfig.addProperty(<span class="literal">"submenu"</span>, { handler: <span class="reserved">this</span>.configSubmenu });
},
<span class="comment">/**
* Finds the next enabled MenuModuleItem instance in a MenuModule instance
* <span class="attrib">@return</span> Returns a MenuModuleItem instance.
* <span class="attrib">@type</span> YAHOO.widget.MenuModuleItem
*/</span>
getNextEnabledSibling: <span class="reserved">function</span>() {
<span class="reserved">if</span>(<span class="reserved">this</span>.parent instanceof YAHOO.widget.MenuModule) {
var nGroupIndex = <span class="reserved">this</span>.groupIndex;
<span class="comment">/**
* Returns the next item in an array
* <span class="attrib">@param</span> {p_aArray} An array
* <span class="attrib">@param</span> {p_nStartIndex} The index to start searching the array
* <span class="attrib">@ignore</span>
* <span class="attrib">@return</span> Returns an item in an array
* <span class="attrib">@type</span> Object
*/</span>
<span class="reserved">function</span> getNextArrayItem(p_aArray, p_nStartIndex) {
<span class="reserved">return</span> p_aArray[p_nStartIndex] ||
getNextArrayItem(p_aArray, (p_nStartIndex+1));
}
var aItemGroups = <span class="reserved">this</span>.parent.getItemGroups();
var oNextItem;
<span class="reserved">if</span>(<span class="reserved">this</span>.index &lt; (aItemGroups[nGroupIndex].length - 1)) {
oNextItem = getNextArrayItem(
aItemGroups[nGroupIndex],
(<span class="reserved">this</span>.index+1)
);
}
<span class="reserved">else</span> {
var nNextGroupIndex;
<span class="reserved">if</span>(nGroupIndex &lt; (aItemGroups.length - 1)) {
nNextGroupIndex = nGroupIndex + 1;
}
<span class="reserved">else</span> {
nNextGroupIndex = 0;
}
var aNextGroup = getNextArrayItem(aItemGroups, nNextGroupIndex);
<span class="comment">
// Retrieve the first MenuModuleItem instance in the next group</span>
oNextItem = getNextArrayItem(aNextGroup, 0);
}
<span class="reserved">return</span> (
oNextItem.cfg.getProperty(<span class="literal">"disabled"</span>) ||
oNextItem.element.style.display == <span class="literal">"none"</span>
) ?
oNextItem.getNextEnabledSibling() : oNextItem;
}
},
<span class="comment">/**
* Finds the previous enabled MenuModuleItem instance in a
* MenuModule instance
* <span class="attrib">@return</span> Returns a MenuModuleItem instance.
* <span class="attrib">@type</span> YAHOO.widget.MenuModuleItem
*/</span>
getPreviousEnabledSibling: <span class="reserved">function</span>() {
<span class="reserved">if</span>(<span class="reserved">this</span>.parent instanceof YAHOO.widget.MenuModule) {
var nGroupIndex = <span class="reserved">this</span>.groupIndex;
<span class="comment">/**
* Returns the previous item in an array
* <span class="attrib">@param</span> {p_aArray} An array
* <span class="attrib">@param</span> {p_nStartIndex} The index to start searching the array
* <span class="attrib">@ignore</span>
* <span class="attrib">@return</span> Returns an item in an array
* <span class="attrib">@type</span> Object
*/</span>
<span class="reserved">function</span> getPreviousArrayItem(p_aArray, p_nStartIndex) {
<span class="reserved">return</span> p_aArray[p_nStartIndex] ||
getPreviousArrayItem(p_aArray, (p_nStartIndex-1));
}
<span class="comment">/**
* Get the index of the first item in an array
* <span class="attrib">@param</span> {p_aArray} An array
* <span class="attrib">@param</span> {p_nStartIndex} The index to start searching the array
* <span class="attrib">@ignore</span>
* <span class="attrib">@return</span> Returns an item in an array
* <span class="attrib">@type</span> Object
*/</span>
<span class="reserved">function</span> getFirstItemIndex(p_aArray, p_nStartIndex) {
<span class="reserved">return</span> p_aArray[p_nStartIndex] ?
p_nStartIndex :
getFirstItemIndex(p_aArray, (p_nStartIndex+1));
}
var aItemGroups = <span class="reserved">this</span>.parent.getItemGroups();
var oPreviousItem;
<span class="reserved">if</span>(
<span class="reserved">this</span>.index &gt; getFirstItemIndex(aItemGroups[nGroupIndex], 0)
) {
oPreviousItem =
getPreviousArrayItem(
aItemGroups[nGroupIndex],
(<span class="reserved">this</span>.index-1)
);
}
<span class="reserved">else</span> {
var nPreviousGroupIndex;
<span class="reserved">if</span>(nGroupIndex &gt; getFirstItemIndex(aItemGroups, 0)) {
nPreviousGroupIndex = nGroupIndex - 1;
}
<span class="reserved">else</span> {
nPreviousGroupIndex = aItemGroups.length - 1;
}
var aPreviousGroup =
getPreviousArrayItem(aItemGroups, nPreviousGroupIndex);
oPreviousItem =
getPreviousArrayItem(
aPreviousGroup,
(aPreviousGroup.length - 1)
);
}
<span class="reserved">return</span> (
oPreviousItem.cfg.getProperty(<span class="literal">"disabled"</span>) ||
oPreviousItem.element.style.display == <span class="literal">"none"</span>
) ?
oPreviousItem.getPreviousEnabledSibling() : oPreviousItem;
}
},
<span class="comment">/**
* Causes a MenuModuleItem instance to receive the focus and fires the
* focus event.
*/</span>
focus: <span class="reserved">function</span>() {
var oParent = <span class="reserved">this</span>.parent;
var oAnchor = <span class="reserved">this</span>._oAnchor;
var oActiveItem = oParent.activeItem;
<span class="reserved">if</span>(
!<span class="reserved">this</span>.cfg.getProperty(<span class="literal">"disabled"</span>) &amp;&amp;
oParent &amp;&amp;
oParent.cfg.getProperty(<span class="literal">"visible"</span>) &amp;&amp;
<span class="reserved">this</span>.element.style.display != <span class="literal">"none"</span>
) {
<span class="reserved">if</span>(oActiveItem) {
oActiveItem.blur();
}
oAnchor.focus();
<span class="reserved">this</span>.focusEvent.fire();
}
},
<span class="comment">/**
* Causes a MenuModuleItem instance to lose focus and fires the onblur event.
*/</span>
blur: <span class="reserved">function</span>() {
var oParent = <span class="reserved">this</span>.parent;
<span class="reserved">if</span>(
!<span class="reserved">this</span>.cfg.getProperty(<span class="literal">"disabled"</span>) &amp;&amp;
oParent &amp;&amp;
<span class="reserved">this</span>._oDom.getStyle(oParent.element, <span class="literal">"visibility"</span>) == <span class="literal">"visible"</span>
) {
<span class="reserved">this</span>._oAnchor.blur();
<span class="reserved">this</span>.blurEvent.fire();
}
},
<span class="comment">/**
* Removes a MenuModuleItem instance's HTMLLIElement from it's parent
* HTMLUListElement node.
*/</span>
destroy: <span class="reserved">function</span>() {
var oEl = <span class="reserved">this</span>.element;
<span class="reserved">if</span>(oEl) {
<span class="comment">
// Remove CustomEvent listeners</span>
<span class="reserved">this</span>.mouseOverEvent.unsubscribeAll();
<span class="reserved">this</span>.mouseOutEvent.unsubscribeAll();
<span class="reserved">this</span>.mouseDownEvent.unsubscribeAll();
<span class="reserved">this</span>.mouseUpEvent.unsubscribeAll();
<span class="reserved">this</span>.clickEvent.unsubscribeAll();
<span class="reserved">this</span>.keyPressEvent.unsubscribeAll();
<span class="reserved">this</span>.keyDownEvent.unsubscribeAll();
<span class="reserved">this</span>.keyUpEvent.unsubscribeAll();
<span class="reserved">this</span>.focusEvent.unsubscribeAll();
<span class="reserved">this</span>.blurEvent.unsubscribeAll();
<span class="reserved">this</span>.cfg.configChangedEvent.unsubscribeAll();
<span class="comment">
// Remove the element from the parent node</span>
var oParentNode = oEl.parentNode;
<span class="reserved">if</span>(oParentNode) {
oParentNode.removeChild(oEl);
<span class="reserved">this</span>.destroyEvent.fire();
}
<span class="reserved">this</span>.destroyEvent.unsubscribeAll();
}
}
};</pre>
</div>
</div>
</div>
<div id="footer">
<hr />
Copyright &copy; 2006 Yahoo! Inc. All rights reserved.
<br /><br />
Documentation generated by <a href="http://jsdoc.sourceforge.net/">
JSDoc</a>
</div>
</body>
</html>