📄 menu.js
字号:
};
/**
* Removes an item from a group by index.
* @private
* @param {Number} p_nGroupIndex Number indicating the group to which
* the item belongs.
* @param {Number} p_nItemIndex Number indicating the index of the item to
* be removed.
* @return The item that was removed.
* @type YAHOO.widget.MenuModuleItem
*/
YAHOO.widget.MenuModule.prototype._removeItemFromGroupByIndex =
function(p_nGroupIndex, p_nItemIndex) {
var nGroupIndex = typeof p_nGroupIndex == "number" ? p_nGroupIndex : 0;
var aGroup = this._getItemGroup(nGroupIndex);
if(aGroup) {
var aArray = aGroup.splice(p_nItemIndex, 1);
var oItem = aArray[0];
if(oItem) {
// Update the index and className properties of each member
this._updateItemProperties(nGroupIndex);
if(aGroup.length === 0) {
// Remove the UL
var oUL = this._aListElements[nGroupIndex];
if(this.body && oUL) {
this.body.removeChild(oUL);
}
// Remove the group from the array of items
this._aItemGroups.splice(nGroupIndex, 1);
// Remove the UL from the array of ULs
this._aListElements.splice(nGroupIndex, 1);
/*
Assign the "first-of-type" class to the new first UL
in the collection
*/
oUL = this._aListElements[0];
if(oUL) {
this._oDom.addClass(oUL, "first-of-type");
}
}
// Return a reference to the item that was removed
return oItem;
}
}
};
/**
* Removes a item from a group by reference.
* @private
* @param {Number} p_nGroupIndex Number indicating the group to which
* the item belongs.
* @param {YAHOO.widget.MenuModuleItem} p_oItem The item to be removed.
* @return The item that was removed.
* @type YAHOO.widget.MenuModuleItem
*/
YAHOO.widget.MenuModule.prototype._removeItemFromGroupByValue =
function(p_nGroupIndex, p_oItem) {
var aGroup = this._getItemGroup(p_nGroupIndex);
if(aGroup) {
var nItems = aGroup.length;
var nItemIndex = -1;
if(nItems > 0) {
var i = nItems-1;
do {
if(aGroup[i] == p_oItem) {
nItemIndex = i;
break;
}
}
while(i--);
if(nItemIndex > -1) {
return this._removeItemFromGroupByIndex(
p_nGroupIndex,
nItemIndex
);
}
}
}
};
/**
* Updates the index, groupindex, and className properties of the items
* in the specified group.
* @private
* @param {Number} p_nGroupIndex Number indicating the group of items to update.
*/
YAHOO.widget.MenuModule.prototype._updateItemProperties =
function(p_nGroupIndex) {
var aGroup = this._getItemGroup(p_nGroupIndex);
var nItems = aGroup.length;
if(nItems > 0) {
var Dom = this._oDom;
var i = nItems - 1;
var oItem;
var oLI;
// Update the index and className properties of each member
do {
oItem = aGroup[i];
if(oItem) {
oLI = oItem.element;
oItem.index = i;
oItem.groupIndex = p_nGroupIndex;
oLI.setAttribute("groupindex", p_nGroupIndex);
oLI.setAttribute("index", i);
Dom.removeClass(oLI, "first-of-type");
}
}
while(i--);
if(oLI) {
Dom.addClass(oLI, "first-of-type");
}
}
};
/**
* Creates a new item group (array) and it's associated HTMLUlElement node
* @private
* @param {Number} p_nIndex Number indicating the group to create.
* @return An item group.
* @type Array
*/
YAHOO.widget.MenuModule.prototype._createItemGroup = function(p_nIndex) {
if(!this._aItemGroups[p_nIndex]) {
this._aItemGroups[p_nIndex] = [];
var oUL = document.createElement("ul");
this._aListElements[p_nIndex] = oUL;
return this._aItemGroups[p_nIndex];
}
};
/**
* Returns the item group at the specified index.
* @private
* @param {Number} p_nIndex Number indicating the index of the item group to
* be retrieved.
* @return An array of items.
* @type Array
*/
YAHOO.widget.MenuModule.prototype._getItemGroup = function(p_nIndex) {
var nIndex = ((typeof p_nIndex == "number") ? p_nIndex : 0);
return this._aItemGroups[nIndex];
};
/**
* Subscribe's a MenuModule instance to it's parent MenuModule instance's events.
* @private
* @param {YAHOO.widget.MenuModuleItem} p_oItem The item to listen
* for events on.
*/
YAHOO.widget.MenuModule.prototype._configureItemSubmenuModule =
function(p_oItem) {
var oSubmenu = p_oItem.cfg.getProperty("submenu");
if(oSubmenu) {
/*
Listen for configuration changes to the parent MenuModule
instance so they they can be applied to the submenu.
*/
this.cfg.configChangedEvent.subscribe(
this._onParentMenuModuleConfigChange,
oSubmenu,
true
);
this.renderEvent.subscribe(
this._onParentMenuModuleRender,
oSubmenu,
true
);
oSubmenu.beforeShowEvent.subscribe(
this._onSubmenuBeforeShow,
oSubmenu,
true
);
oSubmenu.showEvent.subscribe(this._onSubmenuShow, oSubmenu, true);
oSubmenu.hideEvent.subscribe(this._onSubmenuHide, oSubmenu, true);
}
};
/**
* Subscribes a MenuModule instance to the specified item's Custom Events.
* @private
* @param {YAHOO.widget.MenuModuleItem} p_oItem The item to listen for events on.
*/
YAHOO.widget.MenuModule.prototype._subscribeToItemEvents = function(p_oItem) {
var aArguments = [this, p_oItem];
p_oItem.focusEvent.subscribe(this._onItemFocus, aArguments);
p_oItem.blurEvent.subscribe(this._onItemBlur, aArguments);
p_oItem.cfg.configChangedEvent.subscribe(
this._onItemConfigChange,
aArguments
);
};
/**
* Returns the offset width of a MenuModule instance.
* @private
*/
YAHOO.widget.MenuModule.prototype._getOffsetWidth = function() {
var oClone = this.element.cloneNode(true);
this._oDom.setStyle(oClone, "width", "");
document.body.appendChild(oClone);
var sWidth = oClone.offsetWidth;
document.body.removeChild(oClone);
return sWidth;
};
// Private Custom Event handlers
/**
* "init" Custom Event handler for a MenuModule instance.
* @private
* @param {String} p_sType The name of the event that was fired.
* @param {Array} p_aArgs Collection of arguments sent when the event
* was fired.
* @param {YAHOO.widget.MenuModule} p_oMenuModule The MenuModule instance that
* fired the event.
*/
YAHOO.widget.MenuModule.prototype._onInit =
function(p_sType, p_aArgs, p_oMenuModule) {
var sCSSPosition = (this.cfg.getProperty("position") == "static") ?
"static" : "absolute";
this._oDom.setStyle(this.element, "position", sCSSPosition);
};
/**
* "beforerender" Custom Event handler for a MenuModule instance. Appends all
* of the HTMLUListElement (<UL<s) nodes (and their child
* HTMLLIElement (<LI<)) nodes and their accompanying title nodes to
* the body of the MenuModule instance.
* @private
* @param {String} p_sType The name of the event that was fired.
* @param {Array} p_aArgs Collection of arguments sent when the event
* was fired.
* @param {YAHOO.widget.MenuModule} p_oMenuModule The MenuModule instance that
* fired the event.
*/
YAHOO.widget.MenuModule.prototype._onBeforeRender =
function(p_sType, p_aArgs, p_oMenuModule) {
var Dom = this._oDom;
var oConfig = this.cfg;
var oEl = this.element;
var nListElements = this._aListElements.length;
if(oConfig.getProperty("position") == "static") {
oConfig.queueProperty("iframe", false);
oConfig.queueProperty("visible", true);
}
if(nListElements > 0) {
var i = 0;
var bFirstList = true;
var oUL;
var oGroupTitle;
do {
oUL = this._aListElements[i];
if(oUL) {
if(bFirstList) {
Dom.addClass(oUL, "first-of-type");
bFirstList = false;
}
if(!Dom.isAncestor(oEl, oUL)) {
this.appendToBody(oUL);
}
oGroupTitle = this._aGroupTitleElements[i];
if(oGroupTitle) {
if(!Dom.isAncestor(oEl, oGroupTitle)) {
oUL.parentNode.insertBefore(oGroupTitle, oUL);
}
Dom.addClass(oUL, "hastitle");
}
}
i++;
}
while(i < nListElements);
}
};
/**
* "render" Custom Event handler for a MenuModule instance.
* @private
* @param {String} p_sType The name of the event that was fired.
* @param {Array} p_aArgs Collection of arguments sent when the event
* was fired.
* @param {YAHOO.widget.MenuModule} p_oMenuModule The MenuModule instance that
* fired the event.
*/
YAHOO.widget.MenuModule.prototype._onRender =
function(p_sType, p_aArgs, p_oMenuModule) {
if(this.cfg.getProperty("position") == "dynamic") {
var sWidth = this.element.parentNode.tagName == "BODY" ?
this.element.offsetWidth : this._getOffsetWidth();
this.cfg.setProperty("width", (sWidth + "px"));
}
};
/**
* "show" Custom Event handler for a MenuModule instance.
* @private
* @param {String} p_sType The name of the event that was fired.
* @param {Array} p_aArgs Collection of arguments sent when the event
* was fired.
* @param {YAHOO.widget.MenuModule} p_oMenuModule The MenuModule instance that
* fired the event.
*/
YAHOO.widget.MenuModule.prototype._onShow =
function(p_sType, p_aArgs, p_oMenuModule) {
/*
Setting focus to an item in the newly visible submenu alerts the
contents of the submenu to the screen reader.
*/
this.setInitialFocus();
};
/**
* "hide" Custom Event handler for a MenuModule instance.
* @private
* @param {String} p_sType The name of the event that was fired.
* @param {Array} p_aArgs Collection of arguments sent when the event
* was fired.
* @param {YAHOO.widget.MenuModule} p_oMenuModule The MenuModule instance that
* fired the event.
*/
YAHOO.widget.MenuModule.prototype._onBeforeHide =
function(p_sType, p_aArgs, p_oMenuModule) {
var oActiveItem = this.activeItem;
if(oActiveItem) {
oActiveItem.blur();
if(oActiveItem.cfg.getProperty("selected")) {
oActiveItem.cfg.setProperty("selected", false);
}
var oSubmenu = oActiveItem.cfg.getProperty("submenu");
if(oSubmenu && oSubmenu.cfg.getProperty("visible")) {
oSubmenu.hide();
}
}
};
/**
* "configchange" Custom Event handler for a submenu.
* @private
* @param {String} p_sType The name of the event that was fired.
* @param {Array} p_aArgs Collection of arguments sent when the event
* was fired.
* @param {YAHOO.widget.MenuModule} p_oSubmenu The submenu that subscribed
* to the event.
*/
YAHOO.widget.MenuModule.prototype._onParentMenuModuleConfigChange =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -