User:Wookipan/Sandbox/Page.js

From Team Fortress Wiki
< User:Wookipan‎ | Sandbox
Revision as of 22:09, 4 September 2023 by Wookipan (talk | contribs) (Minor adjustments, increase target width to accommodate the wiki's odd container width)
Jump to: navigation, search

Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
var wikiTooltip = {
    init: function() {
        var $tooltips = $('.wiki-tooltip .wiki-tooltip-content');

        if ($tooltips[0]) {
            $tooltips.each(function() {
                var $this = $(this);

                // Prevent tooltips from overflowing the viewport
                edgeRect = $this.width() + $this.offset().left;
                widthRect = $(window).width();
                if (edgeRect - widthRect > $this.width()*0) {
                    $this.css('left', '');
                    $this.css('right', '0');
                }

                // Check for links and handle them on handheld devices
                if ($this.closest('a').attr('href') !== undefined) {
                    $this.closest('a').removeAttr('title');

                    if (widthRect <= 1000) {
                        wikiTooltip.hasLink($this);
                    }
                }
            });
        }
    },
    hasLink: function(tooltip) {
        var $a = $('<a>');
        var url = tooltip.closest('a');
        var href = url.attr('href');

        $a.attr('href', href);
        url.attr('href', 'javascript:void(0);');
        tooltip.append($a);
        tooltip.css('pointer-events', 'auto');
    }
};
$(wikiTooltip.init);