MediaWiki:Gadget-navboxToggle.js

From Old School Near-Reality Wiki
Jump to navigation Jump to search

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.
 1 $(function () {
 2 	var navtoggle = function () {
 3 		if ($('.navbox.mw-collapsible').length) {
 4 			var $arrow = $('<div>')
 5 				.addClass('mw-ui-icon mw-ui-icon-mf-expand mw-ui-icon-element mw-ui-icon-small indicator mw-ui-icon-flush-left');
 6 			var $navigationText = $('<span>')
 7 				.addClass('mw-headline')
 8 				.text('Navigation');
 9 			var $toggleBar = $('<h2>')
10 				.attr('id', 'navbox-fake-collapsible-heading')
11 				.addClass('section-heading collapsible-heading')
12 				.append($arrow)
13 				.append($navigationText);
14 	
15 			$toggleBar.on('click', function () {
16 				// flip arrow
17 				$('#navbox-fake-collapsible-heading > .mw-ui-icon').toggleClass('mf-mw-ui-icon-rotate-flip');
18 				// collapse navboxes
19 				$('.navbox.mw-collapsible').toggle();
20 			});
21 	
22 			// pull out navboxes so they don't get collapsed by the previous section
23 			var $navboxes = $('.navbox.mw-collapsible').detach();
24 			// default to hidden
25 			$navboxes.toggle();
26 			// append everything to the end of the content section
27 			$('.mw-parser-output').first().append($toggleBar).append($navboxes);
28 		}
29 	};
30 	
31 	function init() {
32 		var tout = setTimeout(clearInterval, 30000, checksections);
33 		var checksections = setInterval( function () {
34 			if ( $('.mw-parser-output .collapsible-heading *[aria-expanded]').length ) {
35 				navtoggle();
36 				clearTimeout(tout);
37 				clearInterval(checksections);
38 			}
39 		}, 500);
40 	}
41 	
42 	init()
43 })