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

Change subject: Avoid jQuery in ve.dm.BlockImageNode.static.toDataElement
......................................................................


Avoid jQuery in ve.dm.BlockImageNode.static.toDataElement

Just a copy of the code from MWBlockImageNode

Change-Id: I2900578d0571a500ce0370a83401ea19666e95ca
---
M src/dm/nodes/ve.dm.BlockImageNode.js
1 file changed, 17 insertions(+), 9 deletions(-)

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



diff --git a/src/dm/nodes/ve.dm.BlockImageNode.js 
b/src/dm/nodes/ve.dm.BlockImageNode.js
index fe36eab..f675066 100644
--- a/src/dm/nodes/ve.dm.BlockImageNode.js
+++ b/src/dm/nodes/ve.dm.BlockImageNode.js
@@ -51,16 +51,24 @@
 // ve.dm.BlockImageNode.static.blacklistedAnnotationTypes = [ 'link' ];
 
 ve.dm.BlockImageNode.static.toDataElement = function ( domElements, converter 
) {
+       // Workaround for jQuery's .children() being expensive due to
+       // https://github.com/jquery/sizzle/issues/311
+       function findChildren( parent, nodeNames ) {
+               return Array.prototype.filter.call( parent.childNodes, function 
( element ) {
+                       return nodeNames.indexOf( 
element.nodeName.toLowerCase() ) !== -1;
+               } );
+       }
+
        var dataElement,
-               $figure = $( domElements[0] ),
-               $img = $figure.children( 'img' ).eq( 0 ),
-               $caption = $figure.children( 'figcaption' ).eq( 0 ),
+               figure = domElements[0],
+               img = findChildren( figure, 'img' )[0] || null,
+               caption = findChildren( figure, 'figcaption' )[0] || null,
                attributes = {
-                       src: $img.attr( 'src' )
+                       src: img && img.getAttribute( 'src' )
                },
-               width = $img.attr( 'width' ),
-               height = $img.attr( 'height' ),
-               altText = $img.attr( 'alt' );
+               width = img && img.getAttribute( 'width' ),
+               height = img && img.getAttribute( 'height' ),
+               altText = img && img.getAttribute( 'alt' );
 
        if ( altText !== undefined ) {
                attributes.alt = altText;
@@ -74,7 +82,7 @@
                attributes: ve.extendObject( 
ve.dm.AlignableNode.static.toDataElementAttributes( domElements, converter ), 
attributes )
        };
 
-       if ( $caption.length === 0 ) {
+       if ( !caption ) {
                return [
                        dataElement,
                        { type: 'imageCaption' },
@@ -83,7 +91,7 @@
                ];
        } else {
                return [ dataElement ]
-                       .concat( converter.getDataFromDomClean( $caption[0], { 
type: 'imageCaption' } ) )
+                       .concat( converter.getDataFromDomClean( caption, { 
type: 'imageCaption' } ) )
                        .concat( [ { type: '/' + this.name } ] );
        }
 };

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

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