MediaWiki:Common.js: Difference between revisions

From Business Heroes Food Truck Simulation
No edit summary
No edit summary
Tag: Reverted
Line 3: Line 3:
$('#p-contentnavigation').append($('#editor-menu'));
$('#p-contentnavigation').append($('#editor-menu'));


const server  = mw.config.get ( 'wgServer' );
const server  = mw.config.get('wgServer');
const path    = mw.config.get ( 'wgScriptPath' );
const path    = mw.config.get('wgScriptPath');
const classes = ['im-marketing', 'im-finance', 'im-operations', 'im-planning', 'im-hr', 'im-accounting'];
const categories = mw.config.get('wgCategories');
const manpage = window.location.pathname.replace(/\/index\.php\//, '');
const curpage = mw.config.get('wgTitle');
let activeDropdown = null;


// add a link and click event to the dropdown togglers, remember the active dropdown
$('#top-panel .dropdown-toggle').each(function(i, v) {
$('#top-panel .dropdown-toggle').each(function(i,v){
  const p = $(v).text();
var p = $(v).text();
  const url = new URL(`${server}${path}/index.php/${encodeURIComponent(p)}`);
var 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();
var current = $(this).parent().find('.dropdown-menu').attr('id');
    activeDropdown = $(this).parent().find('.dropdown-menu').attr('id');
localStorage.setItem('current', current);
    $(v).click;
$(v).click;
  });
});
});
});


// on page load check its category and name to highlight menu items
$('#top-panel a.dropdown-toggle').each(function(i, v) {
var manpage = window.location.pathname.replace('/index.php/','');
  const p = new URL($(v).attr('href')).pathname.replace(/%20/g, ' ').replace(/\/index\.php\//, '');
var curpage = mw.config.get( 'wgTitle' );
  if (p === curpage) {
$('#top-panel a.dropdown-toggle').each(function(i,v){
    $(v)
  var p = new URL($(v).attr('href')).pathname.replaceAll('%20',' ').replace('/index.php/', '');
      .addClass('show')
  if(p == curpage){
      .attr('aria-expanded', 'true')
      $(v)
      .parent()
        .addClass('show').attr('aria-expanded','true')
      .addClass('position-static show')
        .parent().addClass('position-static show')
      .find('.dropdown-menu')
        .find('.dropdown-menu').show();
      .toggleClass('d-none', false);
  } else {
  } else {
      $(v)
    $(v)
        .removeClass('show').attr('aria-expanded','false')
      .removeClass('show')
        .parent().removeClass('position-static show')
      .attr('aria-expanded', 'false')
        .find('.dropdown-menu').hide();
      .parent()
  }
      .removeClass('position-static show')
      .find('.dropdown-menu')
      .toggleClass('d-none', true);
  }
});
});


getActiveCategory();
getActiveCategory();


function getActiveCategory(){
function getActiveCategory() {
var cat = [];
  const activeCategory = categories.find(category => category.toLowerCase() === manpage.toLowerCase());
cat = mw.config.get('wgCategories');
  if (activeCategory) {
if(cat.includes("Planning")) {
    $(`.im-${activeCategory.toLowerCase()}`).parent().addClass('im-active');
    $('.im-planning').parent().addClass('im-active');
  } else {
} else if(cat.includes("Finance")) {
    $(`.im-${activeCategory.toLowerCase()}`).parent().removeClass('im-active');
$('.im-finance').parent().addClass('im-active');
  }
} else if(cat.includes("Marketing")) {
$('.im-marketing').parent().addClass('im-active');
} else if(cat.includes("Operations")) {
$('.im-operations').parent().addClass('im-active');
} else if(cat.includes("HR")) {
$('.im-hr').parent().addClass('im-active');
} else if(cat.includes("accounting")) {
$('.im-accounting').parent().addClass('im-active');
} else {
for(var i = 0, j = classes.length; i < j; i++) {
    classes[i].removeClass('im-active');
}
}
}
}

Revision as of 22:18, 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 manpage = window.location.pathname.replace(/\/index\.php\//, '');
const curpage = mw.config.get('wgTitle');
let activeDropdown = null;

$('#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();
    activeDropdown = $(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');
  }
}