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);
25 if(idx === 0 && elementContent.length > 1 && elementContent[1].nodeType === Node.ELEMENT_NODE && (element instanceof DocumentTextElement) && $.trim($(this).text()) === '')
27 if(idx > 0 && element instanceof DocumentTextElement) {
28 if(toret[toret.length-1] instanceof DocumentNodeElement && $.trim($(this).text()) === '')
36 return documentElementFromHTMLElement(this.$element.parent()[0]);
39 sameNode: function(other) {
40 return other && (typeof other === typeof this) && other.$element[0] === this.$element[0];
43 wrapWithNodeElement: function(wlxmlNode) {
44 this.$element.wrap($('<' + wlxmlNode.tag + ' class="' + wlxmlNode.klass + '"">')[0]);
45 return documentElementFromHTMLElement(this.$element.parent().get(0));
49 var DocumentNodeElement = function(htmlElement) {
50 DocumentElement.call(this, htmlElement);
53 var DocumentTextElement = function(htmlElement) {
54 DocumentElement.call(this, htmlElement);
57 DocumentNodeElement.prototype = new DocumentElement();
58 DocumentTextElement.prototype = new DocumentElement();
60 $.extend(DocumentNodeElement.prototype, {
61 append: function(params) {
62 var to_append = DocumentNodeElement.createDOM(params.tag, params.klass);
63 this.$element.append(to_append);
64 return documentElementFromHTMLElement(to_append);
66 after: function(params) {
67 var to_append = DocumentNodeElement.createDOM(params.tag, params.klass);
68 this.$element.after(to_append);
69 return documentElementFromHTMLElement(to_append);
73 DocumentNodeElement.createDOM = function(tag, klass) {
74 var dom = $('<' + tag + '>');
76 dom.attr('class', klass);
80 var documentElementFromHTMLElement = function(htmlElement) {
81 if(htmlElement.nodeType === Node.ELEMENT_NODE)
82 return new DocumentNodeElement(htmlElement);
83 if(htmlElement.nodeType === Node.TEXT_NODE)
84 return new DocumentTextElement(htmlElement);
88 wrap: function(htmlElement) {
89 return documentElementFromHTMLElement(htmlElement);
91 DocumentElement: DocumentElement,
92 DocumentNodeElement: DocumentNodeElement,
93 DocumentTextElement: DocumentTextElement