Difference between revisions of "MediaWiki:Common.js"
From Project: Gorgon Wiki
Gorgonzola (talk | contribs) m |
Gorgonzola (talk | contribs) (Javascript for Template:Icon tooltips (shows the image caption in a tooltip).) |
||
Line 10: | Line 10: | ||
$(this).children('.spoilers-show').show(); | $(this).children('.spoilers-show').show(); | ||
$(this).children('.spoilers-hide').hide(); | $(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 }); | ||
}); | }); |
Latest revision as of 16:19, 29 October 2014
/* 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 }); });