diff --git a/resources/skins.minerva.scripts/preInit.js b/resources/skins.minerva.scripts/preInit.js index 645ec01..b7f83c6 100644 --- a/resources/skins.minerva.scripts/preInit.js +++ b/resources/skins.minerva.scripts/preInit.js @@ -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 ) ); diff --git a/skin.json b/skin.json index 372c9bb..b8dba5a 100644 --- a/skin.json +++ b/skin.json @@ -252,6 +252,7 @@ "desktop" ], "dependencies": [ + "mobile.init", "skins.minerva.scripts.top", "mediawiki.util", "mediawiki.router",