/******************************************************************************************************************************** * Licensed Materials - Property of IBM * * * * IBM Cognos Products: AGS * * * * (C) Copyright IBM Corp. 2005, 2009 * * * * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * *********************************************************************************************************************************/ //css custom style constants var MENU_MENUBAR="menuBar"; var MENU_CONTAINER="menuContainerOld"; var MENU_HORIZONTAL_SEPERATOR = "menuHorizontalSeperator" var MI_NORMAL="menuItem_normal"; var MI_HOVER="menuItem_hover"; var MI_PRESSED="menuItem_pressed"; var MI_DISABLED="menuItem_disabled"; var MT_NORMAL="menuTitle_normal"; var MT_HOVER="menuTitle_hover"; var MT_PRESSED="menuTitle_pressed"; var TEXT=""; //the id of the menu bar placement tag var AGS_MENUBAR_ID="menuBar" //positioning tweaks for the menus var DROP_DOWN_X_TWEAK=2; var DROP_DOWN_Y_TWEAK=3; var DROP_DOWN_SUBMENU_Y_TWEAK=2; //the menu bar object var agsMenuBar = new MenuBar(MENU_MENUBAR); //the timeout identifier used to auto close any open menus after a period of time defined in TIMEOUT_MS var windowTimeout = null; //the number of milliseconds to wait before all open menus are closed, set to 4 seconds var TIMEOUT_MS=4000; /* ********************** * START MenuBar object ********************** */ function MenuBar(barName) { //methods this.writeMenuBar=writeMenuBar; this.displayMenu=displayMenu; this.addLabel=addLabel; this.closeLastOpenMenu=closeLastOpenMenu; this.showMenu=showMenu; this.showMenuSide=showMenuSide; this.findById=findById; this.findRowElement=findRowElement; this.hideOpenSubMenus=hideOpenSubMenus; this.hideMenu = hideMenu; this.resetMenus = resetMenus; this.getMenuLabelLink = getMenuLabelLink; this.getMenuLabelDiv = getMenuLabelDiv; this.changeObjectVisibility = changeObjectVisibility; this.getElementLeft = getElementLeft; this.getElementTop = getElementTop; this.getElementHeight = getElementHeight; this.moveXY = moveXY; //assign values this.barName=barName; this.menus = new Array(); this.autoOpen=false; this.lastOpenMenu=null; this.lastOpenSubMenu=null; this.numLabels = 0; } /* * Add a label to the menu bar. This equates to one of the top level menu items */ function addLabel(labelText) { var menuNo = this.numLabels; var labelId = 'labelCell' + menuNo; var newMenu = new MenuItem(labelText,this,null,null); newMenu.id=labelId; newMenu.index = this.numLabels; this.menus[menuNo]=newMenu; //set the id suffix newMenu.menuContainerId=this.numLabels; //update the label count this.numLabels += 1; return newMenu; } /* * Display the menu bar, first the menu labels are drawn * A menu label is rendered with the current menu id defined as [id] : *
* the name *
* * followed by each menu container which container one or more menu items. Initially * these are hidden and only displayed when the mouse is clicked */ function writeMenuBar() { var parentMenuBar = this; var AGSMenuBar = document.getElementById(AGS_MENUBAR_ID); if (AGSMenuBar != null) { //create the menu bar div var menuBarDiv = document.createElement("div"); menuBarDiv.id="labelContainer"; menuBarDiv.className=MENU_MENUBAR; menuBarDiv.style.width="100%"; //add each menu label to the menu bar for (var count = 0; count < this.numLabels; count++) { var menuLabel = this.menus[count]; var menuLinkId = 'menuLink' + count; //create the top level div for the label var menuLabelDiv = document.createElement("div"); menuLabelDiv.id=menuLabel.id; menuLabelDiv.style.paddingTop="4px"; menuLabelDiv.style.paddingLeft="3px"; menuLabelDiv.style.paddingRight="3px"; menuLabelDiv.style.paddingBottom="4px"; if (document.all) { menuLabelDiv.style.styleFloat="left"; //for netscape use cssFloat property } else { menuLabelDiv.style.cssFloat="left"; } //create the label anchor var menuLabelAnchor = document.createElement("span"); //set the correct 'hand' pointer for firefox //for some reason firefox render the 'hand' setting //as a text caret if (browserCheck.isNav6Up()) { menuLabelAnchor.style.cursor='pointer'; } menuLabelAnchor.unselectable="on"; menuLabelAnchor.id=menuLinkId; // force the href to do nothing //menuLabelAnchor.href="javascript:return false;"; // create the text var text = document.createTextNode(menuLabel.name); // add it as a child menuLabelAnchor.appendChild(text); menuLabelAnchor.className=MT_NORMAL; menuLabelDiv.appendChild(menuLabelAnchor); /* * The mouse has left a menu label. When autoOpen is set then the menu label style remains unchanged * otherwise change the style from hover to normal */ var onMouseOutHandler = function(event) { var target = (event.target) ? event.target : event.srcElement; //only set timeouts on menuLink ids i.e. anchor tags //this event handler is fired for both menu items in sub menus and label menu items //This is useful because the timeout clear can be handled in one place if (target.id.indexOf('menuLink') != -1) { //the reset function var f = function(){ parentMenuBar.resetMenus(); } windowTimeout = window.setTimeout(f,TIMEOUT_MS); } //only reset the class when auto open is switched off. The menu label should //always be highlighted when a menu is open and the sub menus are being traversed. This is the //normal behaviour for Windows type applications if (!parentMenuBar.autoOpen) { //because this event propagates according to the IE event model //ensure this event has come from the menu label and not a menu item var menuLabelLinkEle = parentMenuBar.getMenuLabelLink(event); var menuLabelDivEle = parentMenuBar.getMenuLabelDiv(event); if (menuLabelLinkEle != null && menuLabelDivEle != null) { menuLabelLinkEle.className=MT_NORMAL; } } } /* * The mouse has entered a menu label. When autoOpen is set this method will close any open menus, * display the new menu and then change the menu style to pressed. When autoOpen is false then the * style is changed to hover */ var onMouseOverHandler = function(event) { var target = (event.target) ? event.target : event.srcElement; var menuLabelLinkEle = parentMenuBar.getMenuLabelLink(event); var menuLabelDivEle = parentMenuBar.getMenuLabelDiv(event); //ensure the menu is kept open window.clearTimeout(windowTimeout); //label link not found we are over a menu item so just ignore if (menuLabelDivEle != null && menuLabelLinkEle != null) { //we have a top level menu item if (parentMenuBar.autoOpen) { var menuItem = parentMenuBar.findById(menuLabelDivEle.id); if (menuItem != null) { var menuNo = menuItem.index; //this closes the last open menu and also resets the menu class //only show it when we had a succesful close if (menuItem != parentMenuBar.lastOpenMenu) { if (parentMenuBar.closeLastOpenMenu()) { parentMenuBar.showMenu(menuNo,event); } } //update the last open property parentMenuBar.lastOpenMenu = menuItem; parentMenuBar.lastOpenSubMenu=null; menuLabelLinkEle.className=MT_PRESSED; //hide any open sub menus parentMenuBar.hideOpenSubMenus(); } } else { menuLabelLinkEle.className = MT_HOVER; } } } //create an anonymous event handler, there is a small hack that is necessary here //because when inside the handler 'this' becomes the document and not the menu bar //so the menu bar needs to be explicitly defined here as parentMenuBar. This only seems to //happen with properties and not object methods so this.findById is okay but this.numLabels is undefined var onClickHandler = function(event) { var returnVal=false; var target = (event.target) ? event.target : event.srcElement; var menuLabelLinkEle = null; var menuLabelDivEle = null; menuLabelLinkEle = parentMenuBar.getMenuLabelLink(event); menuLabelDivEle = parentMenuBar.getMenuLabelDiv(event); //this mouse click event is fired from both clicking a menu item and clicking a label item //so if the label div is null then a menu item has been clicked and we should propagate the event to //the lower echelons of the web page if (menuLabelDivEle != null) { var menuItem = parentMenuBar.findById(menuLabelDivEle.id); var menuNo = menuItem.index; if (browserCheck.isIE5dot5Up()) { //remove the focus outline around the element target.blur(); } //the last open menu is the same as this one, so close the menu if (parentMenuBar.lastOpenMenu == menuItem) { parentMenuBar.hideMenu(menuItem); menuLabelLinkEle.className = MT_HOVER; parentMenuBar.autoOpen = false; parentMenuBar.lastOpenMenu=null; } else { parentMenuBar.autoOpen = true; returnVal = !parentMenuBar.showMenu(menuNo,event); parentMenuBar.lastOpenMenu = menuItem; menuLabelLinkEle.className = MT_PRESSED; } } //propagate the event else { window.event.cancelBubble = false; returnVal = true; } return returnVal; } // set the event handlers for the menu labels parent.addEvent(menuLabelAnchor,"mouseover",onMouseOverHandler); parent.addEvent(menuLabelAnchor,"mouseout",onMouseOutHandler); parent.addEvent(menuLabelAnchor,"click",onClickHandler); //END OF ONCLICK EVENT HANDLER menuLabel.writeContainer(menuLabelDiv); menuBarDiv.appendChild(menuLabelDiv); } //end for loop AGSMenuBar.appendChild(menuBarDiv); //document.onmousedown = pageMousedown; //parent.getMessageIFrame().onmousedown = pageMousedown; cfgSet(MENU_MENUBAR,this); } else { document.write('

Cannot find a placement <div> tag with the required id['+AGS_MENUBAR_ID+']

'); } } /* * Hide a menu item, this method will also hide any open child menu items * menuItem The menu item to be hidden */ function hideMenu(menuItem) { if (menuItem != null) { menuItem.state=MenuItem.CLOSED; //ensure their are no child menus still open var openMenus = menuItem.getOpenMenuItems(); for (var i=0;i