Roo/bootstrap/Navbar.Item.js
[roojs1] / Roo / bootstrap / Navbar.Item.js
1 /*
2  * - LGPL
3  *
4  * row
5  * 
6  */ 
7 Roo.bootstrap.Navbar.Item = function(config){
8     Roo.bootstrap.Navbar.Item.superclass.constructor.call(this, config);
9 };
10
11 Roo.extend(Roo.bootstrap.Navbar.Item, Roo.bootstrap.Component,  {
12     
13     href: false,
14     html: '',
15     badge: '',
16     icon: false,
17     glyphicon: false,
18     
19     getAutoCreate : function(){
20         
21         var cfg = Roo.apply({}, Roo.bootstrap.Navbar.Item.superclass.getAutoCreate.call(this));
22         
23         if (this.parent().parent().sidebar === true) {
24             cfg = {
25                 tag: 'li',
26                 cn: [
27                     {
28                         tag: 'p'
29                     }
30                 ]
31             }
32             
33             if (this.href) {
34                 cfg.cn[0].tag = 'a',
35                 cfg.cn[0].href = this.href;
36             }
37             
38             if (this.html) {
39                 cfg.cn[0].html = this.html;
40             }
41             
42             if (this.icon) {
43                 cfg.cn[0].html = '<i class="icon-'+this.icon+'"></i>'+cfg.cn[0].html || this.html
44             }
45             
46             return cfg;
47         }
48         
49         cfg = {
50             tag: 'li'
51         }
52         cfg.cn = [
53             {
54                 tag: 'p',
55                 html: 'Text'
56             }
57         ];
58         
59         if (this.glyphicon) {
60             if(cfg.html){cfg.html = ' ' + this.html};
61             cfg.cn=[
62                 {
63                     tag: 'span',
64                     cls: 'glyphicon glyphicon-' + this.glyphicon
65                 }
66             ];
67         }
68         
69         cfg.cn[0].html = this.html || cfg.cn[0].html ;
70         if (this.menu) {
71             cfg.cn[0].tag='a';
72             cfg.cn[0].href='#';
73             cfg.cn[0].html += " <span class='caret'></span>";
74         //}else if (!this.href) {
75         //    cfg.cn[0].tag='p';
76         //    cfg.cn[0].cls='navbar-text';
77         } else {
78             cfg.cn[0].tag='a';
79             cfg.cn[0].href=this.href||'#';
80             cfg.cn[0].html=this.html;
81         }
82         
83         if (this.badge !== '') {
84             
85             cfg.cn[0].cn=[
86                 cfg.cn[0].html + ' ',
87                 {
88                     tag: 'span',
89                     cls: 'badge',
90                     html: this.badge
91                 }
92             ];
93             cfg.cn[0].html=''
94         }
95          
96         
97         return cfg;
98     },
99     initEvents: function() {
100        // Roo.log('init events?');
101        // Roo.log(this.el.dom);
102         this.el.select('a',true).on('click',
103                 function(e) {
104                     this.fireEvent('click', this);
105                 },
106                 this
107         );
108     }
109    
110 });
111
112  
113
114