MediaWiki:Common.js

From Project: Gorgon Wiki
Revision as of 16:19, 29 October 2014 by Gorgonzola (talk | contribs) (Javascript for Template:Icon tooltips (shows the image caption in a tooltip).)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
/* Any JavaScript here will be loaded for all users on every page load. */

// Gorgonzola: Used by [[Template:Spoilers]] (reusing classes from <spoiler> extension)
$('.spoilers-button').toggle(function() {
  $(this).parents('.spoilers').find('.spoilers-body').show();
  $(this).children('.spoilers-show').hide();
  $(this).children('.spoilers-hide').show();
}, function() {
  $(this).parents('.spoilers').find('.spoilers-body').hide();
  $(this).children('.spoilers-show').show();
  $(this).children('.spoilers-hide').hide();
});

// Gorgonzola: [[Template:Icon]] tooltips
var elItemTT;

function ggItemTT(bDisp, sTitle) {
  if (bDisp && !elItemTT) {
    elItemTT = $('<div class="gg-icon-tt"></p>').appendTo('body');
  }
  if (bDisp) {
    elItemTT.text(sTitle).show();
  } else {
    elItemTT.hide();
  }
}

$("body").on("mouseover mouseout mousemove", ".js-icon-tt", function(ev) {
  ev.preventDefault();
  if (ev.type !== "mousemove") {
    var sTitle = $(this).parent("a").attr("title");
    ggItemTT(ev.type == "mouseover", sTitle);
  }
  elItemTT.css({ top: ev.pageY -24 , left: ev.pageX +5 });
});