mediawiki-skins-MinervaNeue/resources/skins.minerva.scripts/preInit.js
Jdlrobson 93b16db1c5 Revert "MainMenu is a controller not a View and server rendered"
This reverts commit 111757970e.

Although I cannot replicate the performance issue, the menu doesn't seem to be rendering at all on cached HTML so this is a deal breaker. Back to the drawing board..

Bug: T234599
Change-Id: Idadc5a079340f44ec66d20a38259b6b337d2dcee
2019-10-04 15:03:19 +00:00

60 lines
1.6 KiB
JavaScript

// FIXME: make this an object with a constructor to facilitate testing
// (see https://bugzilla.wikimedia.org/show_bug.cgi?id=44264)
/**
* mobileFrontend namespace
* @class mw.mobileFrontend
* @singleton
*/
module.exports = function () {
// eslint-disable-next-line no-restricted-properties
var M = mw.mobileFrontend,
mobile = M.require( 'mobile.startup' ),
skin = mobile.Skin.getSingleton(),
mainMenu = require( './menu.js' );
/**
* Close navigation if skin is tapped
* @param {JQuery.Event} ev
* @private
*/
function onSkinClick( ev ) {
var $target = $( ev.target );
// Make sure the menu is open and we are not clicking on the menu button
if (
mainMenu &&
mainMenu.isOpen() &&
// eslint-disable-next-line no-jquery/no-class-state
!$target.hasClass( 'main-menu-button' )
) {
mainMenu.closeNavigationDrawers();
ev.preventDefault();
}
}
skin.on( 'click', onSkinClick.bind( skin ) );
( function ( wgRedirectedFrom ) {
// If the user has been redirected, then show them a toast message (see
// https://phabricator.wikimedia.org/T146596).
var redirectedFrom, $msg, title;
if ( wgRedirectedFrom === null ) {
return;
}
redirectedFrom = mw.Title.newFromText( wgRedirectedFrom );
if ( redirectedFrom ) {
// mw.Title.getPrefixedText includes the human-readable namespace prefix.
title = redirectedFrom.getPrefixedText();
$msg = $( '<div>' ).html(
mw.message( 'mobile-frontend-redirected-from', title ).parse()
);
$msg.find( 'a' ).attr( 'href', mw.util.getUrl( title, { redirect: 'no' } ) );
mw.notify( $msg );
}
}( mw.config.get( 'wgRedirectedFrom' ) ) );
/* eslint-enable no-console */
};