Jump to content

MediaWiki:RefToolbar.js

From wiki.vkr

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Simple Reference Tooltips for MediaWiki
// Shows footnote popups like Wikipedia (lightweight)

mw.loader.using(['jquery.client'], function () {
    $(function () {
        var $refs = $('sup.reference');

        $refs.hover(function () {
            var href = $(this).find('a').attr('href');
            if (!href || href.indexOf('#') !== 0) return;

            var id = href.substring(1);
            var $note = $('#' + id);
            if ($note.length === 0) return;

            var text = $note.text();
            var $tip = $('<div>')
                .addClass('reference-tooltip')
                .text(text)
                .css({
                    position: 'absolute',
                    background: '#fffff2',
                    border: '1px solid #aaa',
                    padding: '6px',
                    maxWidth: '300px',
                    zIndex: 9999
                })
                .appendTo('body');

            $(this).data('tooltip', $tip);

            $(this).mousemove(function (e) {
                $tip.css({ top: e.pageY + 15, left: e.pageX + 15 });
            });
        }, function () {
            var $tip = $(this).data('tooltip');
            if ($tip) $tip.remove();
        });
    });
});