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

Change subject: Cleanup elements passed to MWImageNode mixin
......................................................................


Cleanup elements passed to MWImageNode mixin

Change-Id: Idc736bca6ec7f9cae18d065303364ff5b7828a3b
---
M modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js
M modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js
M modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js
3 files changed, 28 insertions(+), 20 deletions(-)

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



diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js 
b/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js
index ea966ee..281579e 100644
--- a/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js
@@ -17,7 +17,7 @@
  * @param {Object} [config] Configuration options
  */
 ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode() {
-       var type, isError;
+       var type, isError, $image;
 
        // Parent constructor
        ve.ce.MWBlockImageNode.super.apply( this, arguments );
@@ -35,19 +35,20 @@
        //       <img> this.$image
        //     <figcaption> this.caption.view.$element
 
-       // Build DOM:
-       this.$image = $( '<img>' )
-               .attr( 'src', this.getResolvedAttribute( 'src' ) );
 
+       // Build DOM:
        if ( isError ) {
+               $image = $( [] );
                this.$a = $( '<a>' )
                        .addClass( 'new' )
                        .text( this.model.getFilename() );
        } else {
+               $image = $( '<img>' )
+                       .attr( 'src', this.getResolvedAttribute( 'src' ) );
                this.$a = $( '<a>' )
                        .addClass( 'image' )
                        .attr( 'href', this.getResolvedAttribute( 'href' ) )
-                       .append( this.$image );
+                       .append( $image );
        }
 
        this.$element
@@ -63,12 +64,12 @@
                // type. The model deals with converting it
                .attr( 'typeof', this.typeToRdfa[ type ] );
 
+       // Mixin constructors
+       ve.ce.MWImageNode.call( this, this.$element, $image );
+
        this.updateCaption();
 
        this.updateSize();
-
-       // Mixin constructors
-       ve.ce.MWImageNode.call( this, this.$element, this.$image );
 };
 
 /* Inheritance */
@@ -265,6 +266,9 @@
  * @inheritdoc
  */
 ve.ce.MWBlockImageNode.prototype.onAttributeChange = function ( key, from, to 
) {
+       // Mixin method
+       ve.ce.MWImageNode.prototype.onAttributeChange.apply( this, arguments );
+
        if ( key === 'height' || key === 'width' ) {
                to = parseInt( to, 10 );
        }
diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js 
b/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js
index b5e0ab9..bcf3ab9 100644
--- a/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js
@@ -15,18 +15,17 @@
  * @mixins ve.ce.MWResizableNode
  *
  * @constructor
- * @param {jQuery} $figure Figure element
- * @param {jQuery} $image Image element
+ * @param {jQuery} $focusable Focusable part of the node
+ * @param {jQuery} $image Image part of the node
  * @param {Object} [config] Configuration options
  */
-ve.ce.MWImageNode = function VeCeMWImageNode( $figure, $image, config ) {
+ve.ce.MWImageNode = function VeCeMWImageNode( $focusable, $image, config ) {
        config = ve.extendObject( {
                enforceMax: false,
                minDimensions: { width: 1, height: 1 }
        }, config );
 
        // Properties
-       this.$figure = $figure;
        this.$image = $image;
        // Parent constructor triggers render so this must precede it
        this.renderedDimensions = null;
@@ -35,8 +34,10 @@
        ve.ce.GeneratedContentNode.call( this );
 
        // Mixin constructors
-       ve.ce.FocusableNode.call( this, this.$figure, config );
-       ve.ce.MWResizableNode.call( this, this.$image, config );
+       ve.ce.FocusableNode.call( this, $focusable, config );
+       if ( this.$image.length ) {
+               ve.ce.MWResizableNode.call( this, this.$image, config );
+       }
 
        // Events
        this.model.connect( this, { attributeChange: 'onAttributeChange' } );
diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js 
b/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js
index 33c73af..cc628ba 100644
--- a/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js
@@ -17,7 +17,7 @@
  * @param {Object} [config] Configuration options
  */
 ve.ce.MWInlineImageNode = function VeCeMWInlineImageNode() {
-       var isError;
+       var isError, $image;
        // Parent constructor
        ve.ce.MWInlineImageNode.super.apply( this, arguments );
 
@@ -27,20 +27,20 @@
                this.$element = $( '<a>' )
                        .addClass( 'new' )
                        .text( this.model.getFilename() );
-               this.$image = $( '<img>' );
+               $image = $( [] );
        } else {
                if ( this.model.getAttribute( 'isLinked' ) ) {
                        this.$element = $( '<a>' ).addClass( 'image' );
-                       this.$image = $( '<img>' ).appendTo( this.$element );
+                       $image = $( '<img>' ).appendTo( this.$element );
                } else {
-                       this.$element = this.$image = $( '<img>' ).appendTo( 
this.$element );
+                       this.$element = $image = $( '<img>' ).appendTo( 
this.$element );
                }
        }
 
        // Mixin constructors
-       ve.ce.MWImageNode.call( this, this.$element, this.$image );
+       ve.ce.MWImageNode.call( this, this.$element, $image );
 
-       this.$image
+       $image
                .attr( 'src', this.getResolvedAttribute( 'src' ) )
                .attr( 'width', this.model.getAttribute( 'width' ) )
                .attr( 'height', this.model.getAttribute( 'height' ) );
@@ -95,6 +95,9 @@
  * @inheritdoc
  */
 ve.ce.MWInlineImageNode.prototype.onAttributeChange = function ( key, from, to 
) {
+       // Mixin method
+       ve.ce.MWImageNode.prototype.onAttributeChange.apply( this, arguments );
+
        if ( key === 'height' || key === 'width' ) {
                to = parseInt( to, 10 );
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Idc736bca6ec7f9cae18d065303364ff5b7828a3b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to