MediaWiki:Tooltips.js

// ';      var rules = { position: 'absolute', visibility: 'hidden' ,top: 0, left: 0 ,margin: 0, border: 0 ,width: '1px', height: '1px' };     Object.merge (rules, container.style);

container.innerHTML = html; body.insertBefore(container, body.firstChild); var innerDiv = container.firstChild; var checkDiv = innerDiv.firstChild; var td = innerDiv.nextSibling.firstChild.firstChild;

data.doesNotAddBorder = (checkDiv.offsetTop !== 5); data.doesAddBorderForTableAndCells = (td.offsetTop === 5);

innerDiv.style.overflow = 'hidden', innerDiv.style.position = 'relative'; data.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5);

var bodyMarginTop   = body.style.marginTop; body.style.marginTop = '1px'; data.doesNotIncludeMarginInBodyOffset = (body.offsetTop === 0); body.style.marginTop = bodyMarginTop;

body.removeChild(container); };

function jQuery_offset (node) {     if (node === node.ownerDocument.body) return jQuery_bodyOffset (node); if (node.getBoundingClientRect) { var box   = node.getBoundingClientRect ; var scroll = {x : this.scroll_offset ('Left'), y: this.scroll_offset ('Top')}; return {x : (box.left + scroll.x), y : (box.top + scroll.y)}; }     if (!data) jQuery_init ; var elem             = node; var offsetParent     = elem.offsetParent; var prevOffsetParent = elem; var doc              = elem.ownerDocument; var prevComputedStyle = doc.defaultView.getComputedStyle(elem, null); var computedStyle;

var top = elem.offsetTop; var left = elem.offsetLeft;

while ( (elem = elem.parentNode) && elem !== doc.body && elem !== doc.documentElement ) { computedStyle = doc.defaultView.getComputedStyle(elem, null); top -= elem.scrollTop, left -= elem.scrollLeft; if ( elem === offsetParent ) { top += elem.offsetTop, left += elem.offsetLeft; if (  data.doesNotAddBorder              && !(data.doesAddBorderForTableAndCells && /^t(able|d|h)$/i.test(elem.tagName))             ) {           top  += parseInt (computedStyle.borderTopWidth,  10) || 0; left += parseInt (computedStyle.borderLeftWidth, 10) || 0; }         prevOffsetParent = offsetParent; offsetParent = elem.offsetParent; }       if (data.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== 'visible') {         top  += parseInt (computedStyle.borderTopWidth,  10) || 0; left += parseInt (computedStyle.borderLeftWidth, 10) || 0; }       prevComputedStyle = computedStyle; }

if (prevComputedStyle.position === 'relative' || prevComputedStyle.position === 'static') { top += doc.body.offsetTop; left += doc.body.offsetLeft; }     if (prevComputedStyle.position === 'fixed') { top += Math.max (doc.documentElement.scrollTop, doc.body.scrollTop); left += Math.max (doc.documentElement.scrollLeft, doc.body.scrollLeft); }     return {x: left, y: top}; }

function jQuery_bodyOffset (body) {     if (!data) jQuery_init; var top = body.offsetTop, left = body.offsetLeft; if (data.doesNotIncludeMarginInBodyOffset) { var styles; if (  body.ownerDocument.defaultView            && body.ownerDocument.defaultView.getComputedStyle) { // Gecko etc.         styles = body.ownerDocument.defaultView.getComputedStyle (body, null); top += parseInt (style.getPropertyValue ('margin-top' ), 10) || 0; left += parseInt (style.getPropertyValue ('margin-left'), 10) || 0; } else { function to_px (element, val) { // Convert em etc. to pixels. Kudos to Dean Edwards; see // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 if (!/^\d+(px)?$/i.test (val) && /^\d/.test (val) && body.runtimeStyle) { var style                = element.style.left; var runtimeStyle         = element.runtimeStyle.left; element.runtimeStyle.left = element.currentStyle.left; element.style.left       = result || 0; val = elem.style.pixelLeft + "px"; element.style.left       = style; element.runtimeStyle.left = runtimeStyle; }           return val; }         style = body.currentStyle || body.style; top += parseInt (to_px (body, style.marginTop ), 10) || 0; left += parseInt (to_px (body, style.marginleft), 10) || 0; }     }      return {x: left, y: top}; }

return jQuery_offset; }),

scroll_offset : function (what) {   var s = 'scroll' + what; return (document.documentElement ? document.documentElement[s] : 0) || document.body[s] || 0; },

viewport : function (what) {   var s = 'client' + what; return (document.documentElement ? document.documentElement[s] : 0) || document.body[s] || 0; },

calculate_dimension : function {   if (this.popup.style.display != 'none' && this.popup.style.display != null) { return {width : this.popup.offsetWidth, height : this.popup.offsetHeight}; }   // Must display it... but position = 'absolute' and visibility = 'hidden' means // the user won't notice it. var view_width = this.viewport ('Width'); this.popup.style.top       = "0px"; this.popup.style.left      = "0px"; // Remove previous width as it may change with dynamic tooltips this.popup.style.width     = ""; this.popup.style.maxWidth  = ""; this.popup.style.overflow  = 'hidden'; this.popup.style.visibility = 'hidden'; // Remove the close button, otherwise the float will always extend the box to   // the right edge. if (this.close_button) this.popup.firstChild.removeChild (this.close_button); this.popup.style.display = "";  // Display it. Now we should have a width var w = this.popup.offsetWidth; var h = this.popup.offsetHeight; var limit = Math.round (view_width * this.options.max_width); if (this.options.max_pixels > 0 && this.options.max_pixels < limit) limit = this.options.max_pixels; if (w > limit) { w = limit; this.popup.style.width   = "" + w + "px"; this.popup.style.maxWidth = this.popup.style.width; if (this.close_button) { this.popup.firstChild.insertBefore (this.close_button, this.popup.firstChild.firstChild); }   } else { this.popup.style.width   = "" + w + "px"; this.popup.style.maxWidth = this.popup.style.width; if (this.close_button) { this.popup.firstChild.insertBefore (this.close_button, this.popup.firstChild.firstChild); }     if (h != this.popup.offsetHeight) { w = w + this.close_button_width; this.popup.style.width   = "" + w + "px"; this.popup.style.maxWidth = this.popup.style.width; }   }    var size = {width : this.popup.offsetWidth, height : this.popup.offsetHeight}; this.popup.style.display = 'none';      // Hide it again this.popup.style.visibility = ""; return size; } } // end Tooltip

//