/*********************************************************** {COPYRIGHT-TOP} *** * Licensed Materials - Property of IBM * Tivoli Presentation Services * * (C) Copyright IBM Corp. 2002,2003 All Rights Reserved. * * US Government Users Restricted Rights - Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. ************************************************************ {COPYRIGHT-END} *** * Change Activity on 6/20/03 version 1.17: * @00=WCL, V3R0, 04/14/2002, JCP: Initial version * @01=D96484, V3R2, 06/14/2002, bcourt: hide select/iframe elements * @02=D99067, V3R2, 06/25/2002, bcourt: hide listbox scrollbar * @03=D97043, V3R3, 09/03/2002, JCP: fix launch menu item on linux NS6 * @04=D104656, V3R3, 09/16/2002, JCP: form submit instead of triggers, mozilla compatibility * @05=D107029, V3R4, 12/03/2002, Mark Rebuck: Added support for timed menu hiding * @06=D110173, V3R4, 03/24/2003, JCP: selection sometimes gets stuck * @07=D113641, V3R4, 04/29/2003, LSR: Requirement #258 Shorten CSS Names * @08=D113626, V3R4, 06/20/2003, JCP: clicking on text doesn't launch action on linux Moz13 *******************************************************************************/ var visibleMenu_ = null; var padding_ = 10; var transImg_ = "transparent.gif"; var arrowNorm_ = "contextArrowDefault.gif"; var arrowSel_ = "contextArrowSelected.gif"; var arrowDis_ = "contextArrowDisabled.gif"; var launchNorm_ = "contextLauncherDefault.gif"; var launchSel_ = "contextLauncherSelected.gif"; var arrowNormRTL_ = "contextArrowDefault.gif"; var arrowSelRTL_ = "contextArrowSelected.gif"; var arrowDisRTL_ = "contextArrowDisabled.gif"; var launchNormRTL_ = "contextLauncherDefault.gif"; var launchSelRTL_ = "contextLauncherSelected.gif"; var wclIsOpera_ = /Opera/.test(navigator.userAgent); //ARC CHANGES FOR SPECIFYING STYLES - BEGIN var defaultContextMenuBorderStyle_ = "lwpShadowBorder"; var defaultContextMenuTableStyle_ = "lwpBorderAll"; //ARC CHANGES FOR SPECIFYING STYLES - END var arrowWidth_ = "12"; var arrowHeight_ = "12"; var submenuAltText_ = "+"; //ARC CHANGES FOR SPECIFIYING EMPTY MENU TEXT - BEGIN var defaultNoActionsText_ = "(0)"; var defaultNoActionsTextStyle_ = "lwpMenuItemDisabled"; //ARC CHANGES FOR SPECIFIYING EMPTY MENU TEXT - END var hideCurrentMenuTimer_ = null; var onmousedown_ = document.onmousedown; function clearMenuTimer( ) { //@05 if (null != hideCurrentMenuTimer_) { clearTimeout( hideCurrentMenuTimer_ ); hideCurrentMenuTimer_ = null; } } function setMenuTimer( ) { // @05 clearMenuTimer( ); hideCurrentMenuTimer_ = setTimeout( 'hideCurrentContextMenu( )', 2000); } function debug( str ) { /* if ( xbDEBUG != null ) { xbDEBUG.dump( str ); } */ } // constructor function UilContextMenu( name, isLTR, width, borderStyle, tableStyle, emptyMenuText, emptyMenuTextStyle, positionUnder ) { // member variables this.name = name; this.items = new Array(); this.isVisible = false; this.isDismissable = true; this.selectedItem = null; this.isDynamic = false; this.isCacheable = false; this.isEmpty = true; this.isLTR = isLTR; this.hiddenItems = new Array(); //@01A this.isHyperlinkChild = true; // We will reset later if needed. this.bottomPositioned = positionUnder; // html variables this.launcher = null; this.menuTag = null; //ARC CHANGES FOR SPECIFYING STYLES - BEGIN //styles for menu if ( borderStyle != null ) { this.menuBorderStyle = borderStyle; } else { this.menuBorderStyle = defaultContextMenuBorderStyle_; } if ( tableStyle != null ) { this.menuTableStyle = tableStyle; } else { this.menuTableStyle = defaultContextMenuTableStyle_; } //ARC CHANGES FOR SPECIFYING STYLES - END //ARC CHANGES FOR SPECIFIYING EMPTY MENU TEXT - BEGIN if ( emptyMenuText != null ) { this.noActionsText = emptyMenuText; } else { this.noActionsText = defaultNoActionsText_; } if ( emptyMenuTextStyle != null ) { this.noActionsTextStyle = emptyMenuTextStyle; } else { this.noActionsTextStyle = defaultNoActionsTextStyle_; } //ARC CHANGES FOR SPECIFIYING EMPTY MENU TEXT - END // external methods this.add = UilContextMenuAdd; this.addSeparator = UilContextMenuAddSeparator; this.show = UilContextMenuShow; this.hide = UilContextMenuHide; // internal methods this.create = UilContextMenuCreate; this.getMenuItem = UilContextMenuGetMenuItem; this.getSelectedItem = UilContextMenuGetSelectedItem; if ( this.name == null ) { this.name = "UilContextMenu_" + allMenus_.length; } } // adds a menu item to the context menu function UilContextMenuAdd( item ) { this.items[ this.items.length ] = item; this.isEmpty = false; } function UilContextMenuAddSeparator() { var sep = new UilMenuItem(); sep.isSeparator = true; this.add( sep ); } // shows the context menu // launcher- html element (anchor) that is launching the menu // launchItem- menu item that is launching the menu function UilContextMenuShow( launcher, launchItem ) { if ( this.items.length == 0 ) { // empty context menu debug( 'menu is empty!' ); //ARC CHANGES FOR SPECIFIYING EMPTY MENU TEXT - BEGIN this.add( new UilMenuItem( this.noActionsText, false, "javascript:void(0);", null, null, null, null, this.noActionsTextStyle ) ); //ARC CHANGES FOR SPECIFIYING EMPTY MENU TEXT - END this.isEmpty = true; } if ( this.menuTag == null ) { // create the context menu html this.create(); } else { this.menuTag.style.left = ""; //196195 //Reset this.menuTag.style.top = ""; //196195 //Reset this.menuTag.style.width = ""; //"0px"; //196195 //Reset this.menuTag.style.height = ""; //196195 //Reset this.menuTag.style.overflow = "visible"; //196195 //Reset, No horizontal and vertical scrollbars } if ( this.menuTag != null) { // store the launcher for later this.launcher = launcher; if ( this.launcher.tagName == "IMG" ) { this.isHyperlinkChild = false; // we want the anchor tag this.launcher = this.launcher.parentNode; } // boundaries of window var bd = new ContextMenuBrowserDimensions(); var maxX = bd.getScrollFromLeft() + bd.getViewableAreaWidth(); var maxY = bd.getScrollFromTop() + bd.getViewableAreaHeight(); var minX = bd.getScrollFromLeft(); var minY = bd.getScrollFromTop(); debug( 'max: ' + maxX + ', ' + maxY ); var menuWidth = getWidth( this.menuTag ); var menuHeight = getHeight( this.menuTag ); // move the context menu to the right of the launcher var posX = 0; var posY = 0; var fUseUpperY = false; //196195 var maxUpperPosY = 0; //196195 if ( launchItem != null ) { // launched from submenu var launchTag = launchItem.itemTag; var launchTagWidth = getWidth( launchTag ); var parentTag = launchItem.parentMenu.menuTag; //@04A var launchOffsetX = getLeft( parentTag ); //@04C var launchOffsetY = getTop( parentTag ); //@04C posX = launchOffsetX + getLeft( launchTag ) + launchTagWidth; //@04C posY = launchOffsetY + getTop( launchTag ); //@04C if ( !this.isLTR ) { posX -= launchTagWidth; posX -= menuWidth; } // try to keep it in the window if ( this.isLTR ) { if ( posX + menuWidth > maxX ) { // try to show it to the left of the parent menu var posX1 = launchOffsetX - menuWidth; var posX2 = maxX - menuWidth; if ( 0 <= posX1 ) { posX = posX1; } else { posX = Math.max( minX, posX2 ); } } } else { if ( posX < 0 ) { // try to show it to the right of the parent menu var posX1 = launchOffsetX + launchTagWidth; if ( posX1 + menuWidth < maxX ) { posX = posX1; } else { posX = Math.min( maxX, maxX - menuWidth ); } } } if ( posY + menuHeight > maxY ) { var posY1 = maxY - menuHeight; posY = Math.max( minY, posY1 ); } } else { // launched from menu link var launcherLeft = getLeft( this.launcher, true ) if ( this.launcher.tagName == "BUTTON" || this.bottomPositioned ) { posX = launcherLeft; // bidi if ( !this.isLTR ) { //196195 posX += getWidth( this.launcher ) - getWidth( this.menuTag ); posX += getWidth( this.launcher ) - menuWidth; //196195 } if (this.isLTR) { if ((posX + menuWidth) > maxX) { //196195 begins if ((posX + getWidth(this.launcher)) > maxX) { posX = Math.max(minX, maxX - menuWidth); } else //196195 ends posX = Math.max(minX, posX + getWidth( this.launcher ) - menuWidth); } //196195 begins else if (posX < minX) { posX = minX; } //196195 ends } else{ if (posX < minX) { //196195 if ((launcherLeft + menuWidth) < maxX) { if ((launcherLeft > minX) && ((launcherLeft + menuWidth) < maxX)) { //196195 posX = launcherLeft; } else{ posX = Math.min(minX, maxX - menuWidth); } } //196195 begins else if ( (posX + menuWidth) > maxX) { if (Math.min(posX, maxX - menuWidth) >= minX) posX = Math.min(posX, maxX - menuWidth); } //196195 ends } maxUpperPosY = getTop( this.launcher, true ); //196195 var upperVisibleHeight = maxUpperPosY - minY; //196195 posY = getTop( this.launcher, true ) + getHeight( this.launcher ); var lowerVisibleHeight = maxY - posY; //196195 //196195 if ( posY + menuHeight > maxY ) { if ( (posY + menuHeight > maxY) && (lowerVisibleHeight < upperVisibleHeight) ) { //196195 // top posY -= (menuHeight + getHeight( this.launcher )); fUseUpperY = true; //196195 } if ( posY < minY ) { posY = minY; } } else { // left-right posX = launcherLeft + this.launcher.offsetWidth; posY = getTop( this.launcher, true ); if ( !this.isLTR ) { posX -= this.launcher.offsetWidth; posX -= menuWidth; } // keep it in the window if ( this.isLTR ) { if ( posX + menuWidth > maxX ) { // try to show it on the left side of the launcher var posX1 = launcherLeft - menuWidth; if ( posX1 > 0 ) { posX = posX1; } else { posX = Math.max( minX, maxX - menuWidth ); } } } else { if ( posX < minX ) { // try to show it on the right side of the launcher var posX1 = launcherLeft + this.launcher.offsetWidth; if ( posX1 + menuWidth < maxX ) { posX = posX1; } else { posX = Math.min( minX, maxX - menuWidth ); } } } if ( posY + menuHeight > maxY ) { posY = Math.max( minY, maxY - menuHeight ); } } if ( ((posX + menuWidth) > maxX) || (((posY + menuHeight) > maxY) && (fUseUpperY == false)) || (((posY + menuHeight) > maxUpperPosY) && (fUseUpperY == true)) ) { if (posX + menuWidth > maxX) { this.menuTag.style.width = (maxX - posX) + "px"; } else{ this.menuTag.style.width = menuWidth + "px"; } if (fUseUpperY == false) { if (posY + menuHeight > maxY) { this.menuTag.style.height = (maxY - posY) + "px"; } else { this.menuTag.style.height = menuHeight + "px"; } } else { if (posY + menuHeight > maxUpperPosY) { this.menuTag.style.height = (maxUpperPosY - posY) + "px"; } else { this.menuTag.style.height = menuHeight + "px"; } } this.menuTag.style.overflow = "auto"; } else { //196195 begins this.menuTag.style.width = menuWidth + "px"; this.menuTag.style.height = menuHeight + "px"; this.menuTag.style.overflow = "visible"; //196195 } //196196 ends } debug( 'show ' + this.name + ': ' + posX + ', ' + posY ); this.menuTag.style.left = posX + "px"; this.menuTag.style.top = posY + "px"; // make the context menu visible this.menuTag.style.visibility = "visible"; this.isVisible = true; // set focus on the first menu item this.items[0].setSelected( true ); this.items[0].anchorTag.focus(); /* // no longer needed since fixed in Opera 9, and no other non-IE browsers need this // @01A - Hide any items that intersect this menu var coll = document.getElementsByTagName("SELECT"); if (coll!=null) { for (i=0; i= b ) ) { return true; } else { return false; } } // hides the context menu function UilContextMenuHide() { if ( this.menuTag != null ) { debug( 'hide ' + this.name ); // hide any visible submenus first for ( var i=0; i