Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189736
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(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/36/189736/1
diff --git a/src/dm/nodes/ve.dm.BlockImageNode.js
b/src/dm/nodes/ve.dm.BlockImageNode.js
index 6904532..2df7333 100644
--- a/src/dm/nodes/ve.dm.BlockImageNode.js
+++ b/src/dm/nodes/ve.dm.BlockImageNode.js
@@ -50,16 +50,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;
@@ -73,7 +81,7 @@
attributes: ve.extendObject(
ve.dm.AlignableNode.static.toDataElementAttributes( domElements, converter ),
attributes )
};
- if ( $caption.length === 0 ) {
+ if ( !caption ) {
return [
dataElement,
{ type: 'imageCaption' },
@@ -82,7 +90,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: newchange
Gerrit-Change-Id: I2900578d0571a500ce0370a83401ea19666e95ca
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits