Hygiene: Minerva uses skin instance defined by MobileFrontend

The global events for resize and throttled will also be defined
inside MobileFrontend.

Depends-On: I8503c26bd064ae0d203f95a35031468c7c678ac1
Bug: T173454
Change-Id: I00d361ad504ab90f2bf80a53a7c76269f1116207
This commit is contained in:
jdlrobson 2017-09-07 13:34:35 -04:00 committed by Jdlrobson
parent 1c0d0d5f3c
commit 8729f0b654
2 changed files with 6 additions and 104 deletions

View file

@ -5,24 +5,12 @@
* @class mw.mobileFrontend
* @singleton
*/
( function ( M, $ ) {
var currentPage, skin,
PageGateway = M.require( 'mobile.startup/PageGateway' ),
gateway = new PageGateway( new mw.Api() ),
Page = M.require( 'mobile.startup/Page' ),
( function ( M ) {
var skin = M.require( 'mobile.init/skin' ),
mainMenu = M.require( 'skins.minerva.scripts.top/mainMenu' ),
toast = M.require( 'mobile.startup/toast' ),
Skin = M.require( 'mobile.startup/Skin' ),
ReferencesMobileViewGateway = M.require(
'mobile.references.gateway/ReferencesMobileViewGateway'
),
skinData = {
el: 'body',
page: getCurrentPage(),
referencesGateway: ReferencesMobileViewGateway.getSingleton()
};
toast = M.require( 'mobile.startup/toast' );
skin = new Skin( skinData );
// Proxy to MobileFrontend defined skin
M.define( 'skins.minerva.scripts/skin', skin );
/**
@ -67,93 +55,6 @@
}
}( mw.config.get( 'wgRedirectedFrom' ) ) );
/**
* Given 2 functions, it returns a function that will run both with it's
* context and parameters and return the results combined
* @private
* @param {Function} fn1
* @param {Function} fn2
* @return {Function} which returns the results of [fn1, fn2]
*/
function apply2( fn1, fn2 ) {
return function () {
return [
fn1.apply( this, arguments ),
fn2.apply( this, arguments )
];
};
}
/**
* @event resize
* The `window`'s resize event debounced at 100 ms. The `resize:throttled` event is the `window`'s
* resize event throttled to 200 ms.
*/
/**
* @event scroll
* The `window`'s scroll event debounced at 100 ms. The `scroll:throttled` event is the `window`'s
* scroll event throttled to 200 ms.
*/
$( window )
.on( 'resize', apply2(
$.debounce( 100, $.proxy( M, 'emit', 'resize' ) ),
$.throttle( 200, $.proxy( M, 'emit', 'resize:throttled' ) )
) )
.on( 'scroll', apply2(
$.debounce( 100, $.proxy( M, 'emit', 'scroll' ) ),
$.throttle( 200, $.proxy( M, 'emit', 'scroll:throttled' ) )
) );
/**
* Get current page view object
* FIXME: Move to M.define( 'page' )
* @method
* @return {Page}
*/
function getCurrentPage() {
if ( currentPage ) {
return currentPage;
} else {
return loadCurrentPage();
}
}
/**
* Constructs an incomplete Page object representing the currently loaded page.
*
* @method
* @private
* @return {Page}
* @ignore
*/
function loadCurrentPage() {
var permissions = mw.config.get( 'wgRestrictionEdit', [] ),
$content = $( '#content #bodyContent' );
if ( permissions.length === 0 ) {
permissions.push( '*' );
}
currentPage = new Page( {
el: $content,
title: mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ),
protection: {
edit: permissions
},
revId: mw.config.get( 'wgRevisionId' ),
isMainPage: mw.config.get( 'wgIsMainPage' ),
isWatched: $( '#ca-watch' ).hasClass( 'watched' ),
sections: gateway.getSectionsFromHTML( $content ),
id: mw.config.get( 'wgArticleId' ),
namespaceNumber: mw.config.get( 'wgNamespaceNumber' )
} );
return currentPage;
}
$.extend( M, {
getCurrentPage: getCurrentPage
} );
// Recruit volunteers through the console (note console.log may not be a function so check via apply)
/* eslint-disable no-console */
if ( window.console && window.console.log && window.console.log.apply &&
@ -161,4 +62,4 @@
console.log( mw.msg( 'mobile-frontend-console-recruit' ) );
}
/* eslint-enable no-console */
}( mw.mobileFrontend, jQuery ) );
}( mw.mobileFrontend ) );

View file

@ -252,6 +252,7 @@
"desktop"
],
"dependencies": [
"mobile.init",
"skins.minerva.scripts.top",
"mediawiki.util",
"mediawiki.router",