home *** CD-ROM | disk | FTP | other *** search
Wrap
//POPUPS SCRIPT - HTML Help only //Version 2 (2.00.0002) //For use with HTML Help and IE 4 and 5 only //December 16, 1998 //Original Developer: Mark Jewett //Version 2 revised by Peter Costantini //*********************************************************************** //*** CUSTOMIZABLE OPTIONS ********************************************** //Author-definable options var popWidth = 300; /*Base width of popup*/ var popBackColor = "#ffffcc"; /*Background color of popup*/ var popBordStyle = "solid"; /*Border style of popup*/ var popBordWidth = 1; /*Border width of popup*/ var popBordColor = "#666666"; /*Border color of popup*/ var popPadding = 6; /*Padding of text within popup*/ /* Next two variables for use in sizing popups proportionately. */ var popWidthIncrement = 50 /* Amount to add to popup width for string longer than popStringLimit */ var popStringLimit = 400 /* String length beyond which to add popWidthIncrement to popup width */ //*********************************************************************** //DO NOT CHANGE CODE FROM HERE FOWARD UNLESS YOU KNOW WHAT YOU'RE DOING //*********************************************************************** //GLOBAL VARIABLES var posX, posY; //coordinates of popup var popOpen, stayOpen; //state of popups //*********************************************************************** //ADD HTML FORMATTING TO HOST PAGE //dynamically write in DIV to hold popup popupDIV = "<DIV ID='popup' STYLE='position:absolute; top:-1000; left:-1000; width:" + popWidth + "; padding:" + popPadding + "; visibility:hidden; background:" + popBackColor + "; border:" + popBordStyle + " " + popBordWidth + " " + popBordColor + "; z-index:3;'></DIV>"; document.write (popupDIV); //*********************************************************************** //EVENT HANDLING document.onclick = doCLICK; document.onmouseup = doSELECT; document.onkeypress = doKEY; //*********************************************************************** //MAIN FUNCTION // * startPopups() * // Accepts text variable from defs.js passed by calling file as parameter. Checks that definition file is done loading and another popup is not open. The defs_loaded flag is set in defs.js. function startPopups(x) { if (defs_loaded != true) window.setTimeout("startPopups("+x+")", 50); if (!popOpen) { doPopup(x); return; } } //*********************************************************************** // * doCLICK() * //Sets position of popup DIV based on mouse click, or leaves it in place if a nested popup is clicked. Nesting is indicated in variables in defs.js. function doCLICK() { srcElement = window.event.srcElement; if (((srcElement.parentElement.tagName.charAt(0).toLowerCase() == "a") && (srcElement.parentElement.href.substring(0,22) == "javascript:startPopups")) || ((srcElement.tagName.charAt(0).toLowerCase() == "a") && (srcElement.href.substring(0,22) == "javascript:startPopups"))) { if ((popOpen) && (window.event.srcElement.name == "nest")) { posX = document.all.popup.style.posLeft; posY = document.all.popup.style.posTop; } else { posX = window.event.clientX; posY = window.event.clientY + document.body.scrollTop; } } if (popOpen) closePopup(); } //*********************************************************************** // * doKEY() * //If user clicks ESC, closes popup. function doKEY() { if (window.event.keyCode == 27) closePopup(); } //*********************************************************************** // * doSELECT() * //If user selects text inside of popup, does not close popup. function doSELECT() { stayOpen = false; if (!popOpen) return true; if (popOpen) { if (document.selection.type != "Text") return true; else if (document.selection.createRange().text == "") return true; } if (window.event.srcElement.tagName.charAt(0).toLowerCase() == "a") return true; stayOpen = true; return false; } //*********************************************************************** // * doPopup(def) * //Creates popup and insert HTML string from defs.js into it. function doPopup(def) { //get definition from "defs.js" popString = eval(def); //fill contents with popup def document.all.popup.innerHTML = popString; /* Expand width of popup DIV proportionately for long definitions. */ var popupWidth = document.all.popup.offsetWidth; if (popString.length < popStringLimit) { popupWidth = popWidth; document.all.popup.style.width = popWidth; } else { if (popString.length < (2 * popStringLimit)) { popupWidth = popWidth + popWidthIncrement; document.all.popup.style.width = popWidth + popWidthIncrement; } else { popupWidth = popWidth + (2 * popWidthIncrement); document.all.popup.style.width = popWidth + (2 * popWidthIncrement); } } //determine if popup will be offscreen to right var rightlimit = posX + popupWidth; if (rightlimit >= document.body.clientWidth) { posX -= (rightlimit - document.body.clientWidth); } /* If left side of popup would go off left side of visible window, position it at the left edge of the window. */ if (posX < 0) { posX = 0; } //this Timeout necessary to allow contents of popup to fill, before getting the height window.setTimeout ("doPopHeight()", 0); //position popup document.all.popup.style.top = posY; document.all.popup.style.left = posX; /* Once popup is positioned, if it's too wide for the window, reduce its width to the width of the window. */ if (document.all.popup.style.width > document.body.clientWidth) { document.all.popup.style.width = document.body.clientWidth; } //Make popup visible. document.all.popup.style.visibility = "visible"; //Track state of popup. popOpen = true; //Do not allow event to bubble. return false; } //*********************************************************************** // * doPopHeight() * //Gets height of popup (based on newly added contents) and determines if it will extend off bottom of visible page. If it does, move it up, but not past top of visible page. function doPopHeight() { var pageBottom = document.body.scrollTop + document.body.clientHeight; var popHeight = document.all.popup.offsetHeight; if (popHeight + posY >= pageBottom) { if (popHeight <= document.body.clientHeight) { document.all.popup.style.top = pageBottom - popHeight; } else /* Position top of popup at top of page if it is longer than visible page. */ { document.all.popup.style.top = document.body.scrollTop; } } } //*********************************************************************** // * closePopup() * //Close popup unless stayOpen flag is set. function closePopup() { if (stayOpen == true) return; document.all.popup.style.visibility = "hidden"; document.all.popup.innerHTML = ""; popOpen = false; return; }