Catrope has uploaded a new change for review. https://gerrit.wikimedia.org/r/69339
Change subject: Copy DOM elements properly, into the correct document ...................................................................... Copy DOM elements properly, into the correct document * Provide a utility for copying an array of DOM elements into a different document * Copy the DOM elements returned in toDomElements(), otherwise weird issues arise when the same data is converted to DOM twice Change-Id: Ie927420624f0d4af0692e18d1bc6f952c8013d61 --- M modules/ve/ce/nodes/ve.ce.GeneratedContentNode.js M modules/ve/dm/metaitems/ve.dm.AlienMetaItem.js M modules/ve/dm/nodes/ve.dm.AlienNode.js M modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js M modules/ve/ve.js 5 files changed, 21 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/39/69339/1 diff --git a/modules/ve/ce/nodes/ve.ce.GeneratedContentNode.js b/modules/ve/ce/nodes/ve.ce.GeneratedContentNode.js index 68702c5..e49fd62 100644 --- a/modules/ve/ce/nodes/ve.ce.GeneratedContentNode.js +++ b/modules/ve/ce/nodes/ve.ce.GeneratedContentNode.js @@ -41,9 +41,7 @@ this.emit( 'teardown' ); } this.$.empty().append( - this.$$( store.value( index ) ).map( function ( i, domElement ) { - return doc.importNode( domElement, true ); - } ) + ve.copyDomElements( store.value( index ), doc ) ); if ( this.live ) { this.emit( 'setup' ); diff --git a/modules/ve/dm/metaitems/ve.dm.AlienMetaItem.js b/modules/ve/dm/metaitems/ve.dm.AlienMetaItem.js index 441f242..a7e58ae 100644 --- a/modules/ve/dm/metaitems/ve.dm.AlienMetaItem.js +++ b/modules/ve/dm/metaitems/ve.dm.AlienMetaItem.js @@ -39,8 +39,8 @@ }; }; -ve.dm.AlienMetaItem.static.toDomElements = function ( dataElement ) { - return dataElement.attributes.domElements; +ve.dm.AlienMetaItem.static.toDomElements = function ( dataElement, doc ) { + return ve.copyDomElements( dataElement.attributes.domElements, doc ); }; /* Registration */ diff --git a/modules/ve/dm/nodes/ve.dm.AlienNode.js b/modules/ve/dm/nodes/ve.dm.AlienNode.js index 79be364..16bfcfb 100644 --- a/modules/ve/dm/nodes/ve.dm.AlienNode.js +++ b/modules/ve/dm/nodes/ve.dm.AlienNode.js @@ -52,8 +52,8 @@ }; }; -ve.dm.AlienNode.static.toDomElements = function ( dataElement ) { - return dataElement.attributes.domElements; +ve.dm.AlienNode.static.toDomElements = function ( dataElement, doc ) { + return ve.copyDomElements( dataElement.attributes.domElements, doc ); }; /* Concrete subclasses */ diff --git a/modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js b/modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js index 3909899..8f82068 100644 --- a/modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js +++ b/modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js @@ -47,8 +47,8 @@ }; }; -ve.dm.MWReferenceListNode.static.toDomElements = function ( dataElement ) { - return dataElement.attributes.domElements; +ve.dm.MWReferenceListNode.static.toDomElements = function ( dataElement, doc ) { + return ve.copyDomElements( dataElement.attributes.domElements, doc ); }; /* Registration */ diff --git a/modules/ve/ve.js b/modules/ve/ve.js index 9641e1f..0b92a1a 100644 --- a/modules/ve/ve.js +++ b/modules/ve/ve.js @@ -106,6 +106,20 @@ ve.copyObject = oo.copy; /** + * @method + * Copy an array of DOM elements, optionally into a different document. + * + * @param {HTMLElement[]} domElements DOM elements to copy + * @param {HTMLDocument} [doc] Document to create the copies in + * @return {HTMLElement[]} Copy of domElements with each element cloned into doc + */ + ve.copyDomElements = function ( domElements, doc ) { + return domElements.map( function ( domElement ) { + return doc ? doc.importNode( domElement, true ) : domElement.cloneNode( true ); + } ); + }; + + /** * Check to see if an object is a plain object (created using "{}" or "new Object"). * * @method -- To view, visit https://gerrit.wikimedia.org/r/69339 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie927420624f0d4af0692e18d1bc6f952c8013d61 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Catrope <roan.katt...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits