// ============================================================================= // Author: Tasso Quidera // Date: February 7th, 2007 A.D. (The year of our LORD) // Purpose: Capture mouse position and display a mini dialog with information as needed // ============================================================================= var Dlg, MvDlg, DlgCount=0; Netscape = (document.all) ? false : true; if (Netscape) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP | Event.MOUSEMOVE); document.onmousedown = MDownCapture; document.onmouseup = MUpCapture; document.onmousemove = MMoveCapture; var over = false, MouseIsDown=false; // Global variables to hold mouse x & y positions var PositionX = 0, X=0; var PositionY = 0, Y=0; var CenterX = window.screen.availHeight/2; var CenterY = window.screen.availWidth/2; //======================================================== // //======================================================== function keyPressHandler(e) { var kC = (window.event) ? // MSIE or Firefox? event.keyCode : e.keyCode; var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE // MSIE : Firefox if(kC==Esc) EscCloseDiv(); } //======================================================== // MOUSE MOVE CAPTURE //======================================================== function MMoveCapture(e) { // Main function to retrieve mouse x-y pos.s if (!Netscape) { // grab the x-y pos.s if browser is IE PositionX = event.clientX + document.body.scrollLeft PositionY = event.clientY + document.body.scrollTop } else { // grab the x-y pos.s if browser is NS PositionX = e.pageX PositionY = e.pageY } // catch possible negative values in NS4 if (PositionX < 0){PositionX = 0} if (PositionY < 0){PositionY = 0} // show the position values in the form named Show // in the text fields named MouseX and MouseY //document.MouseSpot.MouseX.value = PositionX //document.MouseSpot.MouseY.value = PositionY if (Dlg && MouseIsDown) { if (Netscape) { Dlg.style.top = e.pageY-Y; Dlg.style.left = e.pageX-X; } else { Dlg.pixelLeft = event.clientX-X + document.body.scrollLeft; Dlg.pixelTop = event.clientY-Y + document.body.scrollTop; return false; } } return true } //======================================================== //======================================================== function MDownCapture(e) { MouseIsDown=true; if (over) { Dlg = document.getElementById(MvDlg); if (Netscape) { X=e.layerX; Y=e.layerY; return false; } else { if (Dlg) Dlg = Dlg.style; X=event.offsetX; Y=event.offsetY; } } } //======================================================== //======================================================== function MUpCapture() { //Dlg = null; MouseIsDown=false; // if this is a nested frame if (parent.MouseIsDown) parent.MouseIsDown=false; } //======================================================== // DIALOG FADERS SECTION //======================================================== /* All that is required for a dialog fade in and out is the following code // also some event to trigger the display such as: */ function CloseDiv(dlgname) { shiftOpacity(dlgname,500); setTimeout("document.getElementById('"+dlgname+"').style.visibility='hidden';", 500); setTimeout("document.getElementById('"+dlgname+"').style.opacity=0;", 500); MvDlg=""; } function EscCloseDiv() { var dlgname=MvDlg; if (MvDlg=='undefined') return; shiftOpacity(dlgname,500); setTimeout("document.getElementById('"+dlgname+"').style.visibility='hidden';", 500); setTimeout("document.getElementById('"+dlgname+"').style.opacity=0;", 500); MvDlg=""; } // show a movable dialog function ShowDiv(dlgname) { MvDlg=dlgname; if (document.getElementById(dlgname).style.visibility=='hidden') { document.getElementById(dlgname).style.top=PositionY; document.getElementById(dlgname).style.left=PositionX; //document.getElementById(dlgname).style.top=window.screen.availHeight/2; //document.getElementById(dlgname).style.left=window.screen.availWidth/2; document.getElementById(dlgname).style.visibility='visible'; shiftOpacity(dlgname,500); } } // Show a dialog that will fade after 5 seconds function ShowFaderDiv(dlgname) { if (document.getElementById(dlgname).style.visibility=='hidden') { document.getElementById(dlgname).style.top=PositionY; document.getElementById(dlgname).style.left=PositionX; document.getElementById(dlgname).style.opacity=0; document.getElementById(dlgname).style.visibility='visible'; shiftOpacity(dlgname,500); // Set a 5 second delayed fadeout setTimeout("CloseDiv('"+dlgname+"')", 8000); } } //======================================================== //======================================================== // ==================================================================== // FUNCTIONS FOR MAKING APPEAR AND DISPEAR A GIVEN ELEMENT BY ID // ==================================================================== function shiftOpacity(id, millisec) { if (id=="" ||id=='undefined'||!id) { // if called within nested frame if (parent.Dlg) parent.shiftOpacity(parent.Dlg.value,millisec); return; } //if an element is invisible, make it visible, else make it invisible if (document.getElementById(id).style.opacity == 0 ) { opacity(id, 0, 100, millisec); } else { opacity(id, 100, 0, millisec); } } function opacity(id, opacStart, opacEnd, millisec) { //speed for each frame var speed = Math.round(millisec / 100); var timer = 1; //determine the direction for the blending, if start and end are the same nothing happens if(opacStart > opacEnd) { for(i = opacStart; i >= opacEnd; i--) { setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); timer++; } } else if(opacStart < opacEnd) { for(i = opacStart; i <= opacEnd; i++) { setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); timer++; } } } //change the opacity for different browsers function changeOpac(opacity, id) { var object = document.getElementById(id).style; object.opacity = (opacity / 100); object.MozOpacity = (opacity / 100); object.KhtmlOpacity = (opacity / 100); object.filter = "alpha(opacity=" + opacity + ")"; }