MediaWiki:Common.js: Difference between revisions

From Business Heroes Food Truck Simulation
No edit summary
No edit summary
Line 10: Line 10:
const areas      = ['Marketing', 'Finance', 'Operations', 'Planning', 'HR', 'Accounting'];
const areas      = ['Marketing', 'Finance', 'Operations', 'Planning', 'HR', 'Accounting'];


// add a link and click event to the dropdown togglers
$(function() {
$('#top-panel .dropdown-toggle').each(function(i,v){
var p = $(v).text();
// add a link and click event to the dropdown togglers
var url = new URL( server + path + '/index.php/' + encodeURIComponent(p));
$('#top-panel .dropdown-toggle').each(function(i,v){
$(v).attr('href', url);
var p = $(v).text();
var url = new URL( server + path + '/index.php/' + encodeURIComponent(p));
$(v).attr('href', url);


$(v).on('click', function(e){
$(v).on('click', function(e){
e.stopPropagation();
e.stopPropagation();
$(v).click;
$(v).click;
});
});
});
});


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


function getActiveCategory(){
function getActiveCategory(){

Revision as of 01:01, 20 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\//, '');
const areas      = ['Marketing', 'Finance', 'Operations', 'Planning', 'HR', 'Accounting'];

$(function() {
	
	// add a link and click event to the dropdown togglers
	$('#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();
			$(v).click;
		});
	});

	// on page load check its name to highlight menu items
	$('#top-panel a.dropdown-toggle').each(function(i,v){
		var 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')
        	.show();
		} else {
    		$(v)
    	    .removeClass('show')
    	    .attr('aria-expanded','false')
    	    .parent()
    	    .removeClass('position-static show')
    	    .find('.dropdown-menu')
    	    .hide();
		}
	});

	// highlight active category
	getActiveCategory();

});

function getActiveCategory(){
	for(var i = 0, j = areas.length; i < j; i++) {
    	if(categories.includes(areas[i])) {
    		$('.im-' + areas[i].toLowerCase()).parent().addClass('im-active');
		} else {
			$('.im-' + areas[i].toLowerCase()).parent().removeClass('im-active');
		}
	}
}