jenkins-bot has submitted this change and it was merged.

Change subject: mw.ViewPageTarget: Clean up transform/restore logic
......................................................................


mw.ViewPageTarget: Clean up transform/restore logic

Merge methods:
* transformPage: transformSkinTabs + hideSiteNotice
* restorePage: restoreSkinTabs + restoreSiteNotice

Callers now consistently do both (e.g. #tearDownSurface only
called #restoreSkinTabs). This is also in preparation for
bug 43844.

Removed call from #tearDownSurface as that method is only
called from #deactivate which already calls #restorePage.

Clean up support check:
* Rename supportsStrictMode to supportsES5. Though the feature
  test asserts strict mode, we use it to check support for
  ES5. VisualEditor doesn't particularily care about strict
  mode itself.
* Reverse support if-statemement to return early instead of
  wrapping everything that follows. This makes it easier to
  see that we intent to abort if the current environment is
  known to be problematic. Also easier for code later on
  by not accidentally falling outside this block
* Follows-up aaa5ad254be12aa69.

Change-Id: Ia4b949d9c066a3f7b07217aa3d51de9908734e85
---
M modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js
1 file changed, 52 insertions(+), 57 deletions(-)

Approvals:
  Trevor Parscal: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js 
b/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js
index 8422f23..e41b96d 100644
--- a/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js
@@ -19,7 +19,7 @@
        var browserWhitelisted,
                browserBlacklisted,
                currentUri = new mw.Uri( window.location.toString() ),
-               supportsStrictMode = ( function () {
+               supportsES5 = ( function () {
                        'use strict';
                        return this === undefined;
                }() ),
@@ -100,35 +100,40 @@
                'serializeError': 'onSerializeError'
        } );
 
-       // Initialization
-       if ( supportsStrictMode && supportsContentEditable && 
!browserBlacklisted ) {
-               if ( !browserWhitelisted ) {
-                       // show warning
-                       this.localNoticeMessages.push( 
'visualeditor-browserwarning' );
+       if ( !supportsES5 || !supportsContentEditable || browserBlacklisted ) {
+               // Don't initialise in browsers that are broken
+               return;
+       }
+
+       if ( !browserWhitelisted ) {
+               // Show warning in unknown browsers that pass the support test
+               // Continue at own risk.
+               this.localNoticeMessages.push( 'visualeditor-browserwarning' );
+       }
+
+       if ( currentUri.query.venotify ) {
+               // The following messages can be used here:
+               // visualeditor-notification-saved
+               // visualeditor-notification-created
+               // visualeditor-notification-restored
+               mw.notify(
+                       ve.msg( 'visualeditor-notification-' + 
currentUri.query.venotify,
+                               new mw.Title( this.pageName ).toText()
+                       )
+               );
+               if ( window.history.replaceState ) {
+                       delete currentUri.query.venotify;
+                       window.history.replaceState( null, document.title, 
currentUri );
                }
-               if ( currentUri.query.venotify ) {
-                       // The following messages can be used here:
-                       // visualeditor-notification-saved
-                       // visualeditor-notification-created
-                       // visualeditor-notification-restored
-                       mw.notify(
-                               ve.msg( 'visualeditor-notification-' + 
currentUri.query.venotify,
-                                       new mw.Title( this.pageName ).toText()
-                               )
-                       );
-                       if ( window.history.replaceState ) {
-                               delete currentUri.query.venotify;
-                               window.history.replaceState( null, 
document.title, currentUri );
-                       }
-               }
-               this.setupSkinTabs();
-               if ( mw.config.get( 'wgVisualEditorConfig' 
).enableSectionEditLinks ) {
-                       this.setupSectionEditLinks();
-               }
-               if ( this.isViewPage ) {
-                       if ( currentUri.query.veaction === 'edit' ) {
-                               this.activate();
-                       }
+       }
+
+       this.setupSkinTabs();
+       if ( mw.config.get( 'wgVisualEditorConfig' ).enableSectionEditLinks ) {
+               this.setupSectionEditLinks();
+       }
+       if ( this.isViewPage ) {
+               if ( currentUri.query.veaction === 'edit' ) {
+                       this.activate();
                }
        }
 };
@@ -256,9 +261,9 @@
 ve.init.mw.ViewPageTarget.prototype.activate = function () {
        if ( !this.active && !this.activating ) {
                this.activating = true;
+
                // User interface changes
-               this.transformSkinTabs();
-               this.hideSiteNotice();
+               this.transformPage();
                this.showSpinner();
                this.hideTableOfContents();
                this.mutePageContent();
@@ -282,8 +287,7 @@
                ) {
                        this.deactivating = true;
                        // User interface changes
-                       this.restoreSkinTabs();
-                       this.restoreSiteNotice();
+                       this.restorePage();
                        this.hideSpinner();
 
                        if ( this.toolbarCancelButton ) {
@@ -806,8 +810,6 @@
  * @method
  */
 ve.init.mw.ViewPageTarget.prototype.tearDownSurface = function () {
-       // Reset tabs
-       this.restoreSkinTabs();
        // Update UI
        if ( this.$document ) {
                this.$document.blur();
@@ -1613,45 +1615,38 @@
 };
 
 /**
- * Modify page tabs to show that editing is taking place.
+ * Page modifications for switching to edit mode.
  *
  * @method
  */
-ve.init.mw.ViewPageTarget.prototype.transformSkinTabs = function () {
+ve.init.mw.ViewPageTarget.prototype.transformPage = function () {
+
+       // Put skin tabs in "edit" mode
        $( $( '#p-views' ).length ? '#p-views' : '#p-cactions' )
                .find( 'li.selected' ).removeClass( 'selected' );
        $( this.tabLayout === 'add' ? '#ca-ve-edit' : '#ca-edit' )
                .addClass( 'selected' );
-};
 
-/**
- * Modify page tabs to show that viewing is taking place.
- *
- * @method
- */
-ve.init.mw.ViewPageTarget.prototype.restoreSkinTabs = function () {
-       $( $( '#p-views' ).length ? '#p-views' : '#p-cactions' )
-               .find( 'li.selected' ).removeClass( 'selected' );
-       $( '#ca-view' ).addClass( 'selected' );
-};
-
-/**
- * Hide site notice on page if present.
- *
- * @method
- */
-ve.init.mw.ViewPageTarget.prototype.hideSiteNotice = function () {
+       // Hide site notice (if present)
        $( '#siteNotice:visible' )
                .addClass( 've-hide' )
                .slideUp( 'fast' );
 };
 
 /**
- * Show site notice on page if present.
+ * Page modifications for switching back to view mode.
  *
  * @method
  */
-ve.init.mw.ViewPageTarget.prototype.restoreSiteNotice = function () {
+ve.init.mw.ViewPageTarget.prototype.restorePage = function () {
+
+       // Put skin tabs back in "view" mode
+       $( $( '#p-views' ).length ? '#p-views' : '#p-cactions' )
+               .find( 'li.selected' ).removeClass( 'selected' );
+       $( '#ca-view' ).addClass( 'selected' );
+
+
+       // Make site notice visible again (if present)
        $(' #siteNotice.ve-hide' )
                .slideDown( 'fast' );
 };

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia4b949d9c066a3f7b07217aa3d51de9908734e85
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to