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

Change subject: Fix MWImageNode dimensions and implement toDomElements
......................................................................


Fix MWImageNode dimensions and implement toDomElements

Using element.height was returning 0 if the attribute was empty
when in fact what we mean to store is null (i.e. auto height).

This takes care of the writing of attributes in CE as jQuery
ignores an attribute-set command if the value is null.

Also in this commit I've implemented a basic toDomElements
that outputs the original HTML (code copied from AlienNode).
This stops the code from throwing an exception but will
eventually need to be rewritten to rebuild the HTML from
the attributes stored in the DM.

Bug: 56336
Change-Id: I297a1d0a07e9ebf9d0110fb1cdf266f8415f25b7
---
M modules/ve/dm/nodes/ve.dm.MWImageNode.js
M modules/ve/test/dm/ve.dm.Converter.test.js
M modules/ve/test/dm/ve.dm.example.js
3 files changed, 43 insertions(+), 7 deletions(-)

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



diff --git a/modules/ve/dm/nodes/ve.dm.MWImageNode.js 
b/modules/ve/dm/nodes/ve.dm.MWImageNode.js
index 6601c84..e905a34 100644
--- a/modules/ve/dm/nodes/ve.dm.MWImageNode.js
+++ b/modules/ve/dm/nodes/ve.dm.MWImageNode.js
@@ -30,17 +30,34 @@
 
 ve.dm.MWImageNode.static.matchRdfaTypes = [ 'mw:Image' ];
 
+ve.dm.MWImageNode.static.storeHtmlAttributes = false;
+
 ve.dm.MWImageNode.static.toDataElement = function ( domElements ) {
+       var $node = $( domElements[0].childNodes[0] ),
+               width = $node.attr( 'width' ),
+               height = $node.attr( 'height' ),
+               html = $( '<div>', domElements[0].ownerDocument ).append( $( 
domElements ).clone() ).html();
+
        return {
-               'type': 'MWimage',
+               'type': this.name,
                'attributes': {
-                       'src': domElements[0].childNodes[0].src,
-                       'width': domElements[0].childNodes[0].width,
-                       'height': domElements[0].childNodes[0].height
-               }
+                       'src': $node.attr( 'src' ),
+                       'width': width !== '' ? Number( width ) : null,
+                       'height': height !== '' ? Number( height ) : null,
+                       // TODO: don't store html, just enough attributes to 
rebuild
+                       'html': html
+               },
        };
 };
 
+ve.dm.MWImageNode.static.toDomElements = function ( dataElement ) {
+       //TODO: rebuild html from attributes
+       var wrapper = document.createElement( 'div' );
+       wrapper.innerHTML = dataElement.attributes.html;
+       // Convert wrapper.children to an array
+       return Array.prototype.slice.call( wrapper.childNodes, 0 );
+};
+
 /* Registration */
 
 ve.dm.modelRegistry.register( ve.dm.MWImageNode );
diff --git a/modules/ve/test/dm/ve.dm.Converter.test.js 
b/modules/ve/test/dm/ve.dm.Converter.test.js
index f45855f..557a73a 100644
--- a/modules/ve/test/dm/ve.dm.Converter.test.js
+++ b/modules/ve/test/dm/ve.dm.Converter.test.js
@@ -38,7 +38,7 @@
        }
 } );
 
-QUnit.test( 'getDataFromDom', 49, function ( assert ) {
+QUnit.test( 'getDataFromDom', 50, function ( assert ) {
        var msg,
                cases = ve.dm.example.domToDataCases;
 
@@ -59,7 +59,7 @@
        }
 } );
 
-QUnit.test( 'getDomFromData', 53, function ( assert ) {
+QUnit.test( 'getDomFromData', 54, function ( assert ) {
        var msg,
                cases = ve.dm.example.domToDataCases;
 
diff --git a/modules/ve/test/dm/ve.dm.example.js 
b/modules/ve/test/dm/ve.dm.example.js
index 31886f5..59a75f9 100644
--- a/modules/ve/test/dm/ve.dm.example.js
+++ b/modules/ve/test/dm/ve.dm.example.js
@@ -675,6 +675,8 @@
        }
 };
 
+ve.dm.example.MWImageHtml = '<a rel="mw:Image" href="./File:image.png" 
data-parsoid="{&quot;tsr&quot;:[158,216],&quot;src&quot;:&quot;[[Image:VisualEditor-logo.svg|500px|thumb|center|VE
 
logo]]&quot;,&quot;optNames&quot;:{&quot;width&quot;:&quot;$1px&quot;},&quot;dsr&quot;:[158,216,null,null]}"><img
 height="" width="500" 
src="/index.php?title=Special:FilePath/image.png&amp;width=500" 
alt="image.png"></a>';
+
 ve.dm.example.domToDataCases = {
        'paragraph with plain text': {
                'html': '<body><p>abc</p></body>',
@@ -705,6 +707,23 @@
                        { 'type': '/paragraph' }
                ]
        },
+       'mw:Image': {
+               'html': '<body><p>' + ve.dm.example.MWImageHtml + '</p></body>',
+               'data': [
+                       { 'type': 'paragraph' },
+                       {
+                               'type': 'MWimage',
+                               'attributes': {
+                                       'src': 
'/index.php?title=Special:FilePath/image.png&width=500',
+                                       'width': 500,
+                                       'height': null,
+                                       'html': ve.dm.example.MWImageHtml
+                               }
+                       },
+                       { 'type': '/MWimage' },
+                       { 'type': '/paragraph' }
+               ]
+       },
        'paragraph with alienInline inside': {
                'html': '<body><p>a<tt class="foo">b</tt>c</p></body>',
                'data': [

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I297a1d0a07e9ebf9d0110fb1cdf266f8415f25b7
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Inez <[email protected]>
Gerrit-Reviewer: Krinkle <[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