2019-03-13 18:57:00 -04:00
|
|
|
/* eslint-disable no-jquery/no-global-selector */
|
2019-01-14 16:00:07 -05:00
|
|
|
$( function () {
|
2019-07-12 15:51:58 -04:00
|
|
|
var mobileMediaQuery = window.matchMedia( 'screen and (max-width: 550px)' ),
|
2020-08-04 17:39:18 -04:00
|
|
|
loadOptionalDependencies = require( './optional-enhancements.js' ),
|
2019-01-14 16:00:07 -05:00
|
|
|
// Track if DOM has been set up for mobile fanciness yet
|
|
|
|
monobookMobileElements = false,
|
|
|
|
// Toggles and targets for popouts
|
|
|
|
toggles = {
|
|
|
|
'#sidebar-toggle': '#sidebar-mobilejs',
|
|
|
|
'#p-personal-toggle': '#p-personal',
|
|
|
|
'#ca-more a': '#p-cactions',
|
|
|
|
'#ca-languages a': '#p-lang',
|
|
|
|
'#ca-tools a': '#p-tb'
|
|
|
|
};
|
2018-05-03 15:45:10 -04:00
|
|
|
|
2019-01-14 16:00:07 -05:00
|
|
|
// Close menus
|
|
|
|
function closeMenus() {
|
|
|
|
$( '.mobile-menu-active' ).removeClass( 'mobile-menu-active' );
|
|
|
|
$( '.menus-cover' ).removeClass( 'visible' );
|
|
|
|
}
|
2018-05-03 15:45:10 -04:00
|
|
|
|
2019-01-14 16:00:07 -05:00
|
|
|
// Set up DOM for mobile fanciness
|
|
|
|
// We don't automatically do this because MonoBook; most users will be on desktop
|
|
|
|
function setupMonoBookMobile() {
|
2019-07-12 15:51:58 -04:00
|
|
|
if ( !monobookMobileElements && mobileMediaQuery.matches ) {
|
2019-01-14 16:00:07 -05:00
|
|
|
// Duplicate nav
|
|
|
|
$( '#column-one' ).append(
|
|
|
|
$( '#sidebar' ).clone().find( '*' ).addBack().each( function () {
|
|
|
|
if ( this.id ) {
|
|
|
|
this.id = this.id + '-mobilejs';
|
|
|
|
}
|
|
|
|
} ).end().end()
|
|
|
|
);
|
|
|
|
// Thing to fade out the content while menus are active
|
|
|
|
$( '#column-one' ).append( $( '<div>' ).attr( 'id', 'menus-cover-background' ).addClass( 'menus-cover' ) );
|
|
|
|
$( '#column-one' ).append( $( '<div>' ).attr( 'id', 'menus-cover' ).addClass( 'menus-cover' ) );
|
2018-05-03 15:45:10 -04:00
|
|
|
|
2019-01-14 16:00:07 -05:00
|
|
|
// Add extra cactions tabs - edit, editsource, contributions
|
|
|
|
// Wrap in function to keep jenkins from whining
|
|
|
|
$( function () {
|
|
|
|
var newTabs = [
|
|
|
|
'ca-edit',
|
|
|
|
// 'ca-ve-edit', // TODO when VE is more usable to begin with here
|
|
|
|
// 'ca-watch', 'ca-unwatch', // Maybe?
|
|
|
|
't-contributions'
|
|
|
|
];
|
|
|
|
newTabs.forEach( function ( item ) {
|
2019-10-31 17:47:42 -04:00
|
|
|
var $a = $( '#' + item + ' a' );
|
2019-01-14 16:00:07 -05:00
|
|
|
// TODO check if we're on the page and add class=selected
|
2018-05-03 15:45:10 -04:00
|
|
|
|
2019-10-31 17:47:42 -04:00
|
|
|
if ( $a.length ) {
|
2019-01-14 16:00:07 -05:00
|
|
|
mw.util.addPortletLink(
|
|
|
|
'p-cactions-mobile',
|
2019-10-31 17:47:42 -04:00
|
|
|
$a.attr( 'href' ),
|
|
|
|
$a.text(),
|
|
|
|
$a.parent().attr( 'id' ) + '-mobile',
|
|
|
|
$a.attr( 'tooltip' ),
|
|
|
|
$a.attr( 'accesskey' ),
|
2019-01-14 16:00:07 -05:00
|
|
|
'#ca-more'
|
|
|
|
);
|
|
|
|
}
|
2018-05-03 15:45:10 -04:00
|
|
|
} );
|
2019-01-14 16:00:07 -05:00
|
|
|
} );
|
2018-05-03 15:45:10 -04:00
|
|
|
|
2019-03-13 18:57:00 -04:00
|
|
|
// eslint-disable-next-line no-jquery/no-each-util
|
2019-01-14 16:00:07 -05:00
|
|
|
$.each( toggles, function ( toggle, target ) {
|
2018-05-03 15:45:10 -04:00
|
|
|
// Add close buttons
|
2019-01-14 16:00:07 -05:00
|
|
|
$( target ).append( $( '<div>' ).addClass( 'mobile-close-button' ) );
|
2018-05-03 15:45:10 -04:00
|
|
|
|
|
|
|
// Open menus
|
2019-01-14 16:00:07 -05:00
|
|
|
$( toggle ).on( 'click', function () {
|
2019-07-12 15:51:58 -04:00
|
|
|
if ( mobileMediaQuery.matches ) {
|
2019-01-14 16:00:07 -05:00
|
|
|
$( target ).addClass( 'mobile-menu-active' );
|
|
|
|
$( '.menus-cover' ).addClass( 'visible' );
|
|
|
|
}
|
|
|
|
// Don't still link to # targets
|
|
|
|
return false;
|
2018-05-03 15:45:10 -04:00
|
|
|
} );
|
2019-01-14 16:00:07 -05:00
|
|
|
} );
|
2018-05-03 15:45:10 -04:00
|
|
|
|
2019-01-14 16:00:07 -05:00
|
|
|
$( '.mobile-close-button, .menus-cover' ).on( 'click', closeMenus );
|
|
|
|
// TODO: tap events on same (if not already included in 'click') - also close
|
|
|
|
// TODO: appropriate swipe event(s) - also close
|
2018-05-03 15:45:10 -04:00
|
|
|
|
2019-01-14 16:00:07 -05:00
|
|
|
monobookMobileElements = true;
|
2018-05-03 15:45:10 -04:00
|
|
|
}
|
2019-01-14 16:00:07 -05:00
|
|
|
}
|
2018-05-03 15:45:10 -04:00
|
|
|
|
2019-01-14 16:00:07 -05:00
|
|
|
$( window ).on( 'resize', setupMonoBookMobile );
|
|
|
|
setupMonoBookMobile();
|
2020-08-04 17:39:18 -04:00
|
|
|
loadOptionalDependencies();
|
2019-01-14 16:00:07 -05:00
|
|
|
} );
|