Roo/bootstrap/NavHeaderbar.js
[roojs1] / Roo / bootstrap / NavHeaderbar.js
1 /*
2  * - LGPL
3  *
4  * navbar
5  * navbar-fixed-top
6  * navbar-expand-md  fixed-top 
7  */
8
9 /**
10  * @class Roo.bootstrap.NavHeaderbar
11  * @extends Roo.bootstrap.NavSimplebar
12  * Bootstrap Sidebar class
13  *
14  * @cfg {String} brand what is brand
15  * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
16  * @cfg {String} brand_href href of the brand
17  * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button   default true
18  * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
19  * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
20  * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
21  * 
22  * @constructor
23  * Create a new Sidebar
24  * @param {Object} config The config object
25  */
26
27
28 Roo.bootstrap.NavHeaderbar = function(config){
29     Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
30       
31 };
32
33 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
34     
35     position: '',
36     brand: '',
37     brand_href: false,
38     srButton : true,
39     autohide : false,
40     desktopCenter : false,
41    
42     
43     getAutoCreate : function(){
44         
45         var   cfg = {
46             tag: this.nav || 'nav',
47             cls: 'navbar',
48             role: 'navigation',
49             cn: []
50         };
51         
52         var cn = cfg.cn;
53         if (this.desktopCenter) {
54             cn.push({cls : 'container', cn : []});
55             cn = cn[0].cn;
56         }
57         
58         if(this.srButton){
59             cn.push({
60                 tag: 'div',
61                 cls: 'navbar-header',
62                 cn: [
63                     {
64                         tag: 'button',
65                         type: 'button',
66                         cls: 'navbar-toggle',
67                         'data-toggle': 'collapse',
68                         cn: [
69                             {
70                                 tag: 'span',
71                                 cls: 'sr-only',
72                                 html: 'Toggle navigation'
73                             },
74                             {
75                                 tag: 'span',
76                                 cls: 'icon-bar'
77                             },
78                             {
79                                 tag: 'span',
80                                 cls: 'icon-bar'
81                             },
82                             {
83                                 tag: 'span',
84                                 cls: 'icon-bar'
85                             }
86                         ]
87                     }
88                 ]
89             });
90         }
91         
92         cn.push({
93             tag: 'div',
94             cls: 'collapse navbar-collapse',
95             cn : []
96         });
97         
98         cfg.cls += this.inverse ? ' navbar-inverse navbar-dark bg-dark' : ' navbar-default';
99         
100         if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
101             cfg.cls += ' navbar-' + this.position + ' ' + this.position ;
102             
103             // tag can override this..
104             
105             cfg.tag = this.tag || (this.position  == 'fixed-bottom' ? 'footer' : 'header');
106         }
107         
108         if (this.brand !== '') {
109             cn[0].cn.push({
110                 tag: 'a',
111                 href: this.brand_href ? this.brand_href : '#',
112                 cls: 'navbar-brand',
113                 cn: [
114                 this.brand
115                 ]
116             });
117         }
118         
119         if(this.main){
120             cfg.cls += ' main-nav';
121         }
122         
123         
124         return cfg;
125
126         
127     },
128     getHeaderChildContainer : function()
129     {
130         if (this.srButton && this.el.select('.navbar-header').getCount()) {
131             return this.el.select('.navbar-header',true).first();
132         }
133         
134         return this.getChildContainer();
135     },
136     
137     
138     initEvents : function()
139     {
140         Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
141         
142         if (this.autohide) {
143             
144             var prevScroll = 0;
145             var ft = this.el;
146             
147             Roo.get(document).on('scroll',function(e) {
148                 var ns = Roo.get(document).getScroll().top;
149                 var os = prevScroll;
150                 prevScroll = ns;
151                 
152                 if(ns > os){
153                     ft.removeClass('slideDown');
154                     ft.addClass('slideUp');
155                     return;
156                 }
157                 ft.removeClass('slideUp');
158                 ft.addClass('slideDown');
159                  
160               
161           },this);
162         }
163     }    
164     
165 });
166
167
168
169  
170
171