Esanders has uploaded a new change for review.

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


Change subject: Build link-less images with <span> not <a>
......................................................................

Build link-less images with <span> not <a>

toDataElement part fixed in  I6d496f7. This fixes the
toDomElement part so we don't trigger a round trip warning.

Bug: 51963
Change-Id: I27a7579890d669a8b980710db1bafe066b744236
---
M modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js
1 file changed, 9 insertions(+), 7 deletions(-)


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

diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js 
b/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js
index 263cefd..2e76107 100644
--- a/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js
+++ b/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js
@@ -46,14 +46,14 @@
 ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, 
converter ) {
        var $figure = $( domElements[0] ),
                // images with link='' have a span wrapper instead
-               $wrapper = $figure.children( 'a,span' ).eq( 0 ),
-               $img = $wrapper.children( 'img' ).eq( 0 ),
+               $imgWrapper = $figure.children( 'a, span' ).eq( 0 ),
+               $img = $imgWrapper.children( 'img' ).eq( 0 ),
                $caption = $figure.children( 'figcaption' ).eq( 0 ),
                typeofAttr = $figure.attr( 'typeof' ),
                classes = $figure.attr( 'class' ),
                recognizedClasses = [],
                attributes = {
-                       href: $wrapper.attr( 'href' ) || '',
+                       href: $imgWrapper.attr( 'href' ) || '',
                        src: $img.attr( 'src' ),
                        width: $img.attr( 'width' ),
                        height: $img.attr( 'height' ),
@@ -126,7 +126,7 @@
 ve.dm.MWBlockImageNode.static.toDomElements = function ( data, doc, converter 
) {
        var dataElement = data[0],
                figure = doc.createElement( 'figure' ),
-               a = doc.createElement( 'a' ),
+               imgWrapper = doc.createElement( dataElement.attributes.href !== 
'' ? 'a' : 'span' ),
                img = doc.createElement( 'img' ),
                wrapper = doc.createElement( 'div' ),
                classes = [],
@@ -182,13 +182,15 @@
        } else if ( classes.length > 0 ) {
                figure.className = classes.join( ' ' );
        }
-       a.setAttribute( 'href', dataElement.attributes.href );
+       if ( dataElement.attributes.href !== '' ) {
+               imgWrapper.setAttribute( 'href', dataElement.attributes.href );
+       }
        img.setAttribute( 'src', dataElement.attributes.src );
        img.setAttribute( 'width', dataElement.attributes.width );
        img.setAttribute( 'height', dataElement.attributes.height );
        img.setAttribute( 'resource', dataElement.attributes.resource );
-       figure.appendChild( a );
-       a.appendChild( img );
+       figure.appendChild( imgWrapper );
+       imgWrapper.appendChild( img );
 
        // If length of captionData is smaller or equal to 2 it means that 
there is no caption or that
        // it is empty - in both cases we are going to skip appending 
<figcaption>.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I27a7579890d669a8b980710db1bafe066b744236
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>

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

Reply via email to