Debian Codegraph @

skins/MonoBook/resources/skin.js

raw symbols SCIP
1 /* eslint-disable no-jquery/no-global-selector */
2 $( function () {
3 var mobileMediaQuery = window.matchMedia( 'screen and (max-width: 550px)' ),
4 isResponsive = document.body.classList.contains( 'skin--responsive' ),
5 echo = require( './mobile-echo.js' ),
6 uls = require( './mobile-uls.js' ),
7 // Track if DOM has been set up for mobile fanciness yet
8 monobookMobileElements = false,
9 // Toggles and targets for popouts
10 toggles = {
11 '#sidebar-toggle': '#sidebar-mobilejs',
12 '#p-personal-toggle': '#p-personal',
13 '#ca-more a': '#p-cactions',
14 '#ca-languages a': '#p-lang',
15 '#ca-tools a': '#p-tb'
16 };
17
18 // Close menus
19 function closeMenus() {
20 $( '.mobile-menu-active' ).removeClass( 'mobile-menu-active' );
21 $( '.menus-cover' ).removeClass( 'visible' );
22 }
23
24 // Set up DOM for mobile fanciness
25 // We don't automatically do this because MonoBook; most users will be on desktop
26 function setupMonoBookMobile() {
27 if ( !monobookMobileElements && mobileMediaQuery.matches ) {
28 // Duplicate nav
29 $( '#column-one' ).append(
30 $( '#sidebar' ).clone().find( '*' ).addBack().each( function () {
31 if ( this.id ) {
32 this.id = this.id + '-mobilejs';
33 }
34 } ).end().end()
35 );
36 // Thing to fade out the content while menus are active
37 $( '#column-one' ).append( $( '<div>' ).attr( 'id', 'menus-cover-background' ).addClass( 'menus-cover' ) );
38 $( '#column-one' ).append( $( '<div>' ).attr( 'id', 'menus-cover' ).addClass( 'menus-cover' ) );
39
40 // Add extra cactions tabs - edit, editsource, contributions
41 // Wrap in function to keep jenkins from whining
42 $( function () {
43 var newTabs = [
44 'ca-edit',
45 // 'ca-ve-edit', // TODO when VE is more usable to begin with here
46 // 'ca-watch', 'ca-unwatch', // Maybe?
47 't-contributions'
48 ];
49 newTabs.forEach( function ( item ) {
50 var $a = $( '#' + item + ' a' );
51 // TODO check if we're on the page and add class=selected
52
53 if ( $a.length ) {
54 mw.util.addPortletLink(
55 'p-cactions-mobile',
56 $a.attr( 'href' ),
57 $a.text(),
58 $a.parent().attr( 'id' ) + '-mobile',
59 $a.attr( 'tooltip' ),
60 $a.attr( 'accesskey' ),
61 '#ca-more'
62 );
63 }
64 } );
65 } );
66
67 // eslint-disable-next-line no-jquery/no-each-util
68 $.each( toggles, function ( toggle, target ) {
69 // Add close buttons
70 $( target ).append( $( '<div>' ).addClass( 'mobile-close-button' ) );
71
72 // Open menus
73 $( toggle ).on( 'click', function () {
74 if ( mobileMediaQuery.matches ) {
75 $( target ).addClass( 'mobile-menu-active' );
76 $( '.menus-cover' ).addClass( 'visible' );
77 }
78 // Don't still link to # targets
79 return false;
80 } );
81 } );
82
83 $( '.mobile-close-button, .menus-cover' ).on( 'click', closeMenus );
84 // TODO: tap events on same (if not already included in 'click') - also close
85 // TODO: appropriate swipe event(s) - also close
86
87 monobookMobileElements = true;
88 }
89 }
90
91 if ( isResponsive ) {
92 $( window ).on( 'resize', setupMonoBookMobile );
93 setupMonoBookMobile();
94 if ( mw.loader.getState( 'ext.uls.interface' ) !== null ) {
95 uls();
96 }
97 if ( mw.loader.getState( 'ext.echo.init' ) !== null && !mw.user.isAnon() ) {
98 echo();
99 }
100 }
101 } );