MediaWiki:Gadget-navboxToggle.js

From RuneRealm Wiki
Jump to navigation Jump to search

After saving, you may need to bypass your browser's cache to see the changes. For further information, see Wikipedia:Bypass your cache.

  • In most Windows and Linux browsers: Hold down Ctrl and press F5.
  • In Safari: Hold down ⇧ Shift and click the Reload button.
  • In Chrome and Firefox for Mac: Hold down both ⌘ Cmd+⇧ Shift and press R.
$(function () {
	var navtoggle = function () {
		if ($('.navbox.mw-collapsible').length) {
			var $arrow = $('<div>')
				.addClass('mf-icon mw-ui-icon-mf-expand mf-icon--small indicator');
			var $navigationText = $('<span>')
				.addClass('mw-headline')
				.attr('tabindex', '0')
				.attr('role', 'button')
				.text('Navigation');
			var $toggleBar = $('<h2>')
				.attr('id', 'navbox-fake-collapsible-heading')
				.addClass('section-heading collapsible-heading')
				.append($arrow)
				.append($navigationText);
	
			$toggleBar.on('click', function () {
				// flip arrow
				$('#navbox-fake-collapsible-heading > .mf-icon').toggleClass('mf-mw-ui-icon-rotate-flip');
				// collapse navboxes
				$('.navbox.mw-collapsible').toggle();
			});
	
			// pull out navboxes so they don't get collapsed by the previous section
			var $navboxes = $('.navbox.mw-collapsible').detach();
			// default to hidden
			$navboxes.toggle();
			// append everything to the end of the content section
			$('.mw-parser-output').first().append($toggleBar).append($navboxes);
		}
	};
	
	function init() {
		var tout = setTimeout(clearInterval, 30000, checksections);
		var checksections = setInterval( function () {
			if ( $('.mw-parser-output .collapsible-heading *[aria-expanded]').length ) {
				navtoggle();
				clearTimeout(tout);
				clearInterval(checksections);
			}
		}, 500);
	}
	
	init();
});