jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/340320 )

Change subject: Use new editor switcher widget from VE
......................................................................


Use new editor switcher widget from VE

Depends-On: Iadf5a81e2733ab81fe25c686dcd6dad8eac3885c
Change-Id: Iccddc7da38e845ffdd1ee74b3b43e39baafbf3a8
---
M resources/mobile.editor.common/EditorOverlayBase.js
M resources/mobile.editor.common/editor.less
M resources/mobile.editor.overlay/EditorOverlay.js
3 files changed, 41 insertions(+), 44 deletions(-)

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



diff --git a/resources/mobile.editor.common/EditorOverlayBase.js 
b/resources/mobile.editor.common/EditorOverlayBase.js
index cb94bef..7b059d0 100644
--- a/resources/mobile.editor.common/EditorOverlayBase.js
+++ b/resources/mobile.editor.common/EditorOverlayBase.js
@@ -305,33 +305,6 @@
                        this[this.nextStep]();
                },
                /**
-                * Set up the editor switching interface
-                * The actual behavior of the editor buttons is initialized in 
postRender()
-                * @method
-                */
-               initializeSwitcher: function () {
-                       var toolFactory = new OO.ui.ToolFactory(),
-                               toolGroupFactory = new OO.ui.ToolGroupFactory(),
-                               toolbar;
-
-                       toolbar = new OO.ui.Toolbar( toolFactory, 
toolGroupFactory, {
-                               classes: [ 'editor-switcher' ]
-                       } );
-                       toolFactory.register( EditVeTool );
-
-                       toolbar.setup( [
-                               {
-                                       icon: 'advanced',
-                                       indicator: 'down',
-                                       type: 'list',
-                                       include: [ { group: 'editorSwitcher' } ]
-                               }
-                       ] );
-
-                       this.$el.find( '.switcher-container' ).html( 
toolbar.$element );
-                       this.switcherToolbar = toolbar;
-               },
-               /**
                 * @inheritdoc
                 */
                hide: function () {
diff --git a/resources/mobile.editor.common/editor.less 
b/resources/mobile.editor.common/editor.less
index 8134170..e1c39f4 100644
--- a/resources/mobile.editor.common/editor.less
+++ b/resources/mobile.editor.common/editor.less
@@ -36,12 +36,17 @@
        }
 
        .editor-switcher {
+               border-left: 1px solid #ddd;
                .oo-ui-toolbar-bar {
                        font-size: unit( 0.8 * @targetIconSize / @baseIconSize, 
em );
                        border-collapse: separate;
                        border: 0;
                        box-shadow: none;
                }
+               .oo-ui-toolGroup {
+                       display: block;
+                       height: 3.14em;
+               }
        }
 }
 
diff --git a/resources/mobile.editor.overlay/EditorOverlay.js 
b/resources/mobile.editor.overlay/EditorOverlay.js
index 79ee250..c13f96b 100644
--- a/resources/mobile.editor.overlay/EditorOverlay.js
+++ b/resources/mobile.editor.overlay/EditorOverlay.js
@@ -133,23 +133,43 @@
                        var self = this;
 
                        if ( this.isVisualEditorEnabled() ) {
-                               this.initializeSwitcher();
-                               /**
-                                * 'Edit' button handler
-                                */
-                               this.switcherToolbar.tools.editVe.onSelect = 
function () {
-                                       // 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 ( !self.gateway.hasChanged ) {
-                                               self._switchToVisualEditor( 
self.options );
-                                       } else {
-                                               if ( window.confirm( mw.msg( 
'mobile-frontend-editor-switch-confirm' ) ) ) {
-                                                       self.onStageChanges();
-                                               } else {
-                                                       
self.switcherToolbar.tools.editVe.setActive( false );
+                               mw.loader.using( 'ext.visualEditor.switching' 
).then( function () {
+                                       var switchToolbar,
+                                               toolFactory = new 
OO.ui.ToolFactory(),
+                                               toolGroupFactory = new 
OO.ui.ToolGroupFactory();
+
+                                       toolFactory.register( 
mw.libs.ve.MWEditModeVisualTool );
+                                       toolFactory.register( 
mw.libs.ve.MWEditModeSourceTool );
+                                       switchToolbar = new OO.ui.Toolbar( 
toolFactory, toolGroupFactory, {
+                                               classes: [ 'editor-switcher' ]
+                                       } );
+
+                                       switchToolbar.on( 'switchEditor', 
function ( mode ) {
+                                               if ( mode === 'visual' ) {
+                                                       // 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 ( 
!self.gateway.hasChanged ) {
+                                                               
self._switchToVisualEditor( self.options );
+                                                       } else {
+                                                               if ( 
window.confirm( mw.msg( 'mobile-frontend-editor-switch-confirm' ) ) ) {
+                                                                       
self.onStageChanges();
+                                                               }
+                                                       }
                                                }
-                                       }
-                               };
+                                       } );
+
+                                       switchToolbar.setup( [
+                                               {
+                                                       type: 'list',
+                                                       icon: 'edit',
+                                                       title: mw.msg( 
'visualeditor-mweditmode-tooltip' ),
+                                                       include: [ 
'editModeVisual', 'editModeSource' ]
+                                               }
+                                       ] );
+
+                                       self.$el.find( '.switcher-container' 
).html( switchToolbar.$element );
+                                       switchToolbar.emit( 'updateState' );
+                               } );
                        }
 
                        EditorOverlayBase.prototype.postRender.apply( this );
@@ -385,7 +405,6 @@
                                function () {
                                        self.clearSpinner();
                                        self.$content.show();
-                                       
self.switcherToolbar.tools.editVe.setActive( false );
                                        // FIXME: We should show an error 
notification, but right now toast
                                        // notifications are not dismissible 
when shown within the editor.
                                }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iccddc7da38e845ffdd1ee74b3b43e39baafbf3a8
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to