Merge "Add getDomSubtreeFromModel to converter API"

This commit is contained in:
jenkins-bot 2013-12-12 17:41:00 +00:00 committed by Gerrit Code Review
commit aad149fa43
2 changed files with 22 additions and 9 deletions

View file

@ -701,9 +701,7 @@ ve.ce.Surface.prototype.onCopy = function ( e ) {
// Clone the elements in the slice
slice.data.cloneElements();
ve.dm.converter.store = slice.getStore();
ve.dm.converter.internalList = slice.getInternalList();
ve.dm.converter.getDomSubtreeFromData( slice.getData(), this.$pasteTarget[0] );
ve.dm.converter.getDomSubtreeFromModel( slice, this.$pasteTarget[0] );
// Some browsers strip out spans when they match the styling of the
// paste target (e.g. plain spans) so we must protect against this
@ -842,9 +840,13 @@ ve.ce.Surface.prototype.beforePaste = function ( e ) {
}
context.push( { 'type': '/' + context[0].type } );
ve.dm.converter.store = doc.getStore();
ve.dm.converter.internalList = doc.getInternalList();
ve.dm.converter.getDomSubtreeFromData( context, this.$pasteTarget[0] );
ve.dm.converter.getDomSubtreeFromModel(
new ve.dm.Document(
new ve.dm.ElementLinearData( doc.getStore(), context ),
doc.getHtmlDocument(), undefined, doc.getInternalList()
),
this.$pasteTarget[0]
);
// Giving the paste target focus too late can cause problems in FF (!?)
// so do it up here.

View file

@ -1072,19 +1072,30 @@ ve.dm.Converter.prototype.isDomAllMetaOrWhitespace = function ( domElements, exc
ve.dm.Converter.prototype.getDomFromModel = function ( model ) {
var doc = ve.createDocumentFromHtml( '' );
this.getDomSubtreeFromModel( model, doc.body );
return doc;
};
/**
* Convert document model to an HTML DOM subtree and add it to a container element.
*
* @method
* @param {ve.dm.Document} model Document model
* @param {HTMLElement} container DOM element to add the generated elements to. Should be empty.
*/
ve.dm.Converter.prototype.getDomSubtreeFromModel = function ( model, container ) {
// Set up the converter state
this.documentData = model.getFullData();
this.store = model.getStore();
this.internalList = model.getInternalList();
this.getDomSubtreeFromData( this.documentData, doc.body, model.getInnerWhitespace() );
this.getDomSubtreeFromData( this.documentData, container, model.getInnerWhitespace() );
// Clear the state
this.documentData = null;
this.store = null;
this.internalList = null;
return doc;
};
/**