function ElementPosition(obj) { var curleft = curtop = 0; if (obj.offsetParent) { curleft = obj.offsetLeft curtop = obj.offsetTop while (obj = obj.offsetParent) { curleft += obj.offsetLeft curtop += obj.offsetTop } } this.left = curleft; this.top = curtop; } function EventMousePosition( e ) { var posx = 0; var posy = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; } else if (e.clientX || e.clientY) { posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } // posx and posy contain the mouse position relative to the document // Do something with this information this.x = posx; this.y = posy; } /***** Popup Dialog Code ******/ function PopupDialogInfo() { this.closeable = true; this.moveable = false; this.title = ""; this.anchorElement = false; this.startOpen = false; } function PopupDialog( info ) { this.anchorElement = info.anchorElement; this.title = info.title; this.div = document.createElement( 'div' ); this.div.className = 'popup_dialog'; this.div.style.visibility = 'hidden'; this.div.style.position = 'absolute'; this.div.style.left = '0px'; this.div.style.top = '0px'; var h1 = document.createElement( 'h1' ); h1.appendChild( document.createTextNode(this.title) ); this.div.appendChild( h1 ); if( info.closeable ) { var closelink = document.createElement( 'a' ); closelink.href = 'javascript: void(0);'; closelink.controllerObj = this; closelink.addEventListener( 'click', function(){this.controllerObj.close();}, false ); var closeimg = document.createElement( 'img' ); closeimg.src = '/images/icons/48x48/actions/fileclose.png'; closeimg.alt = 'X'; closelink.appendChild( closeimg ); h1.appendChild( closelink ); } this.contentDiv = document.createElement( 'div' ); this.contentDiv.className = 'popup_content'; this.div.appendChild( this.contentDiv ); document.body.appendChild( this.div ); this.stateIsOpen = false; if( info.startOpen ) { this.open(); } } PopupDialog.prototype.open = function() { var pos = new ElementPosition( this.anchorElement ); this.div.style.left = pos.left + 'px'; this.div.style.top = pos.top + 'px'; this.div.style.visibility = 'visible'; this.stateIsOpen = true; } PopupDialog.prototype.close = function() { this.div.style.visibility = 'hidden'; this.stateIsOpen = false; } PopupDialog.prototype.content = function() { return this.contentDiv; } PopupDialog.prototype.isOpen = function() { return this.stateIsOpen; } /**** END POPUP DIALOG ********/ /***** CONTEXT MENU CODE *******/ function ContextMenuInfo() { this.mouseOutDelay = 1000; this.callback = false; } function ContextMenu( info ) { this.anchorElement = info.anchorElement; this.anchorElement.contextMenuController = this; info.anchorElement.addEventListener( 'click', function(e) { var mousePos = new EventMousePosition(e); this.contextMenuController.open(mousePos.x,mousePos.y); }, false ); this.ul = document.createElement( 'ul' ); this.ul.className = 'context_menu'; this.ul.style.visibility = 'hidden'; this.ul.style.position = 'absolute'; this.ul.style.left = '0px'; this.ul.style.top = '0px'; this.ul.contextMenuController = this; this.ul.addEventListener( 'mouseout', function(){this.contextMenuController.onMouseOut()}, false ); this.ul.addEventListener( 'mouseover', function(){this.contextMenuController.onMouseOver()}, false ); this.statusMouseIsOver = false; document.body.appendChild( this.ul ); } ContextMenu.prototype.open = function( x, y ) { this.ul.style.left = x + 'px'; this.ul.style.top = y + 'px'; this.ul.style.visibility = 'visible'; this.stateIsOpen = true; } ContextMenu.prototype.close = function() { this.ul.style.visibility = 'hidden'; this.stateIsOpen = false; } ContextMenu.prototype.isOpen = function() { return this.stateIsOpen; } ContextMenu.prototype.add = function( data ) { var li = document.createElement( 'li' ); li.appendChild( document.createTextNode(data) ); this.ul.appendChild( li ); } ContextMenu.prototype.onMouseOver = function(e) { this.statusMouseIsOver = true; window.status = 'over'; } ContextMenu.prototype.onMouseOut = function(e) { this.statusMouseIsOver = false; window.status = 'out'; if( this.stage2TimeoutId ) { window.clearTimeout( this.stage2TimeoutId ); this.stage2TimeoutId = false; } this.stage2TimeoutId = window.setObjectTimeout( this, "mouseOutStage2", 1000 ); } ContextMenu.prototype.isMouseOver = function() { if( this.stage2TimeoutId ) { window.clearTimeout( this.stage2TimeoutId ); this.stage2TimeoutId = false; } return this.statusMouseIsOver; } ContextMenu.prototype.mouseOutStage2 = function() { if( !this.isMouseOver() ) { this.close(); } } /***** END CONTEXT MENU ********/ /***** TIMEOUT CODE ***********/ window.setObjectTimeout = function( object, funcName, delay ) { return window.setTimeout( window.objectTimeoutCallback, delay, object, funcName ); } window.objectTimeoutCallback = function( object, funcName ) { if( object[funcName]) { object[funcName](); } else { throw "Invalid Callback"; } } /******* END TIMEOUT **********/