/* * Copyright 2006 inxire GmbH. All rights reserved. * ------------------------------------------------------ * Version: $Id: tooltip.jsp,v 1.1.12.1 2008/05/19 14:16:48 amorgner Exp $ * * Javascript library to implement ioToolTips * * ioToolTips are tooltips asynchronous loaded with AJAX. * * Author: Tim Peteler */ /** * Calculate absolute X-Position for given event. The returned position * is absolute in respect to the window content (body element). * * @param e the event object, used by NS7 and Mozilla */ function xPosition(e) { if (!e && window.event) var e = window.event; var x = null; // IE: event.clientX is absolute position in window (DO NOT use event.x) !! // NS/Mozilla: e.pageX is absolute position in window content if (e && e.pageX) // Mozilla etc { x = e.pageX; } else if (e && e.clientX) // IE etc { x = e.clientX; // IE calculates (clientX,clientY) relativ to window, not content. Fix this: // IE6: use 'document.documentElement' (=HTML element) instead of 'document.body' for scroll infos x += (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft; } return x; } /** see xPosition */ function yPosition(e) { if (!e && window.event) var e = window.event; var y = null; // IE: event.clientY is absolute position in window (DO NOT use event.y) !! // NS/Mozilla: e.pageY is absolute position in window content if (e && e.pageY) // Mozilla etc { y = e.pageY; } else if (e && e.clientY) // IE etc { y = e.clientY; // IE calculates (clientX,clientY) relativ to window, not content. Fix this: // IE6: use 'document.documentElement' (=HTML element) instead of 'document.body' for scroll infos y += (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop; } return y; } /** * Calculates inner height of browser window. This is highly * browser dependend due to lack of any standard :-( * * Warning: the height of the document is in general larger than the window height, * if scrollbars are visible * * See: http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=16 * http://msdn.microsoft.com/library/default.asp?url=/workshop/author/om/measuring.asp * * window.innerHeight document.body.clientHeight document.documentElement.clientHeight * ======================================================================================================================= * Netscape 4 compatible height of browser window N/A N/A * Opera 6 and Netscape 6+ height of browser window height of browser window N/A * Opera 7 height of browser window height of browser window height of document * IE 4 compatible N/A height of browser window N/A * IE 5 compatible N/A height of browser window 0 * IE 6 standards compliant N/A height of document height of browser window * mode compatible * Ice Browser height of browser window height of browser window height of document * Others most give height of most give height of some give height of document * browser window browser window * * Warning: this code is experimental * * @param win the window to calculate the height of */ function yWindowSize(win) { if (!win) win = window; var winHeight = 0; if (win.innerHeight) { // most non-IE winHeight = win.innerHeight; // including scroll bar !! // if ( typeof(win.innerHeight) == 'number') winHeight = win.innerHeight - 20; // remove some space for scroll bar if (document.body.clientHeight) winHeight = document.body.clientHeight; // without scrollbar !? } else if (document.documentElement && document.documentElement.clientHeight) { winHeight = document.documentElement.clientHeight; } else { winHeight = document.body.clientHeight; } // alert( "Inner window height : " + winHeight // + "\nwindow.innerHeight = " + win.innerHeight // + "\ndocument.documentElement.clientHeight = " + win.document.documentElement.clientHeight // + "\ndocument.body.clientHeight = " + win.document.body.clientHeight ); return winHeight; } /** * Calculates inner width of browser window, see xWindowSize(win). * Warning: this code is experimental */ function xWindowSize(win) { if (!win) win = window; var winWidth = 0; if (win.innerWidth) { // most non-IE winWidth = win.innerWidth; // including scroll bar !! // if ( typeof(win.innerWidth) == 'number') winWidth = win.innerWidth - 20; // remove some space for scroll bar if (document.body.clientWidth) winWidth = document.body.clientWidth; // without scrollbar !? } else if (document.documentElement && document.documentElement.clientWidth) { winWidth = document.documentElement.clientWidth; } else { winWidth = document.body.clientWidth; } // alert( "Inner window width : " + winWidth // + "\nwindow.innerWidth = " + win.innerWidth // + "\ndocument.documentElement.clientWidth = " + win.document.documentElement.clientWidth // + "\ndocument.body.clientWidth = " + win.document.body.clientWidth ); return winWidth; } function updateToolTipPosition(event) { event = (event) ? event : ((window.event) ? window.event : ""); var currToolTip = document.getElementById('ioToolTip'); var bodyWidth = xWindowSize(window); var bodyHeight = yWindowSize(window); var x = xPosition(event)+13; var y = yPosition(event)+3; var scrollLeft = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft; var scrollTop = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop; if(currToolTip.clientWidth > 400) currToolTip.style.width = '400px'; // if the horizontal distance isn't enough to accomodate the width of the context menu if (scrollLeft + bodyWidth < x + currToolTip.offsetWidth) { // move the horizontal position of the menu to the left as appropriate currToolTip.style.left = (x - currToolTip.offsetWidth - 20) + 'px'; } else { // position the horizontal position of the menu where the mouse was clicked currToolTip.style.left = (x + 10) + 'px'; } // same concept with the vertical position if (scrollTop + bodyHeight < y + currToolTip.offsetHeight) { currToolTip.style.top = (scrollTop + bodyHeight - currToolTip.offsetHeight - 5) + 'px'; } else { currToolTip.style.top = (y + 5) + 'px'; } // return false to disable further handling return false; } function showToolTip(event, queryUrl) { asyncHTML('ioToolTip', queryUrl); updateToolTipPosition(event); document.getElementById('ioToolTip').style.visibility = 'visible'; } function hideToolTip() { document.getElementById('ioToolTip').style.visibility = 'hidden'; } //Workaround for MSIE and non existing XMLHttpRequest /*@cc_on @if (@_win32 && @_jscript_version >= 5) if (window.ActiveXObject) function XMLHttpRequest() { try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {} try { return new ActiveXObject('Microsoft.XMLHTTP') } catch(e) {} return false; } @end @*/ //adds HTML from queryUrl to the innerHTML of the given node function asyncHTML(nodeId, queryUrl, reqType, params) { var node = document.getElementById(nodeId); if (!node) return false; node.innerHTML = 'loading...'; xmlhttp = new XMLHttpRequest(); if(xmlhttp == null) { node.innerHTML = 'error while loading...'; //throw 'XmlHttpRequest() not available'; } // default request type is GET if (reqType == null) reqType = 'GET'; reqType = reqType.toUpperCase(); try { if (reqType == 'GET') { if (typeof params != 'undefined' && params) queryUrl += '?' + params; params = ''; //Open new Request xmlhttp.open(reqType, queryUrl, true); } else { //Open new Request xmlhttp.open(reqType, queryUrl, true); xmlhttp.setRequestHeader('Method', 'POST '+queryUrl+' HTTP/1.1'); xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); xmlhttp.setRequestHeader('Connection','close'); // Workaround for Mozilla bug, see https://bugzilla.mozilla.org/show_bug.cgi?id=246651 } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { if (xmlhttp.status == 200) { node.innerHTML = xmlhttp.responseText; } else { return false; } } }; xmlhttp.send(params); } catch(e) { return false; } return true; }