YAHOO.widget.MenuModule = function(p_oElement, p_oUserConfig) {
if (arguments.length > 0) {
YAHOO.widget.MenuModule.superclass.constructor.call(
this,
p_oElement,
p_oUserConfig
);
}
};
YAHOO.widget.MenuModule.prototype = new YAHOO.widget.Overlay();
YAHOO.widget.MenuModule.prototype.constructor = YAHOO.widget.MenuModule;
YAHOO.widget.MenuModule.superclass = YAHOO.widget.Overlay.prototype;
YAHOO.widget.MenuModule.prototype.CSS_CLASS_NAME = "yuimenu";
YAHOO.widget.MenuModule.prototype.ITEM_TYPE = null;
YAHOO.widget.MenuModule.prototype.GROUP_TITLE_TAG_NAME = "H6";
YAHOO.widget.MenuModule.prototype._aGroupTitleElements = null;
YAHOO.widget.MenuModule.prototype._aItemGroups = null;
YAHOO.widget.MenuModule.prototype._aListElements = null;
YAHOO.widget.MenuModule.prototype._oEventUtil = YAHOO.util.Event;
YAHOO.widget.MenuModule.prototype._oDom = YAHOO.util.Dom;
YAHOO.widget.MenuModule.prototype._oCurrentItem = null;
YAHOO.widget.MenuModule.prototype._bFiredMouseOverEvent = false;
YAHOO.widget.MenuModule.prototype._bFiredMouseOutEvent = false;
YAHOO.widget.MenuModule.prototype.activeItem = null;
YAHOO.widget.MenuModule.prototype.parent = null;
YAHOO.widget.MenuModule.prototype.srcElement = null;
YAHOO.widget.MenuModule.prototype.mouseOverEvent = null;
YAHOO.widget.MenuModule.prototype.mouseOutEvent = null;
YAHOO.widget.MenuModule.prototype.mouseDownEvent = null;
YAHOO.widget.MenuModule.prototype.mouseUpEvent = null;
YAHOO.widget.MenuModule.prototype.clickEvent = null;
YAHOO.widget.MenuModule.prototype.keyPressEvent = null;
YAHOO.widget.MenuModule.prototype.keyDownEvent = null;
YAHOO.widget.MenuModule.prototype.keyUpEvent = null;
YAHOO.widget.MenuModule.prototype.init = function(p_oElement, p_oUserConfig) {
if(!this.ITEM_TYPE) {
this.ITEM_TYPE = YAHOO.widget.MenuModuleItem;
}
this._aItemGroups = [];
this._aListElements = [];
this._aGroupTitleElements = [];
var oElement;
if(typeof p_oElement == "string") {
oElement = document.getElementById(p_oElement);
}
else if(p_oElement.tagName) {
oElement = p_oElement;
}
if(oElement) {
switch(oElement.tagName) {
case "DIV":
this.srcElement = oElement;
YAHOO.widget.MenuModule.superclass.init.call(this, oElement);
this.beforeInitEvent.fire(YAHOO.widget.MenuModule);
var oNode = this.body.firstChild,
i = 0;
do {
switch(oNode.tagName) {
case this.GROUP_TITLE_TAG_NAME:
this._aGroupTitleElements[i] = oNode;
break;
case "UL":
this._aListElements[i] = oNode;
this._aItemGroups[i] = [];
i++;
break;
}
}
while((oNode = oNode.nextSibling));
if(this._aListElements[0]) {
this._oDom.addClass(this._aListElements[0], "first");
}
break;
case "SELECT":
this.srcElement = oElement;
var sId = this._oDom.generateId();
YAHOO.widget.MenuModule.superclass.init.call(this, sId);
this.beforeInitEvent.fire(YAHOO.widget.MenuModule);
break;
}
}
else {
YAHOO.widget.MenuModule.superclass.init.call(this, p_oElement);
this.beforeInitEvent.fire(YAHOO.widget.MenuModule);
}
if(this.element) {
this._oDom.addClass(this.element, this.CSS_CLASS_NAME);
this._oEventUtil.addListener(
this.element,
"mouseover",
this._onElementMouseOver,
this,
true
);
this._oEventUtil.addListener(
this.element,
"mouseout",
this._onElementMouseOut,
this,
true
);
this._oEventUtil.addListener(
this.element,
"mousedown",
this._onDOMEvent,
this,
true
);
this._oEventUtil.addListener(
this.element,
"mouseup",
this._onDOMEvent,
this,
true
);
this._oEventUtil.addListener(
this.element,
"click",
this._onElementClick,
this,
true
);
this._oEventUtil.addListener(
this.element,
"keydown",
this._onDOMEvent,
this,
true
);
this._oEventUtil.addListener(
this.element,
"keyup",
this._onDOMEvent,
this,
true
);
this._oEventUtil.addListener(
this.element,
"keypress",
this._onDOMEvent,
this,
true
);
var CustomEvent = YAHOO.util.CustomEvent;
this.mouseOverEvent = new CustomEvent("mouseOverEvent", this);
this.mouseOutEvent = new CustomEvent("mouseOutEvent", this);
this.mouseDownEvent = new CustomEvent("mouseDownEvent", this);
this.mouseUpEvent = new CustomEvent("mouseUpEvent", this);
this.clickEvent = new CustomEvent("clickEvent", this);
this.keyPressEvent = new CustomEvent("keyPressEvent", this);
this.keyDownEvent = new CustomEvent("keyDownEvent", this);
this.keyUpEvent = new CustomEvent("keyUpEvent", this);
this.beforeRenderEvent.subscribe(this._onBeforeRender, this, true);
this.renderEvent.subscribe(this._onRender, this, true);
this.showEvent.subscribe(this._onShow, this, true);
this.hideEvent.subscribe(this._onHide, this, true);
if(p_oUserConfig) {
this.cfg.applyConfig(p_oUserConfig, true);
}
this.cfg.queueProperty("visible", false);
if(this.srcElement) {
this._initSubTree();
}
}
this.initEvent.fire(YAHOO.widget.MenuModule);
};
YAHOO.widget.MenuModule.prototype._getFirstEnabledItem = function() {
var nGroups = this._aItemGroups.length,
oItem,
aItemGroup;
for(var i=0; i<nGroups; i++) {
aItemGroup = this._aItemGroups[i];
if(aItemGroup) {
var nItems = aItemGroup.length;
for(var n=0; n<nItems; n++) {
oItem = aItemGroup[n];
if(!oItem.cfg.getProperty("disabled")) {
return oItem;
}
oItem = null;
}
}
}
};
YAHOO.widget.MenuModule.prototype._checkPosition = function(p_sPosition) {
if(typeof p_sPosition == "string") {
var sPosition = p_sPosition.toLowerCase();
return ("dynamic,static".indexOf(sPosition) != -1);
}
};
YAHOO.widget.MenuModule.prototype._addItemToGroup =
function(p_nGroupIndex, p_oItem, p_nItemIndex) {
if(typeof p_nItemIndex == "number") {
var nGroupIndex = typeof p_nGroupIndex == "number" ?
p_nGroupIndex : 0,
aGroup = this._getItemGroup(nGroupIndex);
if(!aGroup) {
aGroup = this._createItemGroup(nGroupIndex);
}
var bAppend = (p_nItemIndex >= aGroup.length);
if(aGroup[p_nItemIndex]) {
aGroup.splice(p_nItemIndex, 0, p_oItem);
}
else {
aGroup[p_nItemIndex] = p_oItem;
}
var oItem = aGroup[p_nItemIndex];
if(oItem) {
if(bAppend && !oItem.element.parentNode) {
this._aListElements[nGroupIndex].appendChild(oItem.element);
}
else {
function getNextItemSibling(p_aArray, p_nStartIndex) {
return (
p_aArray[p_nStartIndex] ||
getNextItemSibling(p_aArray, (p_nStartIndex+1))
);
}
var oNextItemSibling =
getNextItemSibling(aGroup, (p_nItemIndex+1));
if(oNextItemSibling && !oItem.element.parentNode) {
this._aListElements[nGroupIndex].insertBefore(
oItem.element,
oNextItemSibling.element
);
}
}
oItem.parent = this;
this._subscribeToItemEvents(oItem);
this._configureItemSubmenuModule(oItem);
this._updateItemProperties(nGroupIndex);
return oItem;
}
}
else {
var nGroupIndex = typeof p_nGroupIndex == "number" ? p_nGroupIndex : 0,
aGroup = this._getItemGroup(nGroupIndex);
if(!aGroup) {
aGroup = this._createItemGroup(nGroupIndex);
}
var nItemIndex = aGroup.length;
aGroup[nItemIndex] = p_oItem;
var oItem = aGroup[nItemIndex];
if(oItem) {
if(
!this._oDom.isAncestor(
this._aListElements[nGroupIndex],
oItem.element
)
) {
this._aListElements[nGroupIndex].appendChild(oItem.element);
}
oItem.element.setAttribute("groupindex", nGroupIndex);
oItem.element.setAttribute("index", nItemIndex);
oItem.parent = this;
oItem.index = nItemIndex;
oItem.groupIndex = nGroupIndex;
this._subscribeToItemEvents(oItem);
this._configureItemSubmenuModule(oItem);
if(nItemIndex === 0) {
this._oDom.addClass(oItem.element, "first");
}
return oItem;
}
}
};
YAHOO.widget.MenuModule.prototype._removeItemFromGroupByIndex =
function(p_nGroupIndex, p_nItemIndex) {
var nGroupIndex = typeof p_nGroupIndex == "number" ? p_nGroupIndex : 0,
aGroup = this._getItemGroup(nGroupIndex);
if(aGroup) {
var aArray = aGroup.splice(p_nItemIndex, 1),
oItem = aArray[0];
if(oItem) {
this._updateItemProperties(nGroupIndex);
if(aGroup.length === 0) {
var oUL = this._aListElements[nGroupIndex];
if(this.body && oUL) {
this.body.removeChild(oUL);
}
this._aItemGroups.splice(nGroupIndex, 1);
this._aListElements.splice(nGroupIndex, 1);
oUL = this._aListElements[0];
if(oUL) {
this._oDom.addClass(oUL, "first");
}
}
return oItem;
}
}
};
YAHOO.widget.MenuModule.prototype._removeItemFromGroupByValue =
function(p_nGroupIndex, p_oItem) {
var aGroup = this._getItemGroup(p_nGroupIndex);
if(aGroup) {
var nItems = aGroup.length,
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
);
}
}
}
};
YAHOO.widget.MenuModule.prototype._updateItemProperties =
function(p_nGroupIndex) {
var aGroup = this._getItemGroup(p_nGroupIndex),
nItems = aGroup.length;
if(nItems > 0) {
var i = nItems - 1,
oItem,
oLI;
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);
this._oDom.removeClass(oLI, "first");
}
}
while(i--);
if(oLI) {
this._oDom.addClass(oLI, "first");
}
}
};
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];
}
};
YAHOO.widget.MenuModule.prototype._getItemGroup = function(p_nIndex) {
var nIndex = ((typeof p_nIndex == "number") ? p_nIndex : 0);
return this._aItemGroups[nIndex];
};
YAHOO.widget.MenuModule.prototype._configureItemSubmenuModule =
function(p_oItem) {
var oSubmenu = p_oItem.cfg.getProperty("submenu");
if(oSubmenu) {
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);
}
};
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
);
};
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;
};
YAHOO.widget.MenuModule.prototype._fireItemEvent =
function(p_oElement, p_sEventType, p_oDOMEvent) {
var me = this;
function getItemElement(p_oElement) {
if(p_oElement == me.element) {
return;
}
else if(p_oElement.tagName == "LI") {
return p_oElement;
}
else if(p_oElement.parentNode) {
return getItemElement(p_oElement.parentNode);
}
}
var oElement = getItemElement(p_oElement);
if(oElement) {
var nGroupIndex = parseInt(oElement.getAttribute("groupindex"), 10),
nIndex = parseInt(oElement.getAttribute("index"), 10),
oItem = this._aItemGroups[nGroupIndex][nIndex];
if(!oItem.cfg.getProperty("disabled")) {
oItem[p_sEventType].fire(p_oDOMEvent);
return oItem;
}
}
};
YAHOO.widget.MenuModule.prototype._onDOMEvent =
function(p_oEvent, p_oMenuModule) {
var oEventTypes = {
"mousedown": "mouseDownEvent",
"mouseup": "mouseUpEvent",
"keydown": "keyDownEvent",
"keyup": "keyUpEvent",
"keypress": "keyPressEvent"
},
sCustomEventType = oEventTypes[p_oEvent.type],
oTarget = this._oEventUtil.getTarget(p_oEvent, true);
this._fireItemEvent(oTarget, sCustomEventType, p_oEvent);
this[sCustomEventType].fire(p_oEvent);
this._oEventUtil.stopPropagation(p_oEvent);
};
YAHOO.widget.MenuModule.prototype._onElementMouseOver =
function(p_oEvent, p_oMenuModule) {
var oTarget = this._oEventUtil.getTarget(p_oEvent, true);
if(
(
oTarget == this.element ||
this._oDom.isAncestor(this.element, oTarget)
) &&
!this._bFiredMouseOverEvent
) {
this.mouseOverEvent.fire(p_oEvent);
this._bFiredMouseOverEvent = true;
this._bFiredMouseOutEvent = false;
}
if(!this._oCurrentItem) {
this._oCurrentItem =
this._fireItemEvent(oTarget, "mouseOverEvent", p_oEvent);
}
this._oEventUtil.stopPropagation(p_oEvent);
};
YAHOO.widget.MenuModule.prototype._onElementMouseOut =
function(p_oEvent, p_oMenuModule) {
var oRelatedTarget = this._oEventUtil.getRelatedTarget(p_oEvent),
bLIMouseOut = true,
bMovingToSubmenu = false;
if(this._oCurrentItem && oRelatedTarget) {
if(
oRelatedTarget == this._oCurrentItem.element ||
this._oDom.isAncestor(
this._oCurrentItem.element,
oRelatedTarget
)
) {
bLIMouseOut = false;
}
var oSubmenu = this._oCurrentItem.cfg.getProperty("submenu");
if(
oSubmenu &&
(
oRelatedTarget == oSubmenu.element ||
this._oDom.isAncestor(oSubmenu.element, oRelatedTarget)
)
) {
bMovingToSubmenu = true;
}
}
if(this._oCurrentItem && (bLIMouseOut || bMovingToSubmenu)) {
this._oCurrentItem.mouseOutEvent.fire(p_oEvent);
this._oCurrentItem = null;
}
if(
!this._bFiredMouseOutEvent &&
(
!this._oDom.isAncestor(this.element, oRelatedTarget) ||
bMovingToSubmenu
)
) {
this.mouseOutEvent.fire(p_oEvent);
this._bFiredMouseOutEvent = true;
this._bFiredMouseOverEvent = false;
}
this._oEventUtil.stopPropagation(p_oEvent);
};
YAHOO.widget.MenuModule.prototype._onElementClick =
function(p_oEvent, p_oMenuModule) {
var oTarget = this._oEventUtil.getTarget(p_oEvent, true),
oItem = this._fireItemEvent(oTarget, "clickEvent", p_oEvent),
bCurrentPageURL; // Indicates if the URL points to the current page
if(oItem) {
var sURL = oItem.cfg.getProperty("url"),
oSubmenu = oItem.cfg.getProperty("submenu");
bCurrentPageURL = (sURL.substr((sURL.length-1),1) == "#");
if(oTarget == oItem.subMenuIndicator && oSubmenu) {
if(oSubmenu.cfg.getProperty("visible")) {
oSubmenu.hide();
}
else {
var oActiveItem = this.activeItem;
if(oActiveItem && oActiveItem != this) {
this.clearActiveItem();
}
this.activeItem = oItem;
oItem.cfg.setProperty("selected", true);
oSubmenu.show();
}
}
else if(!bCurrentPageURL) {
document.location = sURL;
}
}
switch(oTarget.tagName) {
case "A":
if(bCurrentPageURL) {
this._oEventUtil.preventDefault(p_oEvent);
}
else {
break;
}
default:
this._oEventUtil.stopPropagation(p_oEvent);
break;
}
this.clickEvent.fire(p_oEvent);
};
YAHOO.widget.MenuModule.prototype._initSubTree = function() {
var oNode;
switch(this.srcElement.tagName) {
case "DIV":
if(this._aListElements.length > 0) {
var i = this._aListElements.length - 1;
do {
oNode = this._aListElements[i].firstChild;
do {
switch(oNode.tagName) {
case "LI":
this.addItem(new this.ITEM_TYPE(oNode), i);
break;
}
}
while((oNode = oNode.nextSibling));
}
while(i--);
}
break;
case "SELECT":
oNode = this.srcElement.firstChild;
do {
switch(oNode.tagName) {
case "OPTGROUP":
case "OPTION":
this.addItem(new this.ITEM_TYPE(oNode));
break;
}
}
while((oNode = oNode.nextSibling));
break;
}
};
YAHOO.widget.MenuModule.prototype._onBeforeRender =
function(p_sType, p_aArguments, p_oMenuModule) {
if(this.cfg.getProperty("position") == "static") {
this.cfg.queueProperty("iframe", false);
this.cfg.queueProperty("visible", true);
}
var nListElements = this._aListElements.length;
if(nListElements > 0) {
var i = 0,
bFirstList = true,
oUL,
oGroupTitle;
do {
oUL = this._aListElements[i];
if(oUL) {
if(bFirstList) {
this._oDom.addClass(oUL, "first");
bFirstList = false;
}
if(!this._oDom.isAncestor(this.element, oUL)) {
this.appendToBody(oUL);
}
oGroupTitle = this._aGroupTitleElements[i];
if(oGroupTitle) {
if(!this._oDom.isAncestor(this.element, oGroupTitle)) {
oUL.parentNode.insertBefore(oGroupTitle, oUL);
}
this._oDom.addClass(oUL, "hastitle");
}
}
i++;
}
while(i < nListElements);
}
};
YAHOO.widget.MenuModule.prototype._onRender =
function(p_sType, p_aArguments, 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"));
}
};
YAHOO.widget.MenuModule.prototype._onShow =
function(p_sType, p_aArguments, p_oMenuModule) {
this.setInitialFocus();
};
YAHOO.widget.MenuModule.prototype._onHide =
function(p_sType, p_aArguments, p_oMenuModule) {
if(this.activeItem) {
if(this.activeItem.cfg.getProperty("selected")) {
this.activeItem.cfg.setProperty("selected", false);
this.activeItem.blur();
}
var oSubmenu = this.activeItem.cfg.getProperty("submenu");
if(oSubmenu && oSubmenu.cfg.getProperty("visible")) {
oSubmenu.hide();
}
}
};
YAHOO.widget.MenuModule.prototype._onParentMenuModuleConfigChange =
function(p_sType, p_aArguments, p_oSubmenu) {
var sPropertyName = p_aArguments[0][0],
oPropertyValue = p_aArguments[0][1];
switch(sPropertyName) {
case "iframe":
case "constraintoviewport":
case "submenualignment":
p_oSubmenu.cfg.setProperty(sPropertyName, oPropertyValue);
break;
}
};
YAHOO.widget.MenuModule.prototype._onParentMenuModuleRender =
function(p_sType, p_aArguments, p_oSubmenu) {
var oParentMenu = p_oSubmenu.parent.parent;
p_oSubmenu.cfg.applyConfig(
{
constraintoviewport:
oParentMenu.cfg.getProperty("constraintoviewport"),
xy: [0,0],
iframe: oParentMenu.cfg.getProperty("iframe")
}
);
if(this._oDom.inDocument(this.element)) {
this.render();
}
else {
this.render(this.parent.element);
}
};
YAHOO.widget.MenuModule.prototype._onSubmenuBeforeShow =
function(p_sType, p_aArguments, p_oSubmenu) {
var aAlignment = this.parent.parent.cfg.getProperty("submenualignment");
this.cfg.setProperty(
"context",
[
this.parent.element,
aAlignment[0],
aAlignment[1]
]
);
this.parent.subMenuIndicator.alt =
this.parent.EXPANDED_SUBMENU_INDICATOR_ALT_TEXT;
};
YAHOO.widget.MenuModule.prototype._onSubmenuShow =
function(p_sType, p_aArguments, p_oSubmenu) {
this.parent.subMenuIndicator.alt =
this.parent.EXPANDED_SUBMENU_INDICATOR_ALT_TEXT;
};
YAHOO.widget.MenuModule.prototype._onSubmenuHide =
function(p_sType, p_aArguments, p_oSubmenu) {
if(this.parent.parent.cfg.getProperty("visible")) {
this.parent.cfg.setProperty("selected", false);
this.parent.focus();
}
this.parent.subMenuIndicator.alt =
this.parent.COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT;
};
YAHOO.widget.MenuModule.prototype._onItemFocus =
function(p_sType, p_aArguments, p_aObjects) {
var me = p_aObjects[0],
oItem = p_aObjects[1];
me.activeItem = oItem;
};
YAHOO.widget.MenuModule.prototype._onItemBlur =
function(p_sType, p_aArguments, p_aObjects) {
var me = p_aObjects[0],
oItem = p_aObjects[1],
oSubmenu = oItem.cfg.getProperty("submenu");
if(!oSubmenu || (oSubmenu && !oSubmenu.cfg.getProperty("visible"))) {
me.activeItem = null;
}
};
YAHOO.widget.MenuModule.prototype._onItemConfigChange =
function(p_sType, p_aArguments, p_aObjects) {
var sProperty = p_aArguments[0][0],
me = p_aObjects[0],
oItem = p_aObjects[1];
switch(sProperty) {
case "submenu":
var oSubmenu = p_aArguments[0][1];
if(oSubmenu) {
me._configureItemSubmenuModule(oItem);
}
break;
case "text":
case "helptext":
if(me.element.style.width) {
var sWidth = me._getOffsetWidth() + "px";
me._oDom.setStyle(me.element, "width", sWidth);
}
break;
}
};
YAHOO.widget.MenuModule.prototype.enforceConstraints =
function(type, args, obj) {
var pos = args[0],
x = pos[0],
y = pos[1],
bod = document.getElementsByTagName('body')[0],
htm = document.getElementsByTagName('html')[0],
bodyOverflow = YAHOO.util.Dom.getStyle(bod, "overflow"),
htmOverflow = YAHOO.util.Dom.getStyle(htm, "overflow"),
offsetHeight = this.element.offsetHeight,
offsetWidth = this.element.offsetWidth,
viewPortWidth = YAHOO.util.Dom.getClientWidth(),
viewPortHeight = YAHOO.util.Dom.getClientHeight(),
scrollX = window.scrollX || document.body.scrollLeft,
scrollY = window.scrollY || document.body.scrollTop,
topConstraint = scrollY + 10,
leftConstraint = scrollX + 10,
bottomConstraint = scrollY + viewPortHeight - offsetHeight - 10,
rightConstraint = scrollX + viewPortWidth - offsetWidth - 10,
aContext = this.cfg.getProperty("context"),
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;
}
}
this.cfg.setProperty("x", x, true);
this.cfg.setProperty("y", y, true);
};
YAHOO.widget.MenuModule.prototype.configPosition =
function(p_sType, p_aArguments, p_oMenuModule) {
var sCSSPosition = p_aArguments[0] == "static" ? "static" : "absolute";
this._oDom.setStyle(this.element, "position", sCSSPosition);
};
YAHOO.widget.MenuModule.prototype.setItemGroupTitle =
function(p_sGroupTitle, p_nGroupIndex) {
if(typeof p_sGroupTitle == "string" && p_sGroupTitle.length > 0) {
var nGroupIndex =
typeof p_nGroupIndex == "number" ? p_nGroupIndex : 0,
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,
nFirstIndex;
do {
if(this._aGroupTitleElements[i]) {
this._oDom.removeClass(
this._aGroupTitleElements[i],
"first"
);
nFirstIndex = i;
}
}
while(i--);
if(nFirstIndex !== null) {
this._oDom.addClass(
this._aGroupTitleElements[nFirstIndex],
"first"
);
}
}
};
YAHOO.widget.MenuModule.prototype.addItem = function(p_oItem, p_nGroupIndex) {
if(p_oItem && p_oItem instanceof YAHOO.widget.MenuModuleItem) {
return this._addItemToGroup(p_nGroupIndex, p_oItem);
}
};
YAHOO.widget.MenuModule.prototype.insertItem =
function(p_oItem, p_nItemIndex, p_nGroupIndex) {
if(p_oItem && p_oItem instanceof YAHOO.widget.MenuModuleItem) {
return this._addItemToGroup(p_nGroupIndex, p_oItem, p_nItemIndex);
}
};
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;
}
}
};
YAHOO.widget.MenuModule.prototype.getItemGroups = function() {
return this._aItemGroups;
};
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];
}
}
};
YAHOO.widget.MenuModule.prototype.destroy = function() {
this._oEventUtil.removeListener(
this.element,
"mouseover",
this._onElementMouseOver
);
this._oEventUtil.removeListener(
this.element,
"mouseout",
this._onElementMouseOut
);
this._oEventUtil.removeListener(
this.element,
"click",
this._onElementClick
);
this._oEventUtil.removeListener(
this.element,
"mousedown",
this._onDOMEvent
);
this._oEventUtil.removeListener(this.element, "mouseup", this._onDOMEvent);
this._oEventUtil.removeListener(this.element, "keydown", this._onDOMEvent);
this._oEventUtil.removeListener(this.element, "keyup", this._onDOMEvent);
this._oEventUtil.removeListener(this.element, "keypress", this._onDOMEvent);
this.mouseOverEvent.unsubscribeAll();
this.mouseOutEvent.unsubscribeAll();
this.mouseDownEvent.unsubscribeAll();
this.mouseUpEvent.unsubscribeAll();
this.clickEvent.unsubscribeAll();
this.keyPressEvent.unsubscribeAll();
this.keyDownEvent.unsubscribeAll();
this.keyUpEvent.unsubscribeAll();
this.beforeMoveEvent.unsubscribeAll();
var nItemGroups = this._aItemGroups.length,
nItems,
i,
n;
if(nItemGroups > 0) {
i = nItemGroups - 1;
do {
if(this._aItemGroups[i]) {
nItems = this._aItemGroups[i].length;
if(nItems > 0) {
n = nItems - 1;
do {
if(this._aItemGroups[i][n]) {
this._aItemGroups[i][n].destroy();
}
}
while(n--);
}
}
}
while(i--);
}
YAHOO.widget.MenuModule.superclass.destroy.call(this);
};
YAHOO.widget.MenuModule.prototype.setInitialFocus = function() {
var oItem = this._getFirstEnabledItem();
if(oItem) {
oItem.focus();
}
};
YAHOO.widget.MenuModule.prototype.setInitialSelection = function() {
var oItem = this._getFirstEnabledItem();
if(oItem) {
oItem.cfg.setProperty("selected", true);
}
};
YAHOO.widget.MenuModule.prototype.clearActiveItem = function () {
var oActiveItem = this.activeItem;
if(oActiveItem) {
oActiveItem.cfg.setProperty("selected", false);
var oSubmenu = oActiveItem.cfg.getProperty("submenu");
if(oSubmenu) {
oSubmenu.hide();
}
}
};
YAHOO.widget.MenuModule.prototype.initDefaultConfig = function() {
YAHOO.widget.MenuModule.superclass.initDefaultConfig.call(this);
this.cfg.addProperty(
"position",
{
value: "dynamic",
handler: this.configPosition,
validator: this._checkPosition
}
);
this.cfg.addProperty("submenualignment", { value: ["tl","tr"] } );
};