| 1 |
|
| 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 |
|
| 8 |
monobookMobileElements = false, |
| 9 |
|
| 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 |
|
| 19 |
function closeMenus() { |
| 20 |
$( '.mobile-menu-active' ).removeClass( 'mobile-menu-active' ); |
| 21 |
$( '.menus-cover' ).removeClass( 'visible' ); |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
function setupMonoBookMobile() { |
| 27 |
if ( !monobookMobileElements && mobileMediaQuery.matches ) { |
| 28 |
|
| 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 |
|
| 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 |
|
| 41 |
|
| 42 |
$( function () { |
| 43 |
var newTabs = [ |
| 44 |
'ca-edit', |
| 45 |
|
| 46 |
|
| 47 |
't-contributions' |
| 48 |
]; |
| 49 |
newTabs.forEach( function ( item ) { |
| 50 |
var $a = $( '#' + item + ' a' ); |
| 51 |
|
| 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 |
|
| 68 |
$.each( toggles, function ( toggle, target ) { |
| 69 |
|
| 70 |
$( target ).append( $( '<div>' ).addClass( 'mobile-close-button' ) ); |
| 71 |
|
| 72 |
|
| 73 |
$( toggle ).on( 'click', function () { |
| 74 |
if ( mobileMediaQuery.matches ) { |
| 75 |
$( target ).addClass( 'mobile-menu-active' ); |
| 76 |
$( '.menus-cover' ).addClass( 'visible' ); |
| 77 |
} |
| 78 |
|
| 79 |
return false; |
| 80 |
} ); |
| 81 |
} ); |
| 82 |
|
| 83 |
$( '.mobile-close-button, .menus-cover' ).on( 'click', closeMenus ); |
| 84 |
|
| 85 |
|
| 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 |
} ); |