/* * javascript multilevel menu developed by Matteo Bicocchi * (c) 2002-2005 Open Lab srl, Matteo Bicocchi * version 3.1 * free to use - please don't cut this lines * tested on: Explorer, Mozilla, Netscape and Opera for PC * Mozilla, Netscape and Safari for Mac Os X * this .js must be used with the 'mbMenu.css' file */ // inizializing variables // var theId; var ContentLine; var contentMenu; var theLayer; var trueX; var trueY; var windowHeight; var winWidth,winHeight; var zMax; var menuDiv; var actualMenu=""; var submenuOnLeft=false; var submenuOnTop=false; var activeOnClick=false; var menuWidth=120; var menuZIndex=2000; var contentLineAlign="left"; var separatorHeight=0; // separator height var lineHeight = 0; //var distanceY=0; // menu top adjust //var distanceX=0; // menu left adjust var subMenuMarginLeft=0; // subMenu left adjust var subMenuMarginTop=0; // subMenu top adjust var imagesUrl="/commons/skin/green/images/"; var actualId=""; var isTxt; var arrowImg= "menuArrow.gif"; var documentLoaded=false; //-----------------link the right css class to the normal and the over state for the menubar--- barMenuOverClass="menuBarOver"; barMenuClass="menuBar"; //-----------------define if you have to click for the first open------------------------- var menuOnClick=true; var show= (menuOnClick)? false : true; //-----------------if you attach the menu to a textual link define the normal and the over style--- var rollOverOnBar=true; var whichMenuBar=""; //-----------------define if you have images or webdings in menu lines------------------- var hasImg=true; function createImg(imgDef){ var hasTxtImg=(imgDef && imgDef.indexOf(".")<1 ); if (hasImg ){ imgString=""; if (!imgDef || imgDef.length==0 || (hasTxtImg && !isExplorer && isWin)){ imgString=imgString+""; }else{ if (hasTxtImg){ imgString=imgString+""+imgDef+""; } else { imgString=imgString+""; } } imgString=imgString+""; }else{ imgString=""; } } //-----------------recursive search for element---------------------------------- function findDiv(theEl){ while (!theEl.name) { theEl=isNetscape ? theEl.parentNode: theEl.parentElement; } return theEl.id; } //-----------------create elements------------------------------------------- function createMenuDiv (theId, where){ var menuDiv = createEl("DIV"); menuDiv.style.position = "absolute"; menuDiv.style.visibility = "hidden"; menuDiv.id = theId; menuDiv.name = theId; menuDiv.style.width= menuWidth; menuDiv.style.zindex = menuZIndex; document.body.appendChild(menuDiv); actualMenu = menuDiv.id; } function createSubMenuDiv (subMenuId, relativeTo){ subMenuDiv = createEl("DIV"); subMenuDiv.style.position = "absolute"; subMenuDiv.id = subMenuId; subMenuDiv.name = subMenuId; subMenuDiv.style.width= menuWidth; subMenuDiv.style.zindex = zMax; //subMenuDiv.style.left= parseFloat(obj(relativeTo).offsetWidth+subMenuMarginLeft)+"px"; //subMenuDiv.style.marginTop= -(parseFloat(obj(relativeTo).offsetHeight+subMenuMarginTop))+"px"; obj(relativeTo).appendChild(subMenuDiv); targetWidth= obj(relativeTo).offsetWidth; windowWidth = getWindowDimensionW(); windowHeight = getWindowDimensionH(); /* if (getAbsoluteLeft(subMenuDiv)>=(windowWidth-targetWidth) ){ // || submenuOnLeft subMenuDiv.style.left= parseFloat(-obj(relativeTo).offsetWidth-subMenuMarginLeft)+"px"; submenuOnLeft=true; } if (submenuOnTop){ subMenuDiv.style.marginTop= -(parseFloat(-obj(subMenuId).offsetHeight+obj(relativeTo).offsetHeight))+"px"; submenuOnTop=true; } */ theEl= obj(relativeTo); theMenuToHide= obj(findDiv(theEl)).menuToHide; if (theMenuToHide){ removeMenu(theMenuToHide); } obj(findDiv(theEl)).menuToHide=subMenuId; } // create the label of the menu function createContentLineTitle (desc){ contentLine = "\n\n\n\n"; return contentLine; } // create the submenu line function createSubmenuLine (desc, submenu,imgDef){ createImg(imgDef); ContentLine="
"+imgString+"
"; return ContentLine; } // create the menu line function createContentLine (desc, lineUrl, target, contentTitle, script,imgDef, enabled){ createImg(imgDef); if (!target) target="document"; if (target=="_parent") target="document.parent"; if (target=="_self") target="document.self"; if(!script){ if (contentTitle) contentTitle="title='"+contentTitle+"'"; else contentTitle="" ContentLine=""+imgString+""; }else{ ContentLine=""+imgString+""; } if(enabled=="false") ContentLine=""+imgString+""; return ContentLine; } // create the menu line disabled function createContentLineDisabled (desc,imgDef){ createImg(imgDef); ContentLine=""+imgString+""; return ContentLine; } // create the separator line function createSeparator (){ ContentLine="
"; return ContentLine; } // create the menu function createContent (wich, theId){ var iframeHeight=0; var h=0; contentMenu="
"; //if is explorer and Windows generate an iframe under the menu to prevent a bug in Explorer that put a form popup element over everything // 30-11-05 tolto z-index:1; da style di iframe contentMenu+=(isExplorer && isWin ? "":""); //contentMenu+= ""; // contentMenu+="
\n"; contentMenu+=""; for (i=0;i-1){ contentMenu +=""; } } contentMenu+=""; contentMenu+="
\n"; contentMenu+="
\n"; return contentMenu; } // change the content of the menu according with the call in the page function changeContent (theMenu, theId){ content= createContent (theMenu, theId); if(isExplorer){ theLayer = document.all[theId]; theLayer.innerHTML=content; } if(isNetscape){ theLayer = obj(theId); theLayer.innerHTML =content; } //scriptDebugger(content); } function showMenu(theMenu, where, theId, isTxt){ if(documentLoaded || !isExplorer){ if (actualId != "") { hideMenu(); } if (whichMenuBar && rollOverOnBar && menuBarType) obj(whichMenuBar).className=barMenuClass; whichMenuBar=where; menuBarType= isTxt; if (whichMenuBar && rollOverOnBar && menuBarType) obj(whichMenuBar).className=barMenuOverClass; var el = obj(theId); if (!el && show==true){ createMenuDiv (theId); actualId=theId; theMenuEl = obj(theId); theMenuEl.style.visibility="visible"; positionIt(where, theId); changeContent (theMenu, theId); //----dimentioning iframe for Explorer bug collisioning with combo form element tableMenuEl= obj('table'+theId); containerMenuEl= obj('container'+theId); topMenuEl= obj(where); if(isExplorer){ containerMenuEl.style.width=tableMenuEl.offsetWidth; containerMenuEl.style.height=tableMenuEl.offsetHeight; } //----END dimentioning iframe // if the menu is out of the window then reposition it targetWidth= tableMenuEl.offsetWidth; targetHeight =tableMenuEl.offsetHeight; windowHeight=getWindowDimensionH() windowWidth = getWindowDimensionW(); if (getAbsoluteLeft(theMenuEl)>=(windowWidth-targetWidth)){ theMenuEl.style.left=(getAbsoluteLeft(theMenuEl)-(targetWidth)+topMenuEl.offsetWidth)+"px"; submenuOnLeft=true; } barHeight=(isExplorer)?45:20; if (getAbsoluteTop(theMenuEl)+targetHeight>=(windowHeight-barHeight)){ theMenuEl.style.marginTop=-((getAbsoluteTop(theMenuEl)-((windowHeight-barHeight)-targetHeight)))+"px"; } theMenuEl.style.zIndex=zMax++; } } } function showSubMenu(theMenu, theId, relativeTo) { if (!obj(theId)) { createSubMenuDiv (theId, relativeTo); theSubMenuEl = obj(theId); changeContent (theMenu, theId); theSubMenuEl.style.zIndex=10+zMax; zMax=zMax++; theSubMenuEl.style.left= parseFloat(obj(relativeTo).offsetWidth+subMenuMarginLeft)+"px"; //theSubMenuEl.style.marginTop= -(parseFloat(obj(relativeTo).offsetHeight+subMenuMarginTop))+"px"; theSubMenuEl.style.top=theSubMenuEl.offsetTop-(parseFloat(obj(relativeTo).offsetHeight+subMenuMarginTop))+"px"; /* if (isSafari){ theSubMenuEl.style.top= theSubMenuEl.offsetTop+(parseFloat(obj(relativeTo).offsetHeight))+"px"; } */ //----dimentioning iframe for Explorer bug collisioning with combo form element if(isExplorer){ tableMenuEl= obj('table'+theId); containerMenuEl= obj('container'+theId); containerMenuEl.style.width=tableMenuEl.offsetWidth; containerMenuEl.style.height=tableMenuEl.offsetHeight; } //----END dimentioning iframe // if the subMenu is out of the window then reposition it tableMenuEl= obj('table'+theId); targetWidth= tableMenuEl.offsetWidth; targetHeight =tableMenuEl.offsetHeight; windowHeight=getWindowDimensionH() windowWidth = getWindowDimensionW(); if (getAbsoluteLeft(theSubMenuEl)>=(windowWidth-targetWidth)){ theSubMenuEl.style.marginLeft=-((obj(relativeTo).offsetWidth+targetWidth)+(subMenuMarginLeft*2)); } barHeight=(isExplorer)?45:35; if (getAbsoluteTop(theSubMenuEl)+targetHeight>=(windowHeight-barHeight)){ theSubMenuEl.style.marginTop=-((getAbsoluteTop(theSubMenuEl)-((windowHeight-barHeight)-targetHeight)))+"px"; } } } // hide the menu & subMenu function hideMenu(){ if (whichMenuBar && rollOverOnBar && menuBarType) obj(whichMenuBar).className=barMenuClass; actualMenu=""; actualSubMenu = ""; whichMenuBar=""; theMenuEl = obj(actualId); if (theMenuEl){ removeMenu(actualId); actualId=""; } } function hideSubMenu(theId){ theMenuEl = obj(theId); theMenuToHide= obj(findDiv(theId)).menuToHide; theMenuEl= obj(theMenuToHide); if (theMenuEl){ removeMenu(theMenuToHide); obj(findDiv(theId)).menuToHide=null; } } function removeMenu (theId){ theMenu= obj(theId); lineToRestore=obj(theId+"_sml"); if(theMenu) theMenu.parentNode.removeChild(theMenu); if (lineToRestore) lineToRestore.className='subMenu'; } function showOnClick(){ show=(menuOnClick)?true:show; } // END hide the menu & subMenu document.onclick = function () { if (menuOnClick) setTimeout('if(actualMenu==\'\') show=false;',250); } document.onmousedown = hideMenu; document.onblur = hideMenu; document.onmousedown = hideMenu; //terrible hack var setStart=true; start = function (){ setTimeout('documentLoaded=true',1000); } //centralized on platform_js.jsp //window.onload = start;