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) {   if (   typeof (is_opera_95) != 'undefined' && is_opera_95 && what == 'Height'        || typeof (is_safari) != 'undefined' && is_safari && !document.evaluate) return window['inner' + what]; var s = 'client' + what; if (typeof (is_opera) != 'undefined' && is_opera) return document.body[s]; 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'; if (typeof (is_opera) != 'undefined' && is_opera) { // Just put it out of the way. Opera has an ugly bug: textareas that were once hidden // through visibility settings don't work anymore when they're displayed. They don't     // fire events, may or may not update their text display when modified through Javascript, // and finally they may even refuse to get or have their value set through JS at all. // If our tooltip content contains a textarea, we'd run into this longstanding bug if     // we used visibility on Opera. Hence we don't.     // For a report of this bug, see http://www.quirksmode.org/bugreports/archives/2005/06/Cant_change_the_value_of_textarea_after_hiding_it_.html // from June 30, 2005 (that would've been about Opera 7.5). I can confirm that this bug // is still in Opera 9.63, though I have not been able to reproduce with a reduced example. // It appears that in addition to using visibility, there is some other ingredient here // that triggers this bug. In any case, not using visibility avoids the bug. // Lupo, 2009-06-10 this.popup.style.top = '-10000px'; this.popup.style.left = '-10000px'; } else 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 if (typeof (is_opera) != 'undefined' && is_opera) { this.popup.style.top = '0px'; // Clean up, even if not really necessary this.popup.style.left = '0px'; } else this.popup.style.visibility = ""; return size; } } // end Tooltip

//