Esanders has uploaded a new change for review.

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

Change subject: Update toolbar setup methods
......................................................................

Update toolbar setup methods

Detachable toolbars in core Ic999ec1 are setup in a different order.

Change-Id: I29156948711d55ba5f6dd4f6c35ca0e4cca32373
---
M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
M modules/ve-mw/init/ve.init.mw.Target.js
2 files changed, 28 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/31/177131/1

diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js 
b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
index 73bdb34..2321d8c 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
@@ -184,10 +184,10 @@
 /**
  * @inheritdoc
  */
-ve.init.mw.ViewPageTarget.prototype.setupToolbar = function () {
+ve.init.mw.ViewPageTarget.prototype.setupToolbar = function ( surface ) {
        var $firstHeading;
        // Parent method
-       ve.init.mw.Target.prototype.setupToolbar.call( this );
+       ve.init.mw.Target.prototype.setupToolbar.call( this, surface );
 
        // Keep it hidden so that we can slide it down smoothly (avoids sudden
        // offset flash when original content is hidden, and replaced in-place 
with a
@@ -196,22 +196,22 @@
        // to target (visibly), only for us to hide it again 0ms later.
        // Though we can't hide it by default because it needs visible 
dimensions
        // to compute stuff during setup.
-       this.toolbar.$bar.hide();
+       this.getToolbar().$bar.hide();
 
-       this.toolbar.enableFloatable();
-       this.toolbar.$element
+       this.getToolbar().enableFloatable();
+       this.getToolbar().$element
                .addClass( 've-init-mw-viewPageTarget-toolbar' );
 
        // Move the toolbar to before #firstHeading if it exists
        $firstHeading = $( '#firstHeading' );
        if ( $firstHeading.length ) {
-               this.toolbar.$element.insertBefore( $firstHeading );
+               this.getToolbar().$element.insertBefore( $firstHeading );
        }
 
-       this.toolbar.$bar.slideDown( 'fast', function () {
+       this.getToolbar().$bar.slideDown( 'fast', function () {
                // Check the surface wasn't torn down while the toolbar was 
animating
                if ( this.getSurface() ) {
-                       this.toolbar.initialize();
+                       this.getToolbar().initialize();
                        this.getSurface().getView().emit( 'position' );
                        this.getSurface().getContext().updateDimensions();
                }
@@ -338,7 +338,7 @@
                // button property (bug 46456)
                this.toolbarSaveButton.disconnect( this );
                this.toolbarSaveButton.$element.detach();
-               this.toolbar.$actions.empty();
+               this.getToolbar().$actions.empty();
        }
 
        // Check we got as far as setting up the surface
@@ -1087,7 +1087,7 @@
 ve.init.mw.ViewPageTarget.prototype.attachToolbarSaveButton = function () {
        var $actionTools = $( '<div>' ),
                $pushButtons = $( '<div>' ),
-               actions = new ve.ui.TargetToolbar( this, this.getSurface() );
+               actions = new ve.ui.TargetToolbar( this );
 
        actions.setup( [
                { include: [ 'help', 'notices' ] },
@@ -1097,7 +1097,7 @@
                        title: ve.msg( 'visualeditor-pagemenu-tooltip' ),
                        include: [ 'meta', 'settings', 'advancedSettings', 
'categories', 'languages', 'editModeSource' ]
                }
-       ] );
+       ], this.getSurface() );
 
        $actionTools
                .addClass( 've-init-mw-viewPageTarget-toolbar-utilities' )
diff --git a/modules/ve-mw/init/ve.init.mw.Target.js 
b/modules/ve-mw/init/ve.init.mw.Target.js
index 06e1644..b6223ae 100644
--- a/modules/ve-mw/init/ve.init.mw.Target.js
+++ b/modules/ve-mw/init/ve.init.mw.Target.js
@@ -20,10 +20,10 @@
  *  revision id here. Defaults to loading the latest version (see #load).
  */
 ve.init.mw.Target = function VeInitMwTarget( $container, pageName, revisionId 
) {
-       var conf = mw.config.get( 'wgVisualEditorConfig' );
-
        // Parent constructor
-       ve.init.Target.call( this, $container );
+       ve.init.Target.call( this, $container, { shadow: true, actions: true } 
);
+
+       var conf = mw.config.get( 'wgVisualEditorConfig' );
 
        // Properties
        this.pageName = pageName;
@@ -1372,16 +1372,18 @@
                setTimeout( function () {
                        // Create ui.Surface (also creates ce.Surface and 
dm.Surface and builds CE tree)
                        var surface = target.addSurface( dmDoc );
-                       surface.$element.addClass( 
've-init-mw-viewPageTarget-surface' )
-                               .addClass( target.protectedClasses );
+                       surface.$element
+                               .addClass( 've-init-mw-viewPageTarget-surface' )
+                               .addClass( target.protectedClasses )
+                               .appendTo( target.$element );
+                       target.setSurface( surface );
+
                        setTimeout( function () {
                                var surfaceView = surface.getView(),
                                        $documentNode = 
surfaceView.getDocument().getDocumentNode().$element;
 
                                // Initialize surface
                                surface.getContext().toggle( false );
-                               target.$element.append( surface.$element );
-                               target.setupToolbar();
 
                                // Apply mw-body-content to the view 
(ve-ce-surface).
                                // Not to surface (ve-ui-surface), since that 
contains both the view
@@ -1403,14 +1405,6 @@
 };
 
 /**
- * @inheritdoc
- */
-ve.init.mw.Target.prototype.setupToolbar = function () {
-       // Parent method
-       ve.init.Target.prototype.setupToolbar.call( this, { shadow: true, 
actions: true } );
-};
-
-/**
  * Fire off the sanity check. Must be called before the surface is activated.
  *
  * To access the result, check whether #sanityCheckPromise has been resolved 
or rejected
@@ -1423,14 +1417,14 @@
        // We have to get a copy of the data now, before we unlock the surface 
and let the user edit,
        // but we can defer the actual conversion and comparison
        var target = this,
-               doc = target.surface.getModel().getDocument(),
+               doc = this.getSurface().getModel().getDocument(),
                data = new ve.dm.FlatLinearData( doc.getStore().clone(), 
ve.copy( doc.getFullData() ) ),
-               oldDom = target.doc,
+               oldDom = this.doc,
                d = $.Deferred();
 
        // Reset
-       target.sanityCheckFinished = false;
-       target.sanityCheckVerified = false;
+       this.sanityCheckFinished = false;
+       this.sanityCheckVerified = false;
 
        setTimeout( function () {
                // We can't compare oldDom.body and newDom.body directly, 
because the attributes on the
@@ -1457,7 +1451,7 @@
                d.resolve();
        } );
 
-       target.sanityCheckPromise = d.promise()
+       this.sanityCheckPromise = d.promise()
                .done( function () {
                        // If we detect no roundtrip errors,
                        // don't emphasize "review changes" to the user.
@@ -1505,7 +1499,7 @@
        var nextNode, offset,
                target = this,
                offsetNode = headingNode,
-               surfaceModel = this.surface.getView().getModel(),
+               surfaceModel = this.getSurface().getView().getModel(),
                lastHeadingLevel = -1;
 
        // Find next sibling which isn't a heading
@@ -1523,7 +1517,7 @@
        );
        // onDocumentFocus is debounced, so wait for that to happen before 
setting
        // the model selection, otherwise it will get reset
-       this.surface.getView().once( 'focus', function () {
+       this.getSurface().getView().once( 'focus', function () {
                surfaceModel.setLinearSelection( new ve.Range( offset ) );
                target.scrollToHeading( headingNode );
        } );
@@ -1538,5 +1532,5 @@
 ve.init.mw.Target.prototype.scrollToHeading = function ( headingNode ) {
        var $window = $( OO.ui.Element.getWindow( this.$element ) );
 
-       $window.scrollTop( headingNode.$element.offset().top - 
this.toolbar.$element.height() );
+       $window.scrollTop( headingNode.$element.offset().top - 
this.getToolbar().$element.height() );
 };

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I29156948711d55ba5f6dd4f6c35ca0e4cca32373
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

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

Reply via email to