summaryrefslogtreecommitdiff
blob: 0cf448ae83bdc31e826367570b801b0d5324af12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*!
 * Introduces a toggle icon than can be used to hide navigation menu in vector
 * @author Niklas Laxström
 * @license GPL-2.0-or-later
 */
( function ( mw, $ ) {
	'use strict';

	var $body = $( 'body' );

	if ( $body.width() < 1000 || mw.storage.get( 'translate-navitoggle' ) === '1' ) {
		$body.addClass( 'tux-navi-collapsed' );
	}

	$( function () {
		var $miniLogo, $toggle, rtl, delim;

		rtl = $body.hasClass( 'rtl' );
		delim = rtl ?
			$( '#mw-head-base' ).css( 'margin-right' ) :
			$( '#mw-head-base' ).css( 'margin-left' );

		$miniLogo = $( '#p-logo' )
			.clone()
			.removeAttr( 'id' )
			.addClass( 'tux-navi-minilogo' );

		$toggle = $( '<div>' )
			.addClass( 'tux-navitoggle' )
			.css( rtl ? 'right' : 'left', delim )
			.click( function () {
				$body.toggleClass( 'tux-navi-collapsed' );
				mw.storage.set(
					'translate-navitoggle',
					String( Number( $body.hasClass( 'tux-navi-collapsed' ) ) )
				);
			} );

		$body.append( $miniLogo, $toggle );
	} );
}( mediaWiki, jQuery ) );