mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
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
This commit is contained in:
parent
2d4101168b
commit
dc798befcf
|
@ -41,9 +41,7 @@ ve.ce.GeneratedContentNode.prototype.onUpdate = function () {
|
|||
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' );
|
||||
|
|
|
@ -39,8 +39,8 @@ ve.dm.AlienMetaItem.static.toDataElement = function ( domElements ) {
|
|||
};
|
||||
};
|
||||
|
||||
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 */
|
||||
|
|
|
@ -52,8 +52,8 @@ ve.dm.AlienNode.static.toDataElement = function ( domElements, converter ) {
|
|||
};
|
||||
};
|
||||
|
||||
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 */
|
||||
|
|
|
@ -47,8 +47,8 @@ ve.dm.MWReferenceListNode.static.toDataElement = function ( domElements ) {
|
|||
};
|
||||
};
|
||||
|
||||
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 */
|
||||
|
|
|
@ -105,6 +105,19 @@
|
|||
*/
|
||||
ve.copyObject = oo.copy;
|
||||
|
||||
/**
|
||||
* 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; if unset, simply clone each element
|
||||
* @return {HTMLElement[]} Copy of domElements with copies of each element
|
||||
*/
|
||||
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").
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue