mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
Merge "Copy DOM elements properly, into the correct document"
This commit is contained in:
commit
60da007ab9
|
@ -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