jenkins-bot has submitted this change and it was merged. Change subject: Hygiene: Refactor page.js ......................................................................
Hygiene: Refactor page.js * Rename page module to Page * Allow multiple page views to be rendered by separating the page-loaded event * Update body classes on a dynamic page load (fixes bug 54282) Change-Id: I3fea375f4583e877937b0face46289807e561e00 --- M includes/Resources.php R javascripts/common/Page.js M javascripts/common/application.js M javascripts/common/history-alpha.js M javascripts/modules/editor/EditorOverlay.js M javascripts/modules/talk/talk.js M javascripts/specials/overlays/PagePreviewOverlay.js A tests/javascripts/common/test_Page.js 8 files changed, 44 insertions(+), 12 deletions(-) Approvals: Awjrichards: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/Resources.php b/includes/Resources.php index f9cfb4a..8d6a348 100644 --- a/includes/Resources.php +++ b/includes/Resources.php @@ -502,7 +502,7 @@ 'javascripts/common/LoadingOverlay.js', 'javascripts/widgets/progress-bar.js', 'javascripts/common/notification.js', - 'javascripts/views/page.js', + 'javascripts/common/Page.js', // Upload specific code 'javascripts/modules/uploads/PhotoUploaderButton.js', // Language specific code diff --git a/javascripts/views/page.js b/javascripts/common/Page.js similarity index 93% rename from javascripts/views/page.js rename to javascripts/common/Page.js index afb7c0c..1b43f66 100644 --- a/javascripts/views/page.js +++ b/javascripts/common/Page.js @@ -32,6 +32,10 @@ lastModifiedTimestamp: ( "" + new Date().getTime() ).substr( 0,10 ) // Default to current timestamp }, + isMainPage: function() { + return this.options.isMainPage; + }, + // FIXME: This assumes only one page can be rendered at one time - emits a page-loaded event and sets wgArticleId render: function( options ) { var pageTitle = options.title, self = this, @@ -62,10 +66,7 @@ // reset loader $el.removeClass( 'loading' ); - // FIXME: Reset the page id - mw.config.set( 'wgArticleId', pageData.id ); - // FIXME: emit events so that modules can reinitialise - M.emit( 'page-loaded', self ); + self.emit( 'ready', self ); } ).fail( $.proxy( self, 'emit', 'error' ) ); } else { self._super( options ); @@ -107,7 +108,7 @@ } } ); - M.define( 'page', Page ); + M.define( 'Page', Page ); M.define( 'Section', Section ); }( mw.mobileFrontend, jQuery ) ); diff --git a/javascripts/common/application.js b/javascripts/common/application.js index a3066db..8076704 100644 --- a/javascripts/common/application.js +++ b/javascripts/common/application.js @@ -251,6 +251,23 @@ return params; } + /** + * Sets the JavaScript configuration and HTML environment for a given page + * Emits a page-loaded event that modules can subscribe to, so that they can + * re-initialize + * + */ + function reloadPage( page ) { + if ( page.isMainPage() ) { + $( 'body' ).addClass( 'page-Main_Page' ); + } else { + $( 'body' ).removeClass( 'page-Main_Page' ); + } + + mw.config.set( 'wgArticleId', page.id ); + M.emit( 'page-loaded', page ); + } + $( init ); $.extend( M, { @@ -265,6 +282,7 @@ isLoggedIn: isLoggedIn, lockViewport: lockViewport, log: log, + reloadPage: reloadPage, supportsGeoLocation: supportsGeoLocation, supportsPositionFixed: supportsPositionFixed, prettyEncodeTitle: prettyEncodeTitle, diff --git a/javascripts/common/history-alpha.js b/javascripts/common/history-alpha.js index dff36d4..65924b0 100644 --- a/javascripts/common/history-alpha.js +++ b/javascripts/common/history-alpha.js @@ -2,7 +2,7 @@ M.assertMode( [ 'alpha' ] ); var - Page = M.require( 'page' ), + Page = M.require( 'Page' ), isSpecialPage = mw.config.get( 'wgNamespaceNumber' ) === mw.config.get( 'wgNamespaceIds' ).special, History = window.History; @@ -33,7 +33,7 @@ var s = History.getState(); new Page( { title: s.title, el: $( '#content_wrapper' ) } ).on( 'error', function() { window.location.reload(); // the page either doesn't exist or was a Special:Page so force a refresh - } ); + } ).on( 'ready', M.reloadPage ); } ); /** diff --git a/javascripts/modules/editor/EditorOverlay.js b/javascripts/modules/editor/EditorOverlay.js index 6b0b3b6..26641b8 100644 --- a/javascripts/modules/editor/EditorOverlay.js +++ b/javascripts/modules/editor/EditorOverlay.js @@ -1,7 +1,7 @@ ( function( M, $ ) { var Overlay = M.require( 'Overlay' ), - Page = M.require( 'page' ), + Page = M.require( 'Page' ), popup = M.require( 'notifications' ), api = M.require( 'api' ), Section = M.require( 'Section' ), @@ -209,7 +209,7 @@ // log success! self.log( 'success' ); M.pageApi.invalidatePage( title ); - new Page( { title: title, el: $( '#content_wrapper' ) } ); + new Page( { title: title, el: $( '#content_wrapper' ) } ).on( 'ready', M.reloadPage ); M.router.navigate( '' ); self.hide(); if ( M.isTestA && self.isNewEditor ) { diff --git a/javascripts/modules/talk/talk.js b/javascripts/modules/talk/talk.js index 230c3c8..c2e9811 100644 --- a/javascripts/modules/talk/talk.js +++ b/javascripts/modules/talk/talk.js @@ -2,7 +2,7 @@ M.assertMode( [ 'beta', 'alpha' ] ); var LoadingOverlay = M.require( 'LoadingOverlay' ), - Page = M.require( 'page' ), + Page = M.require( 'Page' ), loadingOverlay = new LoadingOverlay(); function renderTalkOverlay( pageData ) { diff --git a/javascripts/specials/overlays/PagePreviewOverlay.js b/javascripts/specials/overlays/PagePreviewOverlay.js index 57a5050..e22b768 100644 --- a/javascripts/specials/overlays/PagePreviewOverlay.js +++ b/javascripts/specials/overlays/PagePreviewOverlay.js @@ -3,7 +3,7 @@ var Overlay = M.require( 'Overlay' ), ua = window.navigator.userAgent, device = 'unknown', - Page = M.require( 'page' ), + Page = M.require( 'Page' ), LoadingOverlay = M.require( 'LoadingOverlay' ), PagePreviewOverlay = Overlay.extend( { template: M.template.get( 'overlays/pagePreview' ), diff --git a/tests/javascripts/common/test_Page.js b/tests/javascripts/common/test_Page.js new file mode 100644 index 0000000..9c0dee4 --- /dev/null +++ b/tests/javascripts/common/test_Page.js @@ -0,0 +1,13 @@ +( function( M ) { + var Page = M.require( 'Page' ); + + QUnit.module( 'MobileFrontend Page' ); + + QUnit.test( '#isMainPage', 2, function( assert ) { + var p = new Page( { title: 'Main Page', isMainPage: true } ), + p2 = new Page( { title: 'Foo' } ); + assert.strictEqual( p.isMainPage(), true, 'check main page flag is updated' ); + assert.strictEqual( p2.isMainPage(), false, 'check not marked as main page' ); + } ); + +}( mw.mobileFrontend ) ); -- To view, visit https://gerrit.wikimedia.org/r/85141 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I3fea375f4583e877937b0face46289807e561e00 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Awjrichards <aricha...@wikimedia.org> Gerrit-Reviewer: JGonera <jgon...@wikimedia.org> Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits