Add getDomSubtreeFromModel to converter API

This means we no longer have to inject the store/internalList etc.
state into the converter manually before generating DOM.

Change-Id: I9d1f5f2592a7c5bf4ad404416b79ad65afd83b9c
This commit is contained in:
Ed Sanders 2013-12-12 14:37:18 +00:00
parent 1e83bd03b3
commit 92dab00f60
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;
};
/**