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},
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) {
this.element = element;
nodes.forEach(function(node) {
- var el = this.element.canvas.createElement(node);
+ var el = this.element.createElement(node);
if(el.dom) {
this.dom.append(el.dom);
}
if(param instanceof documentElement.DocumentElement) {
element = param;
} else {
- element = this.element.canvas.createElement(param);//
+ element = this.element.createElement(param);//
}
if(element.dom) {
this.dom.prepend(element.dom);
var DocumentNodeElement = function(wlxmlNode, canvas) {
DocumentElement.call(this, wlxmlNode, canvas);
this.containers = [];
+ this.elementsRegister = canvas.createElementsRegister();
this.contextMenuActions = [];
this.init(this.dom);
};
if(params instanceof DocumentElement) {
element = params;
} else {
- element = e.canvas.createElement(params);
+ element = e.createElement(params);
}
if(element.dom) {
e.dom[action](element.dom);
this.containers.splice(idx, 1);
}
},
+ createElement: function(wlxmlNode) {
+ var parent = this.wlxmlNode.parent() ? utils.getElementForNode(this.wlxmlNode.parent()) : null;
+ return this.canvas.createElement(wlxmlNode, this.elementsRegister, !parent) || parent.createElement(wlxmlNode);
+ },
addToContextMenu: function(actionFqName) {
this.contextMenuActions.push(this.canvas.createAction(actionFqName));
},
if(params instanceof DocumentNodeElement) {
element = params;
} else {
- element = this.canvas.createElement(params);
+ element = this.parent().createElement(params);
}
if(element.dom) {
this.dom.wrap('<div>');
if(params instanceof DocumentNodeElement) {
element = params;
} else {
- element = this.canvas.createElement(params);
+ element = this.createElement(params);
}
if(element.dom) {
this.dom.wrap('<div>');
}
}.bind(this));
}
- if(!Factory) {
- Factory = this.BaseType;
- }
return Factory;
}
});
if(event.meta.node.isRoot()) {
this.canvas.reloadRoot();
} else {
- newElement = this.canvas.createElement(event.meta.node);
+ newElement = element.parent().createElement(event.meta.node);
element.dom.replaceWith(newElement.dom);
}
}