MediaWiki:Gadget-autocollapse.js

From Old School Near-Reality Wiki
Revision as of 18:00, 3 October 2022 by Jacmob (talk | contribs) (Created page with "→‎* * Automatically collapsed navboxes under certain conditions: (function($, mw){ if ($( ".mw-collapsible-toggle" ).length) expandMaps(); if ( !$('.navbox-autocollapse').length || mw.Uri().query.veaction != undefined ) return; mw.hook('wikipage.collapsibleContent').add(init); function init() { var $navboxes = $('.navbox'), // maximum number of navboxes before they all stay collapsed maxShow = 1, // maximum allowable height of navbox before it s...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 /**
 2  * Automatically collapsed navboxes under certain conditions
 3  */
 4 (function($, mw){
 5 	if ($( ".mw-collapsible-toggle" ).length) expandMaps();
 6 	if (
 7 		!$('.navbox-autocollapse').length ||
 8 		mw.Uri().query.veaction != undefined
 9 	) return;
10 	mw.hook('wikipage.collapsibleContent').add(init);
11 	
12 	function init() {
13 		var $navboxes = $('.navbox'),
14 			// maximum number of navboxes before they all stay collapsed
15 			maxShow = 1,
16 			// maximum allowable height of navbox before it stays collapsed
17 			maxHeight = 300;
18 
19 		if ($navboxes.length > maxShow) {
20 			return;
21 		}
22 		
23 		$navboxes.each(function(i,box){
24 			var $box = $(box);
25 			if (!$box.hasClass('navbox-autocollapse')) return;
26 			$box.data('mw-collapsible').expand();
27 			if ( $box.height() > maxHeight ) $box.data('mw-collapsible').collapse();
28 		});
29 	}
30 	
31 	// handle collapsible maps
32 	function expandMaps() {
33 		$( ".mw-collapsible-toggle" ).on( "click keypress", function() {
34 		    const $this = $( this );
35 		    
36 		    if( $this.hasClass( "mw-collapsible-toggle-expanded" ) ) {
37 		        mw.hook( "wikipage.content" ).fire(
38 		            $( "a.mw-kartographer-map", $this.parents( ".mw-collapsible" ).first() ).parent()
39 		        );
40 		    }
41 		} );
42 	}
43 	//$(init);
44 	
45 })(jQuery, mediaWiki);