Jump to content

MediaWiki:Mobile.js

From Artemis Archive
Revision as of 12:58, 29 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.
/* Wait for the MobileFrontend startup modules to be ready */
mw.loader.using('mobile.startup', function () {

  /* Listen for the hook that fires when the main menu is being built */
  mw.hook('mobileFrontend.mainMenu.bootstrap').add(function (menu) {
    var item; // Variable to store the menu item being created

    /* --- Add Links under "Categories" --- */
    // Note: Mobile menus are typically flat lists; adding actual section headers isn't standard.
    // We will add the links directly.

    // Create the "By Location/地点" link
    item = mw.mobileFrontend.menu.buildLink(
      'mw-mobile-menu-cat-loc',                  // Unique ID for this menu item (customizable)
      'By Location/地点',                       // Display text (using the bilingual text from your sidebar)
      mw.util.getUrl('Animal cruelty cases by location') // Target page name (same as in sidebar)
    );
    // *** Use the correct ID found in the HTML for insertion point ***
    // Insert after the "Settings" item which has id="menu-item-settings"
    menu.insertAfter('#menu-item-settings', item); // Use the correct ID found from inspection

    // Create the "By Species/物种" link
    item = mw.mobileFrontend.menu.buildLink(
      'mw-mobile-menu-cat-sp',                   // Unique ID
      'By Species/物种',                        // Display text
      mw.util.getUrl('Animal cruelty cases by species') // Target page
    );
    // Insert after the previously added item using *its* ID
    menu.insertAfter('#mw-mobile-menu-cat-loc', item);

    // Create the "By Year/年份" link
    item = mw.mobileFrontend.menu.buildLink(
      'mw-mobile-menu-cat-yr',                   // Unique ID
      'By Year/年份',                         // Display text
      mw.util.getUrl('Animal cruelty cases by year') // Target page
    );
    menu.insertAfter('#mw-mobile-menu-cat-sp', item);


    /* --- Add Links under "Resources" --- */

    // Create the "Useful links/实用链接" link
    item = mw.mobileFrontend.menu.buildLink(
      'mw-mobile-menu-res-ul',                   // Unique ID
      'Useful links/实用链接',                  // Display text
      mw.util.getUrl('useful links')             // Target page (ensure 'useful links' is the correct page name)
    );
    menu.insertAfter('#mw-mobile-menu-cat-yr', item);

    // Create the "Documentaries/纪录片" link
    item = mw.mobileFrontend.menu.buildLink(
      'mw-mobile-menu-res-doc',                  // Unique ID
      'Documentaries/纪录片',                   // Display text
      mw.util.getUrl('documentaries')            // Target page (ensure 'documentaries' is the correct page name)
    );
    menu.insertAfter('#mw-mobile-menu-res-ul', item);

    // Create the "Psychological study/心理研究" link
    item = mw.mobileFrontend.menu.buildLink(
      'mw-mobile-menu-res-psy',                  // Unique ID
      'Psychological study/心理研究',             // Display text
      mw.util.getUrl('psychological study')      // Target page (ensure 'psychological study' is the correct page name, watch for typos)
    );
    menu.insertAfter('#mw-mobile-menu-res-doc', item);

  });
});