MediaWiki:Common.js: Difference between revisions

From Business Heroes Food Truck Simulation
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 8: Line 8:
const curpage = mw.config.get('wgTitle');
const curpage = mw.config.get('wgTitle');
const manpage = window.location.pathname.replace(/\/index\.php\//, '');
const manpage = window.location.pathname.replace(/\/index\.php\//, '');
let activeDropdown = null;


$('#top-panel .dropdown-toggle').each(function(i, v) {
$('#top-panel .dropdown-toggle').each(function(i, v) {
   const p = $(v).text();
   const p = $(v).text();
   const url = new URL( server + path + '/index.php/' + encodeURIComponent(p));
   const url = new URL( '' + server + path + '/index.php/' + encodeURIComponent(p) + '');
   $(v).attr('href', url);
   $(v).attr('href', url);


   $(v).on('click', function(e) {
   $(v).on('click', function(e) {
     e.stopPropagation();
     e.stopPropagation();
     activeDropdown = $(this).parent().find('.dropdown-menu').attr('id');
     $(this).parent().find('.dropdown-menu').attr('id');
     $(v).click;
     $(v).click;
   });
   });

Revision as of 22:22, 19 December 2022

/* Any JavaScript here will be loaded for all users on every page load. */

$('#p-contentnavigation').append($('#editor-menu'));

const server  = mw.config.get('wgServer');
const path    = mw.config.get('wgScriptPath');
const categories = mw.config.get('wgCategories');
const curpage = mw.config.get('wgTitle');
const manpage = window.location.pathname.replace(/\/index\.php\//, '');

$('#top-panel .dropdown-toggle').each(function(i, v) {
  const p = $(v).text();
  const url = new URL( '' + server + path + '/index.php/' + encodeURIComponent(p) + '');
  $(v).attr('href', url);

  $(v).on('click', function(e) {
    e.stopPropagation();
    $(this).parent().find('.dropdown-menu').attr('id');
    $(v).click;
  });
});

$('#top-panel a.dropdown-toggle').each(function(i, v) {
  const p = new URL($(v).attr('href')).pathname.replace(/%20/g, ' ').replace(/\/index\.php\//, '');
  if (p === curpage) {
    $(v)
      .addClass('show')
      .attr('aria-expanded', 'true')
      .parent()
      .addClass('position-static show')
      .find('.dropdown-menu')
      .toggleClass('d-none', false);
  } else {
    $(v)
      .removeClass('show')
      .attr('aria-expanded', 'false')
      .parent()
      .removeClass('position-static show')
      .find('.dropdown-menu')
      .toggleClass('d-none', true);
  }
});

getActiveCategory();

function getActiveCategory() {
  const activeCategory = categories.find(category => category.toLowerCase() === manpage.toLowerCase());
  if (activeCategory) {
    $(`.im-${activeCategory.toLowerCase()}`).parent().addClass('im-active');
  } else {
    $(`.im-${activeCategory.toLowerCase()}`).parent().removeClass('im-active');
  }
}