doc: function() {
if(this.d === null)
return null;
- return documentElement.wrap(this.d.get(0), this); //{wlxmlTag: this.d.prop('tagName')};
+ return documentElement.DocumentNodeElement.fromHTMLElement(this.d.get(0), this); //{wlxmlTag: this.d.prop('tagName')};
},
wrapText: function(params) {
},
getDocumentElement: function(from) {
if(from instanceof HTMLElement || from instanceof Text) {
- return documentElement.wrap(from, this);
+ return documentElement.DocumentElement.fromHTMLElement(from, this);
}
},
getCursor: function() {
parent: function() {
var parents = this.$element.parents('[wlxml-tag]');
if(parents.length)
- return documentElementFromHTMLElement(parents[0], this.canvas);
+ return DocumentElement.fromHTMLElement(parents[0], this.canvas);
return null;
},
var elementContent = this.dom().contents();
var element = this;
elementContent.each(function(idx) {
- var childElement = documentElementFromHTMLElement(this, element.canvas);
+ var childElement = DocumentElement.fromHTMLElement(this, element.canvas);
if(idx === 0 && elementContent.length > 1 && elementContent[1].nodeType === Node.ELEMENT_NODE && (childElement instanceof DocumentTextElement) && $.trim($(this).text()) === '')
return true;
if(idx > 0 && childElement instanceof DocumentTextElement) {
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)
};
DocumentNodeElement.create = function(params, canvas) {
- return documentElementFromHTMLElement(DocumentNodeElement.createDOM(params)[0]);
+ return this.fromHTMLElement(this.createDOM(params)[0]);
};
DocumentTextElement.create = function(params, canvas) {
- return documentElementFromHTMLElement(DocumentTextElement.createDOM(params)[0]);
+ return this.fromHTMLElement(this.createDOM(params)[0]);
+};
+
+DocumentNodeElement.fromHTMLElement = function(htmlElement, canvas) {
+ return new this(htmlElement, canvas);
+};
+
+DocumentTextElement.fromHTMLElement = function(htmlElement, canvas) {
+ return new this(htmlElement, canvas);
};
}
});
-var documentElementFromHTMLElement = function(htmlElement, canvas) {
- // if(!canvas)
- // throw 'no canvas specified';
- if(htmlElement.nodeType === Node.ELEMENT_NODE)
- return new DocumentNodeElement(htmlElement, canvas);
- if(htmlElement.nodeType === Node.TEXT_NODE)
- return new DocumentTextElement(htmlElement, canvas);
-};
-
return {
- wrap: function(htmlElement, canvas) {
- return documentElementFromHTMLElement(htmlElement, canvas);
- },
DocumentElement: DocumentElement,
DocumentNodeElement: DocumentNodeElement,
DocumentTextElement: DocumentTextElement