2 'libs/jquery-1.9.1.min'
7 // DocumentElement represents a node from WLXML document rendered inside Canvas
8 var DocumentElement = function(htmlElement) {
9 if(arguments.length === 0)
11 this.$element = $(htmlElement);
12 this.wlxmlTag = this.$element.prop('tagName');
15 $.extend(DocumentElement.prototype, {
16 children: function() {
18 if(this instanceof DocumentTextElement)
22 var elementContent = this.$element.contents();
23 elementContent.each(function(idx) {
24 var element = documentElementFromHTMLElement(this);
26 (toret.length === 0 && (element instanceof DocumentNodeElement)) ||
27 (toret.length > 0 && (toret[toret.length -1] instanceof DocumentNodeElement) && (element instanceof DocumentNodeElement))
29 toret.push(documentElementFromHTMLElement(document.createTextNode()));
31 if((idx === elementContent.length - 1) && (element instanceof DocumentNodeElement))
32 toret.push(documentElementFromHTMLElement(document.createTextNode()));
38 var DocumentNodeElement = function(htmlElement) {
39 DocumentElement.call(this, htmlElement);
42 var DocumentTextElement = function(htmlElement) {
43 DocumentElement.call(this, htmlElement);
46 DocumentNodeElement.prototype = new DocumentElement();
47 DocumentTextElement.prototype = new DocumentElement();
49 var documentElementFromHTMLElement = function(htmlElement) {
50 if(htmlElement.nodeType === Node.ELEMENT_NODE)
51 return new DocumentNodeElement(htmlElement);
52 if(htmlElement.nodeType === Node.TEXT_NODE)
53 return new DocumentTextElement(htmlElement);
57 wrap: function(htmlElement) {
58 return documentElementFromHTMLElement(htmlElement);
60 DocumentElement: DocumentElement,
61 DocumentNodeElement: DocumentNodeElement,
62 DocumentTextElement: DocumentTextElement