MediaWiki:Common.js

Revision as of 20:58, 10 August 2020 by JP12 (talk | contribs) (fix non-styled tooltips)

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(){
        // Hover over code
        var title = $(this).attr('title');
        $(this).data('tipText', title).removeAttr('title');
        // Add formating with &
        var codes = title.match(/&[0-9a-fl-o]/g)
        if (!codes) codes = []
        var classes = codes.map(function(x){return 'format-' + x[1]}).join(' ')
        $('<p class="tooltip ' + classes + '">' + title.slice(codes.length * 2) + '</p>')
        //.text(title + "\n1")
        .appendTo('body')
        .show();
    }, function() {
        // Hover out code
        $(this).attr('title', $(this).data('tipText'));
        $('.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();
});