MediaWiki:Common.js: Difference between revisions

fixed the mobile redirect so it actually sticks now
Tag: Reverted
gave the mobile menu some actual links
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
// ==========================================================================
// Force the branded desktop (Vector) skin for everyone, including phones.
// The site auto-switches to MediaWiki's generic Minerva mobile skin based
// on user-agent, which has none of the custom theme/nav and is a much
// worse experience than the (now mobile-responsive) desktop skin. This
// runs as early as possible to minimize the flash of the wrong skin before
// redirecting.
//
// The real loop-guard is the cookie this site's toggle actually sets
// (confirmed by testing: "stopMobileRedirect=true", not the generic
// MobileFrontend "mf_useformat" name assumed earlier) since it's set by
// the server and survives across tabs/sessions. sessionStorage is only a
// secondary backstop, wrapped in its own try/catch, so that browsers which
// block storage access (common in some in-app/embedded browsers) don't
// silently cancel the whole redirect and strand the user on Minerva.
(function () {
  try {
    if (!document.body || !document.body.classList.contains('skin-minerva')) return;
    if (document.cookie.indexOf('stopMobileRedirect=true') !== -1) return;
    var alreadyTried = false;
    try { alreadyTried = !!sessionStorage.getItem('wovForcedDesktop'); } catch (e) {}
    if (alreadyTried) return;
    try { sessionStorage.setItem('wovForcedDesktop', '1'); } catch (e) {}
    var sep = window.location.search ? '&' : '?';
    window.location.href = window.location.pathname + window.location.search + sep + 'mobileaction=toggle_view_desktop';
  } catch (e) {
    // if even the basic checks are blocked, just leave the user on Minerva
    // rather than risk breaking the rest of the site's scripts.
  }
})();
$(document).ready(function() {
$(document).ready(function() {
     $('#ca-nstab-main a').text('Article');
     $('#ca-nstab-main a').text('Article');
Line 35: Line 4:
     $('#ca-view a').text('Read');
     $('#ca-view a').text('Read');
});
});
// ==========================================================================
// Minerva (mobile skin) main menu only ships Home/Random by default; it does
// not pull in MediaWiki:Sidebar the way Vector's portlets do. This injects
// the same section links (kept in sync with MediaWiki:Sidebar by hand) into
// the native menu markup so mobile visitors actually get real navigation
// instead of just Home/Random/Settings/About/Disclaimers.
(function () {
  function initMinervaNav() {
    try {
      if (!document.body || !document.body.classList.contains('skin-minerva')) return;
      var nav = document.getElementById('p-navigation');
      if (!nav || document.getElementById('wov-minerva-extra-nav')) return;
      var sections = [
        { heading: 'Guides', items: [
          ['Getting started', '/w/Getting_Started'],
          ['Interactive Map (Fullscreen)', 'https://jxlife.github.io/WindsOfValenMap/'],
          ['All skills', '/w/Skills'],
          ['All quests', '/w/Quests'],
          ['Combat guide', '/w/Combat']
        ]},
        { heading: 'Database', items: [
          ['Item database', '/w/Items'],
          ['NPC database', '/w/NPCs'],
          ['Set bonuses', '/w/Set_bonuses']
        ]},
        { heading: 'Skills', items: [
          ['Skill Calculator', '/w/Calculators'],
          ['Mining', '/w/Mining'],
          ['Smithing', '/w/Smithing'],
          ['Fishing', '/w/Fishing'],
          ['Potion Making', '/w/Potion_Making']
        ]},
        { heading: 'Tools', items: [
          ['About this wiki', '/w/Project:About'],
          ['Random page', '/w/Special:Random'],
          ['New files', '/w/Special:NewFiles'],
          ['Wanted pages', '/w/Special:WantedPages'],
          ['Wiki statistics', '/w/Special:Statistics']
        ]},
        { heading: 'Updates', items: [
          ['Recent changes', '/w/Special:RecentChanges']
        ]}
      ];
      var container = document.createElement('div');
      container.id = 'wov-minerva-extra-nav';
      sections.forEach(function (section) {
        var heading = document.createElement('div');
        heading.className = 'wov-minerva-nav-heading';
        heading.textContent = section.heading;
        container.appendChild(heading);
        var ul = document.createElement('ul');
        ul.className = 'toggle-list__list';
        section.items.forEach(function (item) {
          var li = document.createElement('li');
          li.className = 'toggle-list-item';
          var a = document.createElement('a');
          a.className = 'toggle-list-item__anchor';
          a.href = item[1];
          var label = document.createElement('span');
          label.className = 'toggle-list-item__label';
          label.textContent = item[0];
          a.appendChild(label);
          li.appendChild(a);
          ul.appendChild(li);
        });
        container.appendChild(ul);
      });
      nav.parentNode.insertBefore(container, nav.nextSibling);
    } catch (e) {}
  }
  if (document.body) {
    initMinervaNav();
  } else {
    document.addEventListener('DOMContentLoaded', initMinervaNav);
  }
})();
// ==========================================================================
// ==========================================================================
// Valen Ledger — Gathering & Combat XP Calculator
// Valen Ledger — Gathering & Combat XP Calculator