Roo/bootstrap/Element.js
[roojs1] / Roo / bootstrap / Element.js
1 /*
2  * - LGPL
3  *
4  * element
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.Element
10  * @extends Roo.bootstrap.Component
11  * Bootstrap Element class
12  * @cfg {String} html contents of the element
13  * @cfg {String} tag tag of the element
14  * @cfg {String} cls class of the element
15  * @cfg {Boolean} preventDefault (true|false) default false
16  * @cfg {Boolean} clickable (true|false) default false
17  * 
18  * @constructor
19  * Create a new Element
20  * @param {Object} config The config object
21  */
22
23 Roo.bootstrap.Element = function(config){
24     Roo.bootstrap.Element.superclass.constructor.call(this, config);
25     
26     this.addEvents({
27         // raw events
28         /**
29          * @event click
30          * When a element is chick
31          * @param {Roo.bootstrap.Element} this
32          * @param {Roo.EventObject} e
33          */
34         "click" : true
35     });
36 };
37
38 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component,  {
39     
40     tag: 'div',
41     cls: '',
42     html: '',
43     preventDefault: false, 
44     clickable: false,
45     
46     getAutoCreate : function(){
47         
48         var cfg = {
49             tag: this.tag,
50             // cls: this.cls, double assign in parent class Component.js :: onRender
51             html: this.html
52         };
53         
54         return cfg;
55     },
56     
57     initEvents: function() 
58     {
59         Roo.bootstrap.Element.superclass.initEvents.call(this);
60         
61         if(this.clickable){
62             
63             if(!Roo.isTouch){
64                 this.el.on('click', this.onClick, this);
65             } else {
66                 this.el.on('touchstart', this.onClick, this);
67             }
68             
69         }
70         
71     },
72     
73     onClick : function(e)
74     {
75         if(this.preventDefault){
76             e.preventDefault();
77         }
78         
79         this.fireEvent('click', this, e);
80     },
81     
82     getValue : function()
83     {
84         return this.el.dom.innerHTML;
85     },
86     
87     setValue : function(value)
88     {
89         this.el.dom.innerHTML = value;
90     }
91    
92 });
93
94  
95
96