Jdlrobson has uploaded a new change for review.

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

Change subject: Hygiene: Refactor complicate variables into functions
......................................................................

Hygiene: Refactor complicate variables into functions

Change-Id: I48b1d8a269d87f9a20129ab10b6c4edbf444d41d
---
M javascripts/modules/editor/EditorOverlay.js
M javascripts/modules/tutorials/init.js
2 files changed, 30 insertions(+), 18 deletions(-)


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

diff --git a/javascripts/modules/editor/EditorOverlay.js 
b/javascripts/modules/editor/EditorOverlay.js
index 8764813..6e7a4ba 100644
--- a/javascripts/modules/editor/EditorOverlay.js
+++ b/javascripts/modules/editor/EditorOverlay.js
@@ -1,10 +1,5 @@
 ( function ( M, $ ) {
        var EditorOverlayBase = M.require( 'modules/editor/EditorOverlayBase' ),
-               isVisualEditorEnabled = M.isWideScreen() &&
-                       mw.config.get( 'wgVisualEditorConfig' ) &&
-                       $.inArray( mw.config.get( 'wgNamespaceNumber' ), 
mw.config.get( 'wgVisualEditorConfig' ).namespaces ) > -1 &&
-                       mw.config.get( 'wgTranslatePageTranslation' ) !== 
'translation' &&
-                       mw.config.get( 'wgPageContentModel' ) === 'wikitext',
                Section = M.require( 'Section' ),
                EditorApi = M.require( 'modules/editor/EditorApi' ),
                AbuseFilterPanel = M.require( 'modules/editor/AbuseFilterPanel' 
),
@@ -29,6 +24,19 @@
                editor: 'SourceEditor',
                sectionLine: '',
 
+               /*
+                * Check whether VisualEditor is enabled or not.
+                * @method
+                * @return boolean
+                */
+               isVisualEditorEnabled: function () {
+                       return M.isWideScreen() &&
+                               mw.config.get( 'wgVisualEditorConfig' ) &&
+                               $.inArray( mw.config.get( 'wgNamespaceNumber' 
), mw.config.get( 'wgVisualEditorConfig' ).namespaces ) > -1 &&
+                               mw.config.get( 'wgTranslatePageTranslation' ) 
!== 'translation' &&
+                               mw.config.get( 'wgPageContentModel' ) === 
'wikitext';
+               },
+
                initialize: function ( options ) {
                        this.api = new EditorApi( {
                                title: options.title,
@@ -37,7 +45,7 @@
                                isNewPage: options.isNewPage
                        } );
                        this.readOnly = options.oldId ? true : false; // If old 
revision, readOnly mode
-                       if ( isVisualEditorEnabled ) {
+                       if ( this.isVisualEditorEnabled() ) {
                                options.editSwitcher = true;
                        }
                        if ( this.readOnly ) {
@@ -49,7 +57,7 @@
                        // be explicit here. This may have been initialized 
from VE.
                        options.isVisualEditor = false;
                        EditorOverlayBase.prototype.initialize.apply( this, 
arguments );
-                       if ( isVisualEditorEnabled ) {
+                       if ( this.isVisualEditorEnabled() ) {
                                this.initializeSwitcher();
                        }
                },
@@ -77,7 +85,7 @@
 
                        // If the user tries to switch to the VisualEditor, 
check if any changes have
                        // been made, and if so, tell the user they have to 
save first.
-                       if ( isVisualEditorEnabled ) {
+                       if ( this.isVisualEditorEnabled() ) {
                                this.$( '.visual-editor' ).on( 'click', 
function () {
                                        if ( !self.api.hasChanged ) {
                                                self._switchToVisualEditor( 
options );
diff --git a/javascripts/modules/tutorials/init.js 
b/javascripts/modules/tutorials/init.js
index 11ead6f..cbb525b 100644
--- a/javascripts/modules/tutorials/init.js
+++ b/javascripts/modules/tutorials/init.js
@@ -15,15 +15,19 @@
                escapeHash = M.escapeHash,
                inEditor = window.location.hash.indexOf( '#editor/' ) > -1,
                hash = window.location.hash,
-               // Whether or not the user should see the leftNav guider
-               shouldShowLeftNavEditTutorial =
-                       M.query.campaign === 'leftNavSignup' &&
-                       mw.config.get( 'wgNamespaceNumber' ) === 0 &&
-                       !inEditor,
-               // If the user came from an edit button signup, show guider.
-               shouldShowEditTutorial = M.query.article_action === 
'signup-edit' && !inEditor,
-               showTutorial = shouldShowEditTutorial || 
shouldShowLeftNavEditTutorial,
                editOverlay, target, $target, href;
+
+       // Whether or not the user should see the leftNav guider
+       function shouldShowLeftNavEditTutorial() {
+               return M.query.campaign === 'leftNavSignup' &&
+                       mw.config.get( 'wgNamespaceNumber' ) === 0 && !inEditor;
+       }
+
+       // If the user came from an edit button signup, show guider.
+       function showShowTutorial() {
+               var shouldShowEditTutorial = M.query.article_action === 
'signup-edit' && !inEditor;
+               return shouldShowEditTutorial || 
shouldShowLeftNavEditTutorial();
+       }
 
        if ( hash && hash.indexOf( '/' ) === -1 ) {
                target = escapeHash( hash ) + ' ~ .edit-page';
@@ -32,9 +36,9 @@
        }
 
        // Note the element might have a new ID if the wikitext was changed so 
check it exists
-       if ( $( target ).length > 0 && showTutorial ) {
+       if ( $( target ).length > 0 && showShowTutorial() ) {
 
-               if ( shouldShowLeftNavEditTutorial ) {
+               if ( shouldShowLeftNavEditTutorial() ) {
                        // Append the funnel name to the edit link's url
                        $target = $( target );
                        href = $target.attr( 'href' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I48b1d8a269d87f9a20129ab10b6c4edbf444d41d
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