Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/182289

Change subject: Hygiene: Introduce Skin.js
......................................................................

Hygiene: Introduce Skin.js

Move loadWideScreenModule there

Change-Id: Ib64b35fc254a9232cd7b9bb0c83e97dc4826e7b5
---
M includes/Resources.php
A javascripts/Skin.js
M javascripts/application.js
3 files changed, 68 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/89/182289/1

diff --git a/includes/Resources.php b/includes/Resources.php
index 0e31486..273113a 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -233,6 +233,7 @@
                        'javascripts/Panel.js',
                        'javascripts/Section.js',
                        'javascripts/Page.js',
+                       'javascripts/Skin.js',
                        'javascripts/Schema.js',
                        'javascripts/util.js',
                        'javascripts/application.js',
diff --git a/javascripts/Skin.js b/javascripts/Skin.js
new file mode 100644
index 0000000..deac7a5
--- /dev/null
+++ b/javascripts/Skin.js
@@ -0,0 +1,60 @@
+( function ( M, $ ) {
+
+       var Skin,
+               browser = M.require( 'browser' ),
+               View = M.require( 'View' );
+
+       /**
+        * Mobile page view object
+        *
+        * @class Page
+        * @uses Section
+        * @extends View
+        */
+       Skin = View.extend( {
+               /**
+                * @cfg {Object} defaults Default options hash.
+                * @cfg {Page} options.page page the skin is currently rendering
+                * @cfg {array} options.tabletModules modules to load when in 
tablet
+                */
+               defaults: {
+                       page: undefined,
+                       tabletModules: []
+               },
+
+               /**
+                * @inheritdoc
+                */
+               initialize: function ( options ) {
+                       var self = this;
+
+                       this.page = options.page;
+                       this.name = options.name;
+                       this.tabletModules = options.tabletModules;
+                       View.prototype.initialize.apply( this, arguments );
+
+                       /**
+                        * Tests current window size and if suitable loads 
styles and scripts specific for larger devices
+                        *
+                        * @method
+                        * @ignore
+                        */
+                       function loadWideScreenModules() {
+                               if ( browser.isWideScreen() ) {
+                                       // Adjust screen for tablets
+                                       if ( self.page.inNamespace( '' ) ) {
+                                               mw.loader.using( 
self.tabletModules ).always( function () {
+                                                       self.off( '_resize' );
+                                               } );
+                                       }
+                               }
+                       }
+                       M.on( 'resize', $.proxy( this, 'emit', '_resize' ) );
+                       this.on( '_resize', loadWideScreenModules );
+                       this.emit( '_resize' );
+               }
+       } );
+
+       M.define( 'Skin', Skin );
+
+}( mw.mobileFrontend, jQuery ) );
diff --git a/javascripts/application.js b/javascripts/application.js
index 9a12f26..6066ae2 100644
--- a/javascripts/application.js
+++ b/javascripts/application.js
@@ -6,41 +6,19 @@
  * @singleton
  */
 ( function ( M, $ ) {
-       var Router = M.require( 'Router' ),
+       var currentPage, skin,
+               Router = M.require( 'Router' ),
                browser = M.require( 'browser' ),
                OverlayManager = M.require( 'OverlayManager' ),
                PageApi = M.require( 'PageApi' ),
                pageApi = new PageApi(),
                Page = M.require( 'Page' ),
                router = new Router(),
-               currentPage,
-               inWideScreenMode = false,
+               Skin = M.require( 'Skin' ),
                // FIXME: Move all the variables below to Browser.js
                ua = window.navigator.userAgent,
                isIos = browser.isIos(),
                isOldIPhone = isIos && /OS [4]_[0-2]|OS [3]_/.test( ua );
-
-       /**
-        * Tests current window size and if suitable loads styles and scripts 
specific for larger devices
-        * FIXME: Separate from application.js
-        *
-        * @method
-        * @param {Page} page
-        */
-       function loadWideScreenModules( page ) {
-               var modules = [];
-               if ( !inWideScreenMode && browser.isWideScreen() &&
-                       mw.config.get( 'skin' ) === 'minerva' ) {
-                       // Adjust screen for tablets
-                       if ( page.inNamespace( '' ) ) {
-                               modules.push( 'tablet.scripts' );
-                       }
-                       inWideScreenMode = true;
-                       mw.loader.using( modules, function () {
-                               M.emit( 'resize' );
-                       } );
-               }
-       }
 
        /**
         * Initialize viewport
@@ -90,9 +68,11 @@
                        } );
                }
 
-               loadWideScreenModules( getCurrentPage() );
+               skin = new Skin( {
+                       tabletModules: mw.config.get( 'skin' ) === 'minerva' ? 
[ 'tablet.scripts' ] : [],
+                       page: getCurrentPage()
+               } );
                $( window ).on( 'resize', $.proxy( M, 'emit', 'resize' ) );
-               M.on( 'resize', loadWideScreenModules );
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/182289
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib64b35fc254a9232cd7b9bb0c83e97dc4826e7b5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to