Jump to content

MediaWiki:Minerva.js

From Artemis Archive
Revision as of 11:51, 30 April 2025 by Bxuwd (talk | contribs)

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.
/* All JavaScript here will be loaded for users of the MinervaNeue skin */
mw.loader.using(['mobile.startup', 'mediawiki.util'], function () { // Ensure modules are loaded
  mw.hook('mobileFrontend.mainMenu.bootstrap').add(function (menu) {
    // Ensure menu object and API function exist
    if (!menu || typeof mw.mobileFrontend.menu.buildLink !== 'function') {
      console.error('Mobile menu object or buildLink function not available.');
      return;
    }

    // --- Define Menu Items (same as before) ---
    var categoryItems = [
      { id: 'cat-loc', text: 'By Location/地点', page: 'Animal cruelty cases by location' },
      { id: 'cat-sp',  text: 'By Species/物种', page: 'Animal cruelty cases by species' },
      { id: 'cat-yr',  text: 'By Year/年份', page: 'Animal cruelty cases by year' }
    ];
    var resourceItems = [
      { id: 'res-ul',  text: 'Useful links/实用链接', page: 'useful links' },
      { id: 'res-doc', text: 'Documentaries/纪录片', page: 'documentaries' },
      { id: 'res-psy', text: 'Psychological study/心理研究', page: 'psychological study' }
    ];

    // --- Find Insertion Point (same as before) ---
    var $insertAfterElement = $('#p-navigation').find('#menu-item-random');
    if (!$insertAfterElement.length) {
       $insertAfterElement = $('#pt-preferences').find('#menu-item-settings');
    }
    if (!$insertAfterElement.length) {
        console.error('Could not find suitable insertion point for mobile menu items.');
        return;
    }

    // --- Create and Insert Items ---
    var $lastElement = $insertAfterElement; // Keep track of the last inserted element for placing divider and next group

    // Function to create and insert an item
    function insertItem(itemData, iconClass) {
        var $item = mw.mobileFrontend.menu.buildLink(itemData.id, itemData.text, mw.util.getUrl(itemData.page));
        // Add specific classes to the LI for CSS targeting
        var $li = $('<li>').attr('id', 'menu-item-' + itemData.id).addClass('custom-menu-item').append($item);
        $lastElement.after($li);
        $lastElement = $li; // Update $lastElement to the newly inserted item
    }

    // Insert Category Items
    categoryItems.forEach(function(itemData) {
        insertItem(itemData, 'mw-ui-icon-minerva-listBullet'); // Using a bullet icon class
    });

    // Insert a Divider LI with a specific class
    var $divider = $('<li>').addClass('menu-divider-section'); // Add class for CSS styling
    $lastElement.after($divider);
    $lastElement = $divider; // Update last element to the divider

    // Insert Resource Items
    resourceItems.forEach(function(itemData) {
        // Determine icon based on item ID or text maybe? Using generic for now.
        var icon = 'mw-ui-icon-minerva-link'; // Example, adjust as needed
        insertItem(itemData, icon);
    });

  });
});