MediaWiki:Common.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
// Even More fancy hovers for recipes
$(function() {
// Tooltip only Text
$('.masterTooltip').hover(function() {
// Hide non-JS
$(this).data('tipText', $(this).attr('title')).removeAttr('title');
//Custom Tooltip
var title = $(this).attr('data-title');
var lore = $(this).attr('data-lore');
var tooltip = '<p class="tooltip">' + parseFormatCodes(title)
if (lore) tooltip += '<br><span class="lore format-5">' + parseFormatCodes(lore) + '</span>'
tooltip += '</p>'
$(tooltip).appendTo('body');
},
function() {
// Hover out
$('.tooltip').remove();
}).mousemove(function(e) {
var mousex = e.pageX + 20; //Get X coordinates
var mousey = e.pageY - 40; //Get Y coordinates
$('.tooltip').css({
top: mousey,
left: mousex
});
});
// Hide the stupid empty newlines after crafting grids
$('.crafting + p br:only-child').parent().hide();
});
function parseFormatCodes(text) {
var spans = 0;
var res = ''
for (var i = 0; i < text.length; i++) {
if (text[i] == '&') continue;
else if (text[i] == '/') {
res += '<br>';
continue;
}
else if ((text[i - 1] == '&') && /[0-9a-fl-or]/.test(text[i])) {
if (text[i] == 'r') {
res += "</span>".repeat(spans);
spans = 0;
} else {
res += '<span class="format-' + text[i] + '">';
spans++;
}
} else res += text[i];
}
return res + "</span>".repeat(spans);
}