/******************************************************************************************************************************** * Licensed Materials - Property of IBM * * * * IBM Cognos Products: AGS * * * * (C) Copyright IBM Corp. 2005, 2008 * * * * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * *********************************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------- Class : CMenu Description : -----------------------------------------------------------------------------------------------------*/ //this compensates for a difference in calculation of the page width by 18 pixels //in mozilla and netscape versus IE var MOZILLA_PAGE_WIDTH_COMPENSATION = 18; function CMenu(id,style) { this.m_htmlContainer = document.body; this.m_bVisible = false; this.m_id = id; this.m_htmlDivElement = null; this.m_parent = null; this.m_menuItems = new Array(); this.m_style = style; this.m_callback = null; this.m_observers = new CObserver(this); this.m_offsetXCoords = 0; this.m_offsetYCoords = 0; this.m_bContainsCascadedChildren = false; } function CMenu_setHTMLContainer(container) { this.m_htmlContainer = container; } function CMenu_getHTMLContainer() { return this.m_htmlContainer; } function CMenu_setParent(parent) { this.m_parent = parent; } function CMenu_getParent() { return this.m_parent; } function CMenu_getId() { return this.m_id; } function CMenu_getHTMLDiv() { return this.m_htmlDivElement; } function CMenu_create() { newElement = (document.all && typeof this.m_htmlContainer.document != "undefined") ? this.m_htmlContainer.document.createElement("div") : this.m_htmlContainer.ownerDocument.createElement("div"); if(typeof this.getStyle() == "object") newElement.className = this.getStyle().getNormalState(); newElement.style.display = "none"; newElement.style.position = "absolute"; newElement.id = this.m_id; //append the new menu this.m_htmlContainer.appendChild(newElement); //create a reference to it this.m_htmlDivElement = newElement; } function CMenu_draw() { if(this.m_htmlContainer == null) return; if(this.m_htmlDivElement == null) this.create(); var html=''; if(this.m_menuItems.length == 0) { if(this.m_callback != null) { menu = this; setTimeout("menu.executeCallback()", 1000); // build a html div with a wait cursor html=''; html += ''; html += ''; html += ''; html += ''; html += ''; } } else { //add the items var i=0; var html=''; for (i=0; i < this.m_menuItems.length; i++) { if(this.m_menuItems[i].isVisible()) { html += ''; } } html += '
'; html += this.m_menuItems[i].draw(); html += '
'; } try { this.m_htmlDivElement.innerHTML = html; // attach the event handlers this.attachEvents(); } catch (e) { } } function CMenu_updateCoords() { //set the z-index first, we still need to set it even if the menu doesn't have a parent //and the coordinates are not set, This is to ensure that the hidden 'shim' is displayed //underneath the menu this.setZIndex(500); myParent = this.getParent(); if(this.getHTMLDiv() == null || myParent == null || ( !(myParent instanceof CToolbarButton) && !(myParent instanceof CMenuItem) ) ) { return; } // make sure the parent has implemented the method "getMenuType" if(typeof myParent.getMenuType != 'function') { return; } var x=0; var y=0; myParentHTMLElement = document.getElementById(this.getParent().getId()); if(myParentHTMLElement == null) return; var current = myParentHTMLElement; // calculate the page width var pageWidth = 0; if(typeof window.innerWidth != "undefined") pageWidth = window.innerWidth - MOZILLA_PAGE_WIDTH_COMPENSATION; else pageWidth = document.body.clientWidth; // calculate the page height var pageHeight = 0; if(typeof window.innerHeight != "undefined") pageHeight = window.innerHeight; else pageHeight = document.body.clientHeight; // handle drop down menus if(myParent.getMenuType() == 'dropDown') { x = document.body.scrollLeft; y = myParentHTMLElement.offsetHeight + document.body.scrollTop; while(current != null) { x += current.offsetLeft; y += current.offsetTop; current = current.offsetParent; } // if the right side of the drop down menu extends beyond browser window viewing area, adjust accordingly if((x + this.getHTMLDiv().offsetWidth) > pageWidth) { x = pageWidth - this.getHTMLDiv().offsetWidth; } // if the bottom of the drop down menu extends below the browser viewing area and there is enough room to draw at the top, then draw to the top if(((y + this.getHTMLDiv().offsetHeight) > pageHeight) && (y - (this.getHTMLDiv().offsetHeight + myParentHTMLElement.clientHeight) >= 0)) { y -= (this.getHTMLDiv().offsetHeight + myParentHTMLElement.clientHeight); } } else if(myParent.getMenuType() == 'cascaded') { x = myParentHTMLElement.offsetWidth + document.body.scrollLeft; y = document.body.scrollTop; while(current != null) { x += current.offsetLeft; y += current.offsetTop; current = current.offsetParent; } // if the right side of the cascaded menu extends beyond the viewing area of the browser window right side, render to the left insted of the right if((x + this.getHTMLDiv().offsetWidth) > pageWidth) { x -= myParentHTMLElement.offsetWidth + this.getHTMLDiv().offsetWidth; } // if the bottom of the cascaded menu extends beyond the bottom of the browser viewing area, draw to the top if((y + this.getHTMLDiv().offsetHeight) > pageHeight) { y -= (this.getHTMLDiv().offsetHeight-myParentHTMLElement.clientHeight); } } this.setXCoord(x); this.setYCoord(y); } function CMenu_add(menuItem) { if(typeof menuItem.getObservers == "function" && typeof menuItem.getObservers() == "object") { menuItem.getObservers().attach(this, this.closeSubMenus, menuItem.onmouseover); menuItem.getObservers().attach(this, this.closeAllMenus, menuItem.onmouseup); menuItem.getObservers().attach(this, this.closeSubMenus, menuItem.onfocus); menuItem.getObservers().attach(this, this.closeAllMenus, menuItem.onkeypress); } this.m_menuItems[this.m_menuItems.length] = menuItem; } function CMenu_get(index) { if(index >= 0 && index < this.getNumItems()) { return this.m_menuItems[index]; } return null; } function CMenu_getNumItems() { return this.m_menuItems.length; } function CMenu_hide() { if(this.m_htmlDivElement != null) { this.m_htmlDivElement.style.display = "none"; this.hideHiddenIframe(); } this.m_bVisible = false; // get the actual element that spawned the menu var theControl = this.getParent(); if (theControl != null && typeof theControl.setFocus == "function") theControl.setFocus(); } function CMenu_show() { if(this.m_htmlDivElement != null) { var htmlElementId = this.m_htmlDivElement.id; this.m_htmlDivElement.style.display = "block"; this.m_bVisible = true; // update the x and y coords this.updateCoords(); var isNS7 = ((!document.all) && (document.getElementById)) ? true : false; var iFrameId = "uiFrameworkHiddenIframe"+this.m_id; var hiddenIframeElement = document.getElementById(iFrameId); //create the shim and set its size and coords based on the parent menu if (hiddenIframeElement == null) { hiddenIframeElement = this.createHiddenIFrame(iFrameId); } //show the shim if(hiddenIframeElement) { hiddenIframeElement.style.display = "block"; updateIframeCoords(iFrameId, htmlElementId, isNS7); setTimeout('updateIframeCoords("'+iFrameId+'", "'+htmlElementId+'", '+isNS7+')',50); } if (!isNS7) { try { this.m_htmlDivElement.focus(); } catch (e) { } } } } function CMenu_createHiddenIFrame(iFrameId) { var container = this.getHTMLContainer(); var iframeElem = (document.all && typeof container.document != "undefined") ? container.document.createElement("iframe") : container.ownerDocument.createElement("iframe"); iframeElem.setAttribute("id",iFrameId); iframeElem.setAttribute("src",'../common/images/spacer.gif'); iframeElem.setAttribute("scrolling",'no'); iframeElem.setAttribute("frameborder",'0'); iframeElem.style.position='absolute'; iframeElem.style.minWidth='0px'; iframeElem.style.minHeight='0px'; iframeElem.style.left='0px'; iframeElem.style.top='0px'; iframeElem.style.zIndex=-499; iframeElem.style.display='none'; container.appendChild(iframeElem); return iframeElem; } function CMenu_isVisible() { return this.m_bVisible; } function CMenu_remove(childClicked) { for(var i = 0; i < this.getNumItems(); ++i) { var currentItem = this.get(i); if(typeof currentItem.getMenu == "function" && currentItem.getMenu() != null) currentItem.getMenu().remove(); } //Only enable when not clicking this items parent. if (this.getParent && this.getParent() instanceof CMenuItem && !childClicked) { this.getParent().enable(); } if(this.m_htmlContainer != null && this.m_htmlDivElement != null) { this.m_htmlContainer.removeChild(this.m_htmlDivElement); } this.m_bVisible = false; this.m_htmlDivElement = null; this.hideHiddenIframe(); } function CMenu_hideHiddenIframe(forceHide) { var hiddenIframeElement = document.getElementById("uiFrameworkHiddenIframe"+this.m_id); if(hiddenIframeElement) { hiddenIframeElement.style.display = "none"; } } function CMenu_enable() { } function CMenu_disable() { } function CMenu_getState() { } function CMenu_clear() { if(this.m_htmlDivElement != null) this.m_htmlDivElement.innerHTML=''; this.m_menuItems.splice(0, this.m_menuItems.length) } function CMenu_attachEvents() { for(var i = 0; i < this.m_menuItems.length; i++) { if(typeof this.m_menuItems[i].attachEvents == "function") this.m_menuItems[i].attachEvents(); } } function CMenu_closeSubMenus(state) { // Called during a notification... // make sure we hide any submenus which have been opened. for(var i = 0; i < this.m_menuItems.length; i++) { menuItem = this.m_menuItems[i]; subject = state.getSubject(); if(menuItem != subject && typeof menuItem.getMenu == "function" && menuItem.getMenu() != null && menuItem.getMenu().isVisible()) { menuItem.getMenu().remove(); } } } function CMenu_closeAllMenus(state) { // Called during a notification... current = this; var highestMenu = null; while(current) { if(current instanceof CMenu) { highestMenu = current; } //not always guaranteed to have a parent, for example drop down combo boxes if (current.getParent) { current = current.getParent(); } else { current=null; } } if(highestMenu != null) highestMenu.remove(); } function CMenu_setStyle(style) { this.m_style = style; } function CMenu_getStyle() { return this.m_style; } function CMenu_setOffsetXCoords(x) { if (x && x != 'undefined') this.m_offsetXCoords = x; } function CMenu_setOffsetYCoords(y) { if (y && y != 'undefined') this.m_offsetYCoords = y; } function CMenu_setContainsCascadedChildren(flag) { this.m_bContainsCascadedChildren = flag; } function CMenu_hasCascadedChildren() { return this.m_bContainsCascadedChildren; } function CMenu_setXCoord(x) { htmlDiv = this.getHTMLDiv(); if(htmlDiv != null) htmlDiv.style.left = x + this.m_offsetXCoords + "px"; } function CMenu_setYCoord(y) { htmlDiv = this.getHTMLDiv(); if(htmlDiv != null) htmlDiv.style.top = y + this.m_offsetYCoords + "px"; } function CMenu_setZIndex(zIndex) { htmlDiv = this.getHTMLDiv(); if(htmlDiv != null) htmlDiv.style.zIndex = zIndex; } // set a callback routine to populate the menu function CMenu_registerCallback(callback) { this.m_callback = callback; } function CMenu_executeCallback() { if(this.m_callback == null) return; this.m_callback(); } function CMenu_getObservers() { return this.m_observers; } function CMenu_onmouseover(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); // notify our parent (if one exists) of this event if(this.getParent() != null && typeof this.getParent().onmouseover == 'function') this.getParent().onmouseover(evt); // notify observers of this event this.getObservers().notify(CMenu_onmouseover); } function CMenu_onmouseout(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); // notify our parent (if one exists) of this event if(this.getParent() != null && typeof this.getParent().onmouseout == 'function') this.getParent().onmouseout(evt); // notify observers of this event this.getObservers().notify(CMenu_onmouseout); } function CMenu_onmouseup(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); // notify our parent (if one exists) of this event if(this.getParent() != null && typeof this.getParent().onmouseup == 'function') this.getParent().onmouseup(evt); // notify observers of this event this.getObservers().notify(CMenu_onmouseup); } function CMenu_onkeypress(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); // notify our parent (if one exists) of this event if(this.getParent() != null && typeof this.getParent().onkeypress == 'function') this.getParent().onkeypress(evt); // notify observers of this event this.getObservers().notify(CMenu_onkeypress); } CMenu.prototype.draw = CMenu_draw; CMenu.prototype.updateCoords = CMenu_updateCoords; CMenu.prototype.add = CMenu_add; CMenu.prototype.get = CMenu_get; CMenu.prototype.getNumItems = CMenu_getNumItems; CMenu.prototype.hide = CMenu_hide; CMenu.prototype.hideHiddenIframe = CMenu_hideHiddenIframe; CMenu.prototype.show = CMenu_show; CMenu.prototype.enable = CMenu_enable; CMenu.prototype.disable = CMenu_disable; CMenu.prototype.getState = CMenu_getState; CMenu.prototype.clear = CMenu_clear; CMenu.prototype.attachEvents = CMenu_attachEvents; CMenu.prototype.setParent = CMenu_setParent; CMenu.prototype.getParent = CMenu_getParent; CMenu.prototype.getHTMLContainer = CMenu_getHTMLContainer; CMenu.prototype.setHTMLContainer = CMenu_setHTMLContainer; CMenu.prototype.getHTMLDiv = CMenu_getHTMLDiv; CMenu.prototype.create = CMenu_create; CMenu.prototype.remove = CMenu_remove; CMenu.prototype.getId = CMenu_getId; CMenu.prototype.isVisible = CMenu_isVisible; CMenu.prototype.setStyle = CMenu_setStyle; CMenu.prototype.getStyle = CMenu_getStyle; CMenu.prototype.closeSubMenus = CMenu_closeSubMenus; CMenu.prototype.closeAllMenus = CMenu_closeAllMenus CMenu.prototype.setOffsetXCoords = CMenu_setOffsetXCoords; CMenu.prototype.setOffsetYCoords = CMenu_setOffsetYCoords; CMenu.prototype.setContainsCascadedChildren = CMenu_setContainsCascadedChildren; CMenu.prototype.hasCascadedChildren = CMenu_hasCascadedChildren; CMenu.prototype.setXCoord = CMenu_setXCoord; CMenu.prototype.setYCoord = CMenu_setYCoord; CMenu.prototype.setZIndex = CMenu_setZIndex; CMenu.prototype.update = new Function("return true"); CMenu.prototype.registerCallback = CMenu_registerCallback; CMenu.prototype.executeCallback = CMenu_executeCallback; CMenu.prototype.getObservers = CMenu_getObservers; CMenu.prototype.onmouseover = CMenu_onmouseover; CMenu.prototype.onmouseout = CMenu_onmouseout; CMenu.prototype.onmouseup = CMenu_onmouseup; CMenu.prototype.onkeypress = CMenu_onkeypress; CMenu.prototype.createHiddenIFrame = CMenu_createHiddenIFrame; function updateIframeCoords(id, containerId, isNS7) { var container = document.getElementById(containerId); var hiddenIframeElement = document.getElementById(id); if (hiddenIframeElement && container) { if(isNS7 == true) { hiddenIframeElement.style.left = container.offsetLeft; hiddenIframeElement.style.top = container.offsetTop; hiddenIframeElement.style.width = container.offsetWidth; hiddenIframeElement.style.height = container.offsetHeight; } else { hiddenIframeElement.style.pixelLeft = container.offsetLeft; hiddenIframeElement.style.pixelTop = container.offsetTop; hiddenIframeElement.style.pixelWidth = container.offsetWidth; hiddenIframeElement.style.pixelHeight = container.offsetHeight; } } }