X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/600f0113753edfca58e20936e4701a096d2b6d04..3dfe15d50b60598341b9754876db4a48162c5cd0:/src/editor/modules/documentCanvas/canvas/canvas.js diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index d3376e3..3dac88f 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -66,7 +66,7 @@ $.extend(TextHandler.prototype, { var Canvas = function(wlxmlDocument, elements, metadata, sandbox) { this.metadata = metadata || {}; this.sandbox = sandbox; - this.elementsRegister = new ElementsRegister(documentElement.DocumentNodeElement, nullElement); + this.elementsRegister = this.createElementsRegister(); elements = [ {tag: 'section', klass: null, prototype: genericElement}, @@ -111,14 +111,28 @@ $.extend(Canvas.prototype, Backbone.Events, { this.reloadRoot(); }, - createElement: function(wlxmlNode) { + createElement: function(wlxmlNode, register, useRoot) { var Factory; + register = register || this.elementsRegister; if(wlxmlNode.nodeType === Node.TEXT_NODE) { Factory = documentElement.DocumentTextElement; } else { + Factory = register.getElement({tag: wlxmlNode.getTagName(), klass: wlxmlNode.getClass()}); + } + if(!Factory && useRoot) { Factory = this.elementsRegister.getElement({tag: wlxmlNode.getTagName(), klass: wlxmlNode.getClass()}); + if(!Factory) { + Factory = documentElement.DocumentNodeElement; + } + } + + if(Factory) { + return new Factory(wlxmlNode, this); } - return new Factory(wlxmlNode, this); + }, + + createElementsRegister: function() { + return new ElementsRegister(documentElement.DocumentNodeElement, nullElement); }, getDocumentElement: function(htmlElement) {