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 37: | Line 37: | ||
         .find('.dropdown-menu').hide();  |          .find('.dropdown-menu').hide();  | ||
    }  |     }  | ||
});  | });  | ||
getActiveCategory();  | |||
function getActiveCategory(){  | function getActiveCategory(){  | ||
| Line 77: | Line 46: | ||
	if(cat.includes("Planning")) {  | 	if(cat.includes("Planning")) {  | ||
     	$('.im-planning').parent().addClass('im-active');  |      	$('.im-planning').parent().addClass('im-active');  | ||
	} else if(cat.includes("Finance")) {  | 	} else if(cat.includes("Finance")) {  | ||
		$('.im-finance').parent().addClass('im-active');  | 		$('.im-finance').parent().addClass('im-active');  | ||
	} else if(cat.includes("Marketing")) {  | 	} else if(cat.includes("Marketing")) {  | ||
		$('.im-marketing').parent().addClass('im-active');  | 		$('.im-marketing').parent().addClass('im-active');  | ||
	} else if(cat.includes("Operations")) {  | 	} else if(cat.includes("Operations")) {  | ||
		$('.im-operations').parent().addClass('im-active');  | 		$('.im-operations').parent().addClass('im-active');  | ||
	} else if(cat.includes("HR")) {  | 	} else if(cat.includes("HR")) {  | ||
		$('.im-hr').parent().addClass('im-active');  | 		$('.im-hr').parent().addClass('im-active');  | ||
	} else if(cat.includes("accounting")) {  | 	} else if(cat.includes("accounting")) {  | ||
		$('.im-accounting').parent().addClass('im-active');  | 		$('.im-accounting').parent().addClass('im-active');  | ||
	} else {  | 	} else {  | ||
		for(var i = 0, j = classes.length; i < j; i++) {  | 		for(var i = 0, j = classes.length; i < j; i++) {  | ||
     		classes[i].removeClass('im-active');  |      		classes[i].removeClass('im-active');  | ||
		}  | 		}  | ||
	}  | 	}  | ||
}  | }  | ||
Revision as of 21:28, 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;
	});
});
// on page load check its category and name to highlight menu items
var manpage = window.location.pathname.replace('/index.php/','');
var curpage = mw.config.get( 'wgTitle' );
$('#top-panel a.dropdown-toggle').each(function(i,v){
   var p = new URL($(v).attr('href')).pathname.replaceAll('%20',' ').replace('/index.php/', '');
   if(p == curpage){
      $(v)
        .addClass('show').attr('aria-expanded','true')
        .parent().addClass('position-static show')
        .find('.dropdown-menu').show();
   } else {
      $(v)
        .removeClass('show').attr('aria-expanded','false')
        .parent().removeClass('position-static show')
        .find('.dropdown-menu').hide();
   }
});
getActiveCategory();
function getActiveCategory(){
	var cat = [];
	cat = mw.config.get('wgCategories');
	if(cat.includes("Planning")) {
    	$('.im-planning').parent().addClass('im-active');
	} else if(cat.includes("Finance")) {
		$('.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');
		}
	}
}