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                 cls: '',
27                 cn: [
28                     {
29                         tag: 'p',
30                         cls: ''
31                     }
32                 ]
33             }
34             
35             if (this.menu) {
36                 cfg.cn[0].cls += ' dropdown-toggle';
37             }
38             
39             if (this.href) {
40                 cfg.cn[0].tag = 'a',
41                 cfg.cn[0].href = this.href;
42             }
43             
44             if (this.html) {
45                 cfg.cn[0].html = this.html;
46             }
47             
48             if (this.glyphicon) {
49                 cfg.cn[0].html = '<i class="glyphicon glyphicon-'+this.glyphicon+'"></i><span>' + cfg.cn[0].html || this.html + '</span>'
50             }
51             
52             return cfg;
53         }
54         
55         cfg = {
56             tag: 'li'
57         }
58         cfg.cn = [
59             {
60                 tag: 'p',
61                 html: 'Text'
62             }
63         ];
64         
65         if (this.glyphicon) {
66             if(cfg.html){cfg.html = ' ' + this.html};
67             cfg.cn=[
68                 {
69                     tag: 'span',
70                     cls: 'glyphicon glyphicon-' + this.glyphicon
71                 }
72             ];
73         }
74         
75         cfg.cn[0].html = this.html || cfg.cn[0].html ;
76         if (this.menu) {
77             cfg.cn[0].tag='a';
78             cfg.cn[0].href='#';
79             cfg.cn[0].html += " <span class='caret'></span>";
80         //}else if (!this.href) {
81         //    cfg.cn[0].tag='p';
82         //    cfg.cn[0].cls='navbar-text';
83         } else {
84             cfg.cn[0].tag='a';
85             cfg.cn[0].href=this.href||'#';
86             cfg.cn[0].html=this.html;
87         }
88         
89         if (this.badge !== '') {
90             
91             cfg.cn[0].cn=[
92                 cfg.cn[0].html + ' ',
93                 {
94                     tag: 'span',
95                     cls: 'badge',
96                     html: this.badge
97                 }
98             ];
99             cfg.cn[0].html=''
100         }
101          
102         
103         return cfg;
104     },
105     initEvents: function() {
106        // Roo.log('init events?');
107        // Roo.log(this.el.dom);
108         this.el.select('a',true).on('click',
109                 function(e) {
110                     this.fireEvent('click', this);
111                 },
112                 this
113         );
114     }
115    
116 });
117
118  
119
120