📄 menu.js
字号:
function(p_sType, p_aArgs, p_oSubmenu) {
var sPropertyName = p_aArgs[0][0];
var oPropertyValue = p_aArgs[0][1];
switch(sPropertyName) {
case "iframe":
case "constraintoviewport":
p_oSubmenu.cfg.setProperty(sPropertyName, oPropertyValue);
break;
}
};
/**
* "render" Custom Event handler for a MenuModule instance. Renders a
* submenu in response to the firing of it's parent's "render" event.
* @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._onParentMenuModuleRender =
function(p_sType, p_aArgs, p_oSubmenu) {
/*
Set the "constraintoviewport" configuration
property to match the parent MenuModule
*/
var oParentMenu = p_oSubmenu.parent.parent;
var oConfig = {
constraintoviewport:
oParentMenu.cfg.getProperty("constraintoviewport"),
xy: [0,0]
};
/*
Only sync the "iframe" configuration property if the parent
MenuModule instance's position is of the same value
*/
if(
this.cfg.getProperty("position") ==
oParentMenu.cfg.getProperty("position")
) {
oConfig.iframe = oParentMenu.cfg.getProperty("iframe");
}
p_oSubmenu.cfg.applyConfig(oConfig);
if(this._oDom.inDocument(this.element)) {
this.render();
}
else {
this.render(this.parent.element);
}
};
/**
* "beforeshow" 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 fired
* the event.
*/
YAHOO.widget.MenuModule.prototype._onSubmenuBeforeShow =
function(p_sType, p_aArgs, p_oSubmenu) {
var oParent = this.parent;
var aAlignment = oParent.parent.cfg.getProperty("submenualignment");
this.cfg.setProperty(
"context",
[
oParent.element,
aAlignment[0],
aAlignment[1]
]
);
oParent.submenuIndicator.alt =
oParent.EXPANDED_SUBMENU_INDICATOR_ALT_TEXT;
};
/**
* "show" 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 fired
* the event.
*/
YAHOO.widget.MenuModule.prototype._onSubmenuShow =
function(p_sType, p_aArgs, p_oSubmenu) {
var oParent = this.parent;
oParent.submenuIndicator.alt =
oParent.EXPANDED_SUBMENU_INDICATOR_ALT_TEXT;
};
/**
* "hide" 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 fired
* the event.
*/
YAHOO.widget.MenuModule.prototype._onSubmenuHide =
function(p_sType, p_aArgs, p_oSubmenu) {
var oParent = this.parent;
if(oParent.parent.cfg.getProperty("visible")) {
oParent.cfg.setProperty("selected", false);
oParent.focus();
}
oParent.submenuIndicator.alt =
oParent.COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT;
};
/**
* "focus" YAHOO.util.CustomEvent handler for a MenuModule instance's items.
* @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 {Array} p_aObjects Array containing the current MenuModule instance
* and the item that fired the event.
*/
YAHOO.widget.MenuModule.prototype._onItemFocus =
function(p_sType, p_aArgs, p_aObjects) {
var me = p_aObjects[0];
var oItem = p_aObjects[1];
me.activeItem = oItem;
};
/**
* "blur" YAHOO.util.CustomEvent handler for a MenuModule instance's items.
* @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 {Array} p_aObjects Array containing the current MenuModule instance
* and the item that fired the event.
*/
YAHOO.widget.MenuModule.prototype._onItemBlur =
function(p_sType, p_aArgs, p_aObjects) {
var me = p_aObjects[0];
var oItem = p_aObjects[1];
var oSubmenu = oItem.cfg.getProperty("submenu");
if(!oSubmenu || (oSubmenu && !oSubmenu.cfg.getProperty("visible"))) {
me.activeItem = null;
}
};
/**
* "configchange" YAHOO.util.CustomEvent handler for the MenuModule
* instance's items.
* @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 {Array} p_aObjects Array containing the current MenuModule instance
* and the item that fired the event.
*/
YAHOO.widget.MenuModule.prototype._onItemConfigChange =
function(p_sType, p_aArgs, p_aObjects) {
var me = p_aObjects[0];
var sProperty = p_aArgs[0][0];
var oItem = p_aObjects[1];
switch(sProperty) {
case "submenu":
var oSubmenu = p_aArgs[0][1];
if(oSubmenu) {
me._configureItemSubmenuModule(oItem);
}
break;
case "text":
case "helptext":
/*
A change to an item's "text" or "helptext"
configuration properties requires the width of the parent
MenuModule instance to be recalculated.
*/
if(me.element.style.width) {
var sWidth = me._getOffsetWidth() + "px";
me._oDom.setStyle(me.element, "width", sWidth);
}
break;
}
};
/**
* The default event handler executed when the moveEvent is fired, if the
* "constraintoviewport" configuration property is set to true.
*/
YAHOO.widget.MenuModule.prototype.enforceConstraints =
function(type, args, obj) {
var Dom = this._oDom;
var oConfig = this.cfg;
var pos = args[0];
var x = pos[0];
var y = pos[1];
var bod = document.getElementsByTagName('body')[0];
var htm = document.getElementsByTagName('html')[0];
var bodyOverflow = Dom.getStyle(bod, "overflow");
var htmOverflow = Dom.getStyle(htm, "overflow");
var offsetHeight = this.element.offsetHeight;
var offsetWidth = this.element.offsetWidth;
var viewPortWidth = Dom.getClientWidth();
var viewPortHeight = Dom.getClientHeight();
var scrollX = window.scrollX || document.body.scrollLeft;
var scrollY = window.scrollY || document.body.scrollTop;
var topConstraint = scrollY + 10;
var leftConstraint = scrollX + 10;
var bottomConstraint = scrollY + viewPortHeight - offsetHeight - 10;
var rightConstraint = scrollX + viewPortWidth - offsetWidth - 10;
var aContext = oConfig.getProperty("context");
var oContextElement = aContext ? aContext[0] : null;
if (x < 10) {
x = leftConstraint;
} else if ((x + offsetWidth) > viewPortWidth) {
if(
oContextElement &&
((x - oContextElement.offsetWidth) > offsetWidth)
) {
x = (x - (oContextElement.offsetWidth + offsetWidth));
}
else {
x = rightConstraint;
}
}
if (y < 10) {
y = topConstraint;
} else if (y > bottomConstraint) {
if(oContextElement && (y > offsetHeight)) {
y = ((y + oContextElement.offsetHeight) - offsetHeight);
}
else {
y = bottomConstraint;
}
}
oConfig.setProperty("x", x, true);
oConfig.setProperty("y", y, true);
};
// Event handlers for configuration properties
/**
* Event handler for when the "position" configuration property of a
* MenuModule changes.
* @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 fired
* the event.
*/
YAHOO.widget.MenuModule.prototype.configPosition =
function(p_sType, p_aArgs, p_oMenuModule) {
var sCSSPosition = p_aArgs[0] == "static" ? "static" : "absolute";
this._oDom.setStyle(this.element, "position", sCSSPosition);
};
/**
* Event handler for when the "iframe" configuration property of a
* MenuModule changes.
* @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 fired
* the event.
* @see YAHOO.widget.Overlay#configIframe
*/
YAHOO.widget.MenuModule.prototype.configIframe =
function(p_sType, p_aArgs, p_oMenuModule) {
if(this.cfg.getProperty("position") == "dynamic") {
YAHOO.widget.MenuModule.superclass.configIframe.call(
this,
p_sType,
p_aArgs,
p_oMenuModule
);
}
};
// Public methods
YAHOO.widget.MenuModule.prototype.toString = function() {
return ("Menu " + this.id);
};
/**
* Sets the title of a group of items.
* @param {String} p_sGroupTitle The title of the group.
* @param {Number} p_nGroupIndex Optional. Number indicating the group to which
* the title belongs.
*/
YAHOO.widget.MenuModule.prototype.setItemGroupTitle =
function(p_sGroupTitle, p_nGroupIndex) {
if(typeof p_sGroupTitle == "string" && p_sGroupTitle.length > 0) {
var Dom = this._oDom;
var nGroupIndex =
typeof p_nGroupIndex == "number" ? p_nGroupIndex : 0;
var oTitle = this._aGroupTitleElements[nGroupIndex];
if(oTitle) {
oTitle.innerHTML = p_sGroupTitle;
}
else {
oTitle = document.createElement(this.GROUP_TITLE_TAG_NAME);
oTitle.innerHTML = p_sGroupTitle;
this._aGroupTitleElements[nGroupIndex] = oTitle;
}
var i = this._aGroupTitleElements.length - 1;
var nFirstIndex;
do {
if(this._aGroupTitleElements[i]) {
Dom.removeClass(
this._aGroupTitleElements[i],
"first-of-type"
);
nFirstIndex = i;
}
}
while(i--);
if(nFirstIndex !== null) {
Dom.addClass(
this._aGroupTitleElements[nFirstIndex],
"first-of-type"
);
}
}
};
/**
* Appends the specified item to a MenuModule instance.
* @param {YAHOO.widget.MenuModuleItem} p_oItem The item to be added.
* @param {Number} p_nGroupIndex Optional. Number indicating the group to which
* the item belongs.
* @return The item that was added to the MenuModule.
* @type YAHOO.widget.MenuModuleItem
*/
YAHOO.widget.MenuModule.prototype.addItem = function(p_oItem, p_nGroupIndex) {
if(p_oItem) {
return this._addItemToGroup(p_nGroupIndex, p_oItem);
}
};
/**
* Inserts an item into a MenuModule instance at the specified index.
* @param {YAHOO.widget.MenuModuleItem} p_oItem The item to be inserted.
* @param {Number} p_nItemIndex Number indicating the ordinal position
* at which the item should be added.
* @param {Number} p_nGroupIndex Optional. Number indicating the group to which
* the item belongs.
* @return The item that was inserted into the MenuModule.
* @type YAHOO.widget.MenuModuleItem
*/
YAHOO.widget.MenuModule.prototype.insertItem =
function(p_oItem, p_nItemIndex, p_nGroupIndex) {
if(p_oItem) {
return this._addItemToGroup(p_nGroupIndex, p_oItem, p_nItemIndex);
}
};
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -