'use strict';
-// DocumentElement represents a node from WLXML document rendered inside Canvas
+// DocumentElement represents a text or an element node from WLXML document rendered inside Canvas
var DocumentElement = function(htmlElement, canvas) {
if(arguments.length === 0)
return;
this.$element = $(htmlElement);
}
+var elementTypeFromParams = function(params) {
+ return params.text !== undefined ? DocumentTextElement : DocumentNodeElement;
+
+};
+
+$.extend(DocumentElement, {
+ create: function(params, canvas) {
+ return elementTypeFromParams(params).create(params);
+ },
+
+ createDOM: function(params) {
+ return elementTypeFromParams(params).createDOM(params);
+ },
+
+ fromHTMLElement: function(htmlElement, canvas) {
+ if(htmlElement.nodeType === Node.ELEMENT_NODE)
+ return DocumentNodeElement.fromHTMLElement(htmlElement, canvas);
+ if(htmlElement.nodeType === Node.TEXT_NODE)
+ return DocumentTextElement.fromHTMLElement(htmlElement, canvas);
+ }
+});
+
$.extend(DocumentElement.prototype, {
dom: function() {
return this.$element;
});
+// DocumentNodeElement represents an element node from WLXML document rendered inside Canvas
var DocumentNodeElement = function(htmlElement, canvas) {
DocumentElement.call(this, htmlElement, canvas);
};
-var DocumentTextElement = function(htmlElement, canvas) {
- DocumentElement.call(this, htmlElement, canvas);
-};
+$.extend(DocumentNodeElement, {
+ createDOM: function(params) {
+ var dom = $('<div>').attr('wlxml-tag', params.tag);
+ if(params.klass)
+ dom.attr('wlxml-class', params.klass);
+ return dom;
+ },
-DocumentNodeElement.prototype = new DocumentElement();
-DocumentTextElement.prototype = new DocumentElement();
+ create: function(params, canvas) {
+ return this.fromHTMLElement(this.createDOM(params)[0]);
+ },
+
+ fromHTMLElement: function(htmlElement, canvas) {
+ return new this(htmlElement, canvas);
+ }
+});
var manipulate = function(e, params, action) {
var element;
return element;
};
+DocumentNodeElement.prototype = new DocumentElement();
+
$.extend(DocumentNodeElement.prototype, {
append: function(params) {
manipulate(this, params, 'append');
});
-DocumentElement.create = function(params, canvas) {
- var ElementType = params.text !== undefined ? DocumentTextElement : DocumentNodeElement;
- return ElementType.create(params);
-};
-
-DocumentElement.createDOM = function(params) {
- var ElementType = params.text !== undefined ? DocumentTextElement : DocumentNodeElement;
- return ElementType.createDOM(params);
-};
-
-DocumentElement.fromHTMLElement = function(htmlElement, canvas) {
- if(htmlElement.nodeType === Node.ELEMENT_NODE)
- return DocumentNodeElement.fromHTMLElement(htmlElement, canvas);
- if(htmlElement.nodeType === Node.TEXT_NODE)
- return DocumentTextElement.fromHTMLElement(htmlElement, canvas);
-}
-
-DocumentNodeElement.createDOM = function(params) {
- var dom = $('<div>').attr('wlxml-tag', params.tag);
- if(params.klass)
- dom.attr('wlxml-class', params.klass);
- return dom;
-};
-
-DocumentTextElement.createDOM = function(params) {
- return $(document.createTextNode(params.text));
-};
-
-DocumentNodeElement.create = function(params, canvas) {
- return this.fromHTMLElement(this.createDOM(params)[0]);
+// DocumentNodeElement represents a text node from WLXML document rendered inside Canvas
+var DocumentTextElement = function(htmlElement, canvas) {
+ DocumentElement.call(this, htmlElement, canvas);
};
-DocumentTextElement.create = function(params, canvas) {
- return this.fromHTMLElement(this.createDOM(params)[0]);
-};
+$.extend(DocumentTextElement, {
+ createDOM: function(params) {
+ return $(document.createTextNode(params.text));
+ },
-DocumentNodeElement.fromHTMLElement = function(htmlElement, canvas) {
- return new this(htmlElement, canvas);
-};
+ create: function(params, canvas) {
+ return this.fromHTMLElement(this.createDOM(params)[0]);
+ },
-DocumentTextElement.fromHTMLElement = function(htmlElement, canvas) {
- return new this(htmlElement, canvas);
-};
+ fromHTMLElement: function(htmlElement, canvas) {
+ return new this(htmlElement, canvas);
+ }
+});
+DocumentTextElement.prototype = new DocumentElement();
$.extend(DocumentTextElement.prototype, {
setText: function(text) {