MediaWiki:Mobile.js

Revision as of 10:47, 29 April 2025 by Bxuwd (talk | contribs) (Created page with "All JavaScript here will be loaded for users of the mobile site: 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 f...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 mobile site */
/* 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)
    );
    // Determine where to insert: Try after 'Watchlist' (#mi-watchlist), fallback to after 'Settings' (#mi-settings)
    var insertAfterSelector = menu.find('#mi-watchlist').length ? '#mi-watchlist' : '#mi-settings';
    menu.insertAfter(insertAfterSelector, item);

    // 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
    );
    menu.insertAfter('#mw-mobile-menu-cat-loc', item); // Insert after the previously added 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); // Insert after the previously added 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); // Insert after the previously added 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); // Insert after the previously added 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); // Insert after the previously added item

  });
});