MediaWiki:Common.js: Difference between revisions
From Business Heroes Food Truck Simulation
Wikiworks743 (talk | contribs) No edit summary |
Wikiworks743 (talk | contribs) No edit summary |
||
| Line 7: | Line 7: | ||
const classes = ['im-marketing', 'im-finance', 'im-operations', 'im-planning', 'im-hr', 'im-accounting']; | const classes = ['im-marketing', 'im-finance', 'im-operations', 'im-planning', 'im-hr', 'im-accounting']; | ||
// add a link and click event to the dropdown togglers | // 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){ | ||
var p = $(v).text(); | var p = $(v).text(); | ||
| Line 23: | Line 23: | ||
getActiveCategory(); | getActiveCategory(); | ||
getCurrentPageMenu(); | getCurrentPageMenu(); | ||
$('.im-icon') | $('.im-icon') | ||
.click(function(){ | .click(function(){ | ||
Revision as of 15:21, 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 classes = ['im-marketing', 'im-finance', 'im-operations', 'im-planning', 'im-hr', 'im-accounting'];
// add a link and click event to the dropdown togglers, remember the active dropdown
$('#top-panel .dropdown-toggle').each(function(i,v){
var p = $(v).text();
var url = new URL( server + path + '/index.php/' + encodeURIComponent(p));
$(v).attr('href', url);
$(v).on('click', function(e){
e.stopPropagation();
var current = $(this).parent().find('.dropdown-menu').attr('id');
localStorage.setItem('current', current);
$(v).click;
});
});
getActiveCategory();
getCurrentPageMenu();
$('.im-icon')
.click(function(){
for(var i = 0, j = classes.length; i < j; i++) {
if($(this).hasClass('' + classes[i] + '')) {
localStorage.setItem('active', '' + classes[i] + '');
break;
}
}
})
.each(function(){
for(var i = 0, j = classes.length; i < j; i++) {
prefix = "/index.php/";
page = decodeURIComponent($(this).attr('href').replace(prefix,''));
$(this).attr('title', page);
}
});
function getActiveButton(){
var getactive = localStorage.getItem('active');
$('.im-icon.' + getactive + '').click();
$('.im-icon.' + getactive + '').parent().addClass('im-active');
}
function getCurrentPageMenu(){
var getcurrent = localStorage.getItem('current');
$('#' + getcurrent + '').click();
$('#' + getcurrent + '').addClass('show').parent().addClass('position-static show').find('a').attr('aria-expanded', 'true');
}
function getActiveCategory(){
var cat = [];
cat = mw.config.get('wgCategories');
if(cat.includes("Planning")) {
$('.im-planning').parent().addClass('im-active');
localStorage.setItem('active', 'im-planning' );
} else if(cat.includes("Finance")) {
$('.im-finance').parent().addClass('im-active');
localStorage.setItem('active', 'im-finance' );
} else if(cat.includes("Marketing")) {
$('.im-marketing').parent().addClass('im-active');
localStorage.setItem('active', 'im-marketing' );
} else if(cat.includes("Operations")) {
$('.im-operations').parent().addClass('im-active');
localStorage.setItem('active', 'im-operations' );
} else if(cat.includes("HR")) {
$('.im-hr').parent().addClass('im-active');
localStorage.setItem('active', 'im-hr' );
} else if(cat.includes("accounting")) {
$('.im-accounting').parent().addClass('im-active');
localStorage.setItem('active', 'im-accounting' );
} else {
getActiveButton();
}
}