summaryrefslogtreecommitdiff
blob: 69d173d8d2f989cbbadea6bdb034c916e2a40ba0 (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
42
43
44
45
46
/*!
 * 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 () {
	'use strict';

	var $body = $( document.body );

	// Bail out on the new Vector skin
	if ( $( '#mw-sidebar-button' ).length ) {
		return;
	}

	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 )
			.on( 'click', function () {
				$body.toggleClass( 'tux-navi-collapsed' );
				mw.storage.set(
					'translate-navitoggle',
					String( Number( $body.hasClass( 'tux-navi-collapsed' ) ) )
				);
			} );

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