Roo/bootstrap/Navbar.js
[roojs1] / Roo / bootstrap / Navbar.js
1 /*
2  * - LGPL
3  *
4  * navbar
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.Navbar
10  * @extends Roo.bootstrap.Component
11  * Bootstrap Navbar class
12  * @cfg {Boolean} bar is a bar?
13  * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
14  * @cfg {String} brand what is brand
15  * @cfg {Boolean} inverse is inverted color
16  * @cfg {String} type (nav | pills | tabs)
17  * @cfg {Boolean} arrangement stacked | justified
18  * @cfg {String} align (left | right) alignment
19  * @cfg {String} brand_href href of the brand
20  * @cfg {Boolean} main (true|false) main nav bar? default false
21  * @cfg {Boolean} loadMask (true|false) loadMask on the bar
22  * @cfg {String} tag (header|footer|nav|div) default is nav 
23
24  * 
25  * @constructor
26  * Create a new Navbar
27  * @param {Object} config The config object
28  */
29
30
31 Roo.bootstrap.Navbar = function(config){
32     Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
33     
34 };
35
36 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component,  {
37     
38     
39     bar: false,
40     brand: '',
41     inverse: false,
42     position: '',
43     align : false,
44     type: false,
45     arrangement: '',
46     brand_href: false,
47     main : false,
48     loadMask : false,
49     tag : false,
50     
51     // private
52     navItems : false,
53     
54     getAutoCreate : function(){
55         
56         
57         
58         var cfg = {
59             cls : 'navbar'
60         };
61          
62         if (this.bar === true) {
63             cfg = {
64                 tag: this.tag || 'nav',
65                 cls: 'navbar',
66                 role: 'navigation',
67                 cn: [
68                     {
69                         tag: 'div',
70                         cls: 'navbar-header',
71                         cn: [
72                             {
73                             tag: 'button',
74                             type: 'button',
75                             cls: 'navbar-toggle',
76                             'data-toggle': 'collapse',
77                             cn: [
78                                 {
79                                     tag: 'span',
80                                     cls: 'sr-only',
81                                     html: 'Toggle navigation'
82                                 },
83                                 {
84                                     tag: 'span',
85                                     cls: 'icon-bar'
86                                 },
87                                 {
88                                     tag: 'span',
89                                     cls: 'icon-bar'
90                                 },
91                                 {
92                                     tag: 'span',
93                                     cls: 'icon-bar'
94                                 }
95                             ]
96                             }
97                         ]
98                     },
99                     {
100                     tag: 'div',
101                     cls: 'collapse navbar-collapse'
102                     }
103                 ]
104             };
105             
106             cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
107             
108             if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
109                 cfg.cls += ' navbar-' + this.position;
110                 // 
111                 cfg.tag = this.position  == 'fixed-bottom' ? 'footer' : 'header';
112             }
113             
114             if (this.brand !== '') {
115                 cfg.cn[0].cn.push({
116                     tag: 'a',
117                     href: this.brand_href ? this.brand_href : '#',
118                     cls: 'navbar-brand',
119                     cn: [
120                     this.brand
121                     ]
122                 });
123             }
124             
125             if(this.main){
126                 cfg.cls += ' main-nav';
127             }
128             
129             
130             return cfg;
131         
132         } else if (this.bar === false) {
133             
134         } else {
135             Roo.log('Property \'bar\' in of Navbar must be either true or false')
136         }
137         
138         cfg.cn = [
139             {
140                 cls: 'nav',
141                 tag : 'ul'
142             }
143         ];
144         this.type = this.type || 'nav';
145         if (['tabs','pills'].indexOf(this.type)!==-1) {
146             cfg.cn[0].cls += ' nav-' + this.type
147         } else {
148             if (this.type!=='nav') {
149                 Roo.log('nav type must be nav/tabs/pills')
150             }
151             cfg.cn[0].cls += ' navbar-nav'
152         }
153         
154         if (['stacked','justified'].indexOf(this.arrangement)!==-1) {
155             cfg.cn[0].cls += ' nav-' + this.arrangement;
156         }
157         
158         
159         if (this.align === 'right') {
160             cfg.cn[0].cls += ' navbar-right';
161         }
162         
163         if (this.inverse) {
164             cfg.cls += ' navbar-inverse';
165             
166         }
167         
168         
169         return cfg;
170     },
171     
172     initEvents :function ()
173     {
174         //Roo.log(this.el.select('.navbar-toggle',true));
175         this.el.select('.navbar-toggle',true).on('click', function() {
176            // Roo.log('click');
177             this.el.select('.navbar-collapse',true).toggleClass('in');                                 
178         }, this);
179         
180         var mark = {
181             tag: "div",
182             cls:"x-dlg-mask"
183         }
184         
185         this.maskEl = Roo.DomHelper.append(this.el, mark, true);
186         
187         var size = this.el.getSize();
188         this.maskEl.setSize(size.width, size.height);
189         this.maskEl.enableDisplayMode("block");
190         this.maskEl.hide();
191         
192         if(this.loadMask){
193             this.maskEl.show();
194         }
195     },
196     
197     
198     getChildContainer : function()
199     {
200         if (this.bar === true) {
201             return this.el.select('.collapse',true).first();
202         }
203         
204         return this.el;
205     },
206     
207     mask : function()
208     {
209         this.maskEl.show();
210     },
211     
212     unmask : function()
213     {
214         this.maskEl.hide();
215     }
216     
217     
218     
219 });
220
221
222
223  
224
225