MediaWiki:VectorPlus.js: Difference between revisions

Jump to navigation Jump to search
(Created page with "$(document).ready(function() { // Check if the current page has a "Tools" menu if ($("#p-tb").length) { // Create a new dropdown menu var dropdown = $("<li>", { "class": "interlanguage-link interwiki-tools" }); var dropdownLink = $("<a>", { "href": "#", "text": "Tools" }); var dropdownList = $("<ul>"); // Move the "What links here" link to the dropdown menu var whatLinksHere = $("#t-whatlinkshere"); if (whatLinksHere.length) { dropd...")
 
mNo edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
$(document).ready(function() {
$(function(){
  // Check if the current page has a "Tools" menu
    // Check if the elements exist
  if ($("#p-tb").length) {
    if (!$('#t-whatlinkshere').length || !$('#t-recentchanges').length || !$('#t-permalink').length || !$('#t-info').length) {
    // Create a new dropdown menu
        return;
    var dropdown = $("<li>", { "class": "interlanguage-link interwiki-tools" });
    var dropdownLink = $("<a>", { "href": "#", "text": "Tools" });
    var dropdownList = $("<ul>");
 
    // Move the "What links here" link to the dropdown menu
    var whatLinksHere = $("#t-whatlinkshere");
    if (whatLinksHere.length) {
      dropdownList.append($("<li>").append(whatLinksHere));
    }
 
    // Move the "Related changes" link to the dropdown menu
    var relatedChanges = $("#t-recentchangeslinked");
    if (relatedChanges.length) {
      dropdownList.append($("<li>").append(relatedChanges));
    }
 
    // Move the "Permanent link" link to the dropdown menu
    var permanentLink = $("#t-permalink");
    if (permanentLink.length) {
      dropdownList.append($("<li>").append(permanentLink));
    }
 
    // Move the "Page information" link to the dropdown menu
    var pageInfo = $("#t-info");
    if (pageInfo.length) {
      dropdownList.append($("<li>").append(pageInfo));
     }
     }


     // Add the dropdown menu to the "Tools" menu
     // Create a dropdown menu for the tools
    dropdown.append(dropdownLink);
    $('<nav id="p-tools" class="vector-menu mw-portlet mw-portlet-tools vector-menu-portal portal" aria-labelledby="p-tools-label" role="navigation">').append(
    dropdown.append(dropdownList);
        $('<h3 id="p-tools-label" class="vector-menu-heading" tabindex="0">').append(
    $("#p-tb ul").prepend(dropdown);
            $('<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');


     // Remove the original links from the "Tools" menu
     // Create a dropdown menu for additional actions
    $("#t-whatlinkshere, #t-recentchangeslinked, #t-permalink, #t-info").remove();
    $('<nav id="p-additional" class="vector-menu mw-portlet mw-portlet-additional vector-menu-portal portal" aria-labelledby="p-additional-label" role="navigation">').append(
  }
        $('<h3 id="p-additional-label" class="vector-menu-heading" tabindex="0">').append(
            $('<span class="vector-menu-heading-label">').text('Additional')
        ).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 $additional = $el.find(".vector-menu-content-list")[0];
                if ($additional.clientWidth < $additional.scrollWidth) {
                    $el.css({'margin-right': '0', 'margin-left': '0'});
                }
                if (window.innerWidth >= 982 && $additional.clientWidth < $additional.scrollWidth) {
                    $el.css({'margin-right': '-0.5em', 'margin-left': '-0.5em'});
                }
            }
        }),
        $('<div class="vector-menu-content">').append(
            $('<ul class="vector-menu-content-list">').append(
                // Add your additional actions here
            )
        )
    ).insertAfter('#ca-history');
});
});

Latest revision as of 01:56, 23 February 2024

$(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');

    // Create a dropdown menu for additional actions
    $('<nav id="p-additional" class="vector-menu mw-portlet mw-portlet-additional vector-menu-portal portal" aria-labelledby="p-additional-label" role="navigation">').append(
        $('<h3 id="p-additional-label" class="vector-menu-heading" tabindex="0">').append(
            $('<span class="vector-menu-heading-label">').text('Additional')
        ).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 $additional = $el.find(".vector-menu-content-list")[0];
                if ($additional.clientWidth < $additional.scrollWidth) {
                    $el.css({'margin-right': '0', 'margin-left': '0'});
                }
                if (window.innerWidth >= 982 && $additional.clientWidth < $additional.scrollWidth) {
                    $el.css({'margin-right': '-0.5em', 'margin-left': '-0.5em'});
                }
            }
        }),
        $('<div class="vector-menu-content">').append(
            $('<ul class="vector-menu-content-list">').append(
                // Add your additional actions here
            )
        )
    ).insertAfter('#ca-history');
});