Merge "Copy DOM elements properly, into the correct document"

This commit is contained in:
jenkins-bot 2013-06-18 22:52:14 +00:00 committed by Gerrit Code Review
commit 60da007ab9
5 changed files with 20 additions and 9 deletions

View file

@ -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' );

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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").
*