MediaWiki:Common.js
From Business Heroes Food Truck Simulation
Revision as of 08:14, 22 December 2022 by Wikiworks743 (talk | contribs)
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* 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']; const contentWrapper = document.querySelector('#content-wrapper'); const headings = contentWrapper.querySelectorAll('h1 > span, h2 > span, h3 > span, h4 > span, h5 > span, h6 > span'); var firstElement = []; $(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(); // highlight current toc elements followHeadings(); }); 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'); } } } function followHeadings(){ const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { const heading = entry.target; const headingId = heading.getAttribute('id'); var className = "n-" + headingId.replace(/_/g, "-"); firstElement = document.getElementsByClassName(`${className}`); if(firstElement.item(0) === null || firstElement.item(0) === undefined){ } else { $('.nav-link').removeClass('active'); firstElement.item(0).classList.add('active'); } } }); }); headings.forEach((heading) => { observer.observe(heading); }); }