MediaWiki:VectorPlus.js

Revision as of 01:43, 23 February 2024 by Makko Oko (talk | contribs)
Jump to navigation Jump to search

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.
$(function(){
    // Check if the elements exist
    if (!$('#t-whatlinkshere').length || !$('#t-recentchanges').length || !$('#t-permalink').length || !$('#t-info').length) {
        return;
    }

    // Create a dropdown menu for the tools
    $('<nav id="p-tools" class="vector-menu mw-portlet mw-portlet-tools vector-menu-portal portal" aria-labelledby="p-tools-label" role="navigation">').append(
        $('<h3 id="p-tools-label" class="vector-menu-heading" tabindex="0">').append(
            $('<span class="vector-menu-heading-label">').text('Tools')
        ).on("keypress", function(event) {
            if (event.which == 13) {
                $(this).trigger("click");
                event.stopImmediatePropagation();
            }
        }).on("click", function(event) {
            var $el = $(this).parent();
            event.stopPropagation();
            if($el.hasClass("collapsed")){
                $el.find(".vector-menu-content").slideUp("fast");
                $el.css({'margin-right': '', 'margin-left': ''});
            }
            else{
                $el.find(".vector-menu-content").slideDown("fast");
                var $tools = $el.find(".vector-menu-content-list")[0];
                if ($tools.clientWidth < $tools.scrollWidth) {
                    $el.css({'margin-right': '0', 'margin-left': '0'});
                }
                if (window.innerWidth >= 982 && $tools.clientWidth < $tools.scrollWidth) {
                    $el.css({'margin-right': '-0.5em', 'margin-left': '-0.5em'});
                }
            }
        }),
        $('<div class="vector-menu-content">').append(
            $('<ul class="vector-menu-content-list">').append(
                $('<li>').append($('#t-whatlinkshere')),
                $('<li>').append($('#t-recentchanges')),
                $('<li>').append($('#t-permalink')),
                $('<li>').append($('#t-info'))
            )
        )
    ).appendTo('#p-cactions');
});