📄 menu.js
字号:
* Removes the specified item from a MenuModule instance.
* @param {YAHOO.widget.MenuModuleItem/Number} p_oObject The item or index of
* the item to be removed.
* @param {Number} p_nGroupIndex Optional. Number indicating the group to which
* the item belongs.
* @return The item that was removed from the MenuModule.
* @type YAHOO.widget.MenuModuleItem
*/
YAHOO.widget.MenuModule.prototype.removeItem =
function(p_oObject, p_nGroupIndex) {
if(typeof p_oObject != "undefined") {
var oItem;
if(p_oObject instanceof YAHOO.widget.MenuModuleItem) {
oItem =
this._removeItemFromGroupByValue(p_nGroupIndex, p_oObject);
}
else if(typeof p_oObject == "number") {
oItem =
this._removeItemFromGroupByIndex(p_nGroupIndex, p_oObject);
}
if(oItem) {
oItem.destroy();
return oItem;
}
}
};
/**
* Returns a multi-dimensional array of all of a MenuModule's items.
* @return An array of items.
* @type Array
*/
YAHOO.widget.MenuModule.prototype.getItemGroups = function() {
return this._aItemGroups;
};
/**
* Returns the item at the specified index.
* @param {Number} p_nItemIndex Number indicating the ordinal position of the
* item to be retrieved.
* @param {Number} p_nGroupIndex Optional. Number indicating the group to which
* the item belongs.
* @return An item.
* @type YAHOO.widget.MenuModuleItem
*/
YAHOO.widget.MenuModule.prototype.getItem =
function(p_nItemIndex, p_nGroupIndex) {
if(typeof p_nItemIndex == "number") {
var aGroup = this._getItemGroup(p_nGroupIndex);
if(aGroup) {
return aGroup[p_nItemIndex];
}
}
};
/**
* Removes the MenuModule instance's element from the DOM and sets all child
* elements to null.
*/
YAHOO.widget.MenuModule.prototype.destroy = function() {
// Remove Custom Event listeners
this.mouseOverEvent.unsubscribeAll();
this.mouseOutEvent.unsubscribeAll();
this.mouseDownEvent.unsubscribeAll();
this.mouseUpEvent.unsubscribeAll();
this.clickEvent.unsubscribeAll();
this.keyPressEvent.unsubscribeAll();
this.keyDownEvent.unsubscribeAll();
this.keyUpEvent.unsubscribeAll();
var nItemGroups = this._aItemGroups.length;
var nItems;
var oItemGroup;
var oItem;
var i;
var n;
// Remove all items
if(nItemGroups > 0) {
i = nItemGroups - 1;
do {
oItemGroup = this._aItemGroups[i];
if(oItemGroup) {
nItems = oItemGroup.length;
if(nItems > 0) {
n = nItems - 1;
do {
oItem = this._aItemGroups[i][n];
if(oItem) {
oItem.destroy();
}
}
while(n--);
}
}
}
while(i--);
}
// Continue with the superclass implementation of this method
YAHOO.widget.MenuModule.superclass.destroy.call(this);
};
/**
* Sets focus to a MenuModule instance's first enabled item.
*/
YAHOO.widget.MenuModule.prototype.setInitialFocus = function() {
var oItem = this._getFirstEnabledItem();
if(oItem) {
oItem.focus();
}
};
/**
* Sets the "selected" configuration property of a MenuModule instance's first
* enabled item to "true."
*/
YAHOO.widget.MenuModule.prototype.setInitialSelection = function() {
var oItem = this._getFirstEnabledItem();
if(oItem) {
oItem.cfg.setProperty("selected", true);
}
};
/**
* Sets the "selected" configuration property of a MenuModule instance's active
* item to "false," blurs the item and hide's the item's submenu.
*/
YAHOO.widget.MenuModule.prototype.clearActiveItem = function () {
if(this.activeItem) {
var oConfig = this.activeItem.cfg;
oConfig.setProperty("selected", false);
var oSubmenu = oConfig.getProperty("submenu");
if(oSubmenu) {
oSubmenu.hide();
}
}
};
/**
* Initializes the class's configurable properties which can be changed using
* the MenuModule's Config object (cfg).
*/
YAHOO.widget.MenuModule.prototype.initDefaultConfig = function() {
YAHOO.widget.MenuModule.superclass.initDefaultConfig.call(this);
var oConfig = this.cfg;
// Add configuration properties
oConfig.addProperty(
"position",
{
value: "dynamic",
handler: this.configPosition,
validator: this._checkPosition
}
);
// this.cfg.refireEvent("position");
oConfig.addProperty("submenualignment", { value: ["tl","tr"] } );
};
/**
* @class The MenuModuleItem class allows you to create and modify an item for a
* MenuModule instance.
* @constructor
* @param {String or HTMLElement} p_oObject String or HTMLElement
* (either HTMLLIElement, HTMLOptGroupElement or HTMLOptionElement) of the
* source HTMLElement node.
* @param {Object} p_oConfig The configuration object literal containing
* the configuration for a MenuModuleItem instance. See the configuration
* class documentation for more details.
*/
YAHOO.widget.MenuModuleItem = function(p_oObject, p_oConfig) {
if(p_oObject) {
this.init(p_oObject, p_oConfig);
}
};
YAHOO.widget.MenuModuleItem.prototype = {
// Constants
/**
* Constant representing the path to the image to be used for the submenu
* arrow indicator.
* @final
* @type String
*/
SUBMENU_INDICATOR_IMAGE_PATH: "nt/ic/ut/alt1/menuarorght8_nrm_1.gif",
/**
* Constant representing the path to the image to be used for the submenu
* arrow indicator when a MenuModuleItem instance is selected.
* @final
* @type String
*/
SELECTED_SUBMENU_INDICATOR_IMAGE_PATH:
"nt/ic/ut/alt1/menuarorght8_hov_1.gif",
/**
* Constant representing the path to the image to be used for the submenu
* arrow indicator when a MenuModuleItem instance is disabled.
* @final
* @type String
*/
DISABLED_SUBMENU_INDICATOR_IMAGE_PATH:
"nt/ic/ut/alt1/menuarorght8_dim_1.gif",
/**
* Constant representing the alt text for the image to be used for the
* submenu arrow indicator.
* @final
* @type String
*/
COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT: "Collapsed. Click to expand.",
/**
* Constant representing the alt text for the image to be used for the
* submenu arrow indicator when the submenu is visible.
* @final
* @type String
*/
EXPANDED_SUBMENU_INDICATOR_ALT_TEXT: "Expanded. Click to collapse.",
/**
* Constant representing the alt text for the image to be used for the
* submenu arrow indicator when a MenuModuleItem instance is disabled.
* @final
* @type String
*/
DISABLED_SUBMENU_INDICATOR_ALT_TEXT: "Disabled.",
/**
* Constant representing the CSS class(es) to be applied to the root
* HTMLLIElement of the MenuModuleItem.
* @final
* @type String
*/
CSS_CLASS_NAME: "yuimenuitem",
/**
* 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.
* @final
* @type YAHOO.widget.MenuModule
*/
SUBMENU_TYPE: null,
/**
* 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.
* @final
* @type YAHOO.widget.MenuModuleItem
*/
SUBMENU_ITEM_TYPE: null,
/**
* Constant representing the prefix path to use for non-secure images
* @type string
*/
IMG_ROOT: "http://us.i1.yimg.com/us.yimg.com/i/",
/**
* Constant representing the prefix path to use for securely served images
* @type string
*/
IMG_ROOT_SSL: "https://a248.e.akamai.net/sec.yimg.com/i/",
// Private member variables
/**
* Reference to the HTMLAnchorElement of the MenuModuleItem's core internal
* DOM structure.
* @private
* @type {HTMLAnchorElement}
*/
_oAnchor: null,
/**
* Reference to the text node of the MenuModuleItem's core internal
* DOM structure.
* @private
* @type {Text}
*/
_oText: null,
/**
* Reference to the HTMLElement (<EM<) used to create the optional
* help text for a MenuModuleItem instance.
* @private
* @type {HTMLElement}
*/
_oHelpTextEM: null,
/**
* Reference to the submenu for a MenuModuleItem instance.
* @private
* @type {YAHOO.widget.MenuModule}
*/
_oSubmenu: null,
/**
* Reference to the Dom utility singleton.
* @private
* @type {YAHOO.util.Dom}
*/
_oDom: YAHOO.util.Dom,
/**
* The current state of a MenuModuleItem instance's "mouseover" event
* @private
* @type {Boolean}
*/
_bFiredMouseOverEvent: false,
/**
* The current state of a MenuModuleItem instance's "mouseout" event
* @private
* @type {Boolean}
*/
_bFiredMouseOutEvent: false,
// Public properties
/**
* The class's constructor function
* @type YAHOO.widget.MenuModuleItem
*/
constructor: YAHOO.widget.MenuModuleItem,
/**
* The string representing the image root
* @type string
*/
imageRoot: null,
/**
* Boolean representing whether or not the current browsing context
* is secure (https)
* @type boolean
*/
isSecure: YAHOO.widget.Module.prototype.isSecure,
/**
* Returns the ordinal position of a MenuModuleItem instance in a group.
* @type Number
*/
index: null,
/**
* Returns the index of the group to which a MenuModuleItem instance belongs.
* @type Number
*/
groupIndex: null,
/**
* Returns the parent object for a MenuModuleItem instance.
* @type {YAHOO.widget.MenuModule}
*/
parent: null,
/**
* Returns the HTMLLIElement for a MenuModuleItem instance.
* @type {HTMLLIElement}
*/
element: null,
/**
* Returns the HTMLElement (either HTMLLIElement, HTMLOptGroupElement or
* HTMLOptionElement) used create the MenuModuleItem instance.
* @type {HTMLLIElement/HTMLOptGroupElement/HTMLOptionElement}
*/
srcElement: null,
/**
* Specifies an arbitrary value for a MenuModuleItem instance.
* @type {Object}
*/
value: null,
/**
* Reference to the HTMLImageElement used to create the submenu
* indicator for a MenuModuleItem instance.
* @type {HTMLImageElement}
*/
submenuIndicator: null,
/**
* String representing the browser
* @type string
*/
browser: YAHOO.widget.Module.prototype.browser,
// Events
/**
* Fires when a MenuModuleItem instances's HTMLLIElement is removed from
* it's parent HTMLUListElement node.
* @type {YAHOO.util.CustomEvent}
* @see YAHOO.util.CustomEvent
*/
destroyEvent: null,
/**
* Fires when the mouse has entered a MenuModuleItem instance. Passes
* back the DOM Event object as an argument.
* @type {YAHOO.util.CustomEvent}
* @see YAHOO.util.CustomEvent
*/
mouseOverEvent: null,
/**
* Fires when the mouse has left a MenuModuleItem instance. Passes back
* the DOM Event object as an argument.
* @type {YAHOO.util.CustomEvent}
* @see YAHOO.util.CustomEvent
*/
mouseOutEvent: null,
/**
* Fires when the user mouses down on a MenuModuleItem instance. Passes
* back the DOM Event object as an argument.
* @type {YAHOO.util.Cu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -