1 jls.loader.provide('jls.html.HtmlElement'); 2 3 jls.loader.require('jls.gui.Element'); 4 jls.loader.require('jls.gui.Event'); 5 6 jls.html.HtmlElement = jls.lang.Class.create(jls.gui.Element, 7 { 8 initialize : function($super, parameters, parent) { 9 this._htmlElement = null; 10 this._htmlTagName = 'div'; 11 $super(parameters, parent); 12 jls.logger.trace('parent: "' + parent + '"'); 13 }, 14 getHtmlElement : function() { 15 return this._htmlElement; 16 }, 17 setHtmlElement : function(element) { 18 this._htmlElement = element; 19 return this; 20 }, 21 getHtmlTagName : function() { 22 return this._htmlTagName; 23 }, 24 setHtmlTagName : function(tagName) { 25 this._htmlTagName = tagName; 26 return this; 27 }, 28 getTextContent : function() { 29 if ((this._htmlElement != null) && (this._htmlElement.firstChild.nodeType == 3)) { 30 return this._htmlElement.firstChild.nodeValue; 31 } 32 return ''; 33 }, 34 setTextContent : function(value) { 35 if (this._htmlElement == null) { 36 return this; 37 } 38 while (this._htmlElement.hasChildNodes()) { 39 this._htmlElement.removeChild(this._htmlElement.firstChild); 40 } 41 this._htmlElement.appendChild(document.createTextNode(value)); 42 return this; 43 }, 44 onCreate : function() { 45 if (this._htmlElement == null) { 46 this._htmlElement = document.createElement(this._htmlTagName); 47 } 48 if ((this.getParent() != null) && (this.getParent() instanceof jls.html.HtmlElement)) { 49 this.getParent()._htmlElement.appendChild(this._htmlElement); 50 } 51 }, 52 onStyleChange : jls.lang.Class.emptyFunction, 53 /*addChild : function($super, child) { 54 var child = $super(child); 55 if ((typeof child == 'object') && (child instanceof jls.html.HtmlElement)) { 56 this._htmlElement.appendChild(child._htmlElement); 57 } 58 return child; 59 },*/ 60 observe: function($super, type, handler) { 61 $super(type, handler); 62 this._htmlElement.addEventListener(type, (function(e) { 63 var event = new jls.gui.Event(e.type, e.target); 64 this.dispatch(event); 65 }).bind(this), false); 66 }, 67 unobserve: function($super, type, handler) { 68 $super(type, handler); 69 this._htmlElement.removeEventListener(type, handler, false); 70 // TODO 71 }, 72 onDestroy : jls.lang.Class.emptyFunction 73 }); 74 75 /*Object.extend(jls.html.HtmlElement, 76 { 77 });*/ 78 79