a0934f02ecf64a02fcdb27510b1b4858194d23a7
[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 navbar-expand-md',
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             var btn = {
60                 tag: 'button',
61                 type: 'button',
62                 cls: 'navbar-toggle navbar-toggler',
63                 'data-toggle': 'collapse',
64                 cn: [
65                     {
66                         tag: 'span',
67                         cls: 'sr-only',
68                         html: 'Toggle navigation'
69                     },
70                     {
71                         tag: 'span',
72                         cls: 'icon-bar navbar-toggler-icon'
73                     },
74                     {
75                         tag: 'span',
76                         cls: 'icon-bar'
77                     },
78                     {
79                         tag: 'span',
80                         cls: 'icon-bar'
81                     }
82                 ]
83             };
84             
85             cn.push( Roo.bootstrap.version == 4 ? btn : {
86                 tag: 'div',
87                 cls: 'navbar-header',
88                 cn: [
89                     btn
90                 ]
91             });
92         }
93         
94         cn.push({
95             tag: 'div',
96             cls: 'collapse navbar-collapse',
97             cn : []
98         });
99         
100         cfg.cls += this.inverse ? ' navbar-inverse navbar-dark bg-dark' : ' navbar-default';
101         
102         if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
103             cfg.cls += ' navbar-' + this.position + ' ' + this.position ;
104             
105             // tag can override this..
106             
107             cfg.tag = this.tag || (this.position  == 'fixed-bottom' ? 'footer' : 'header');
108         }
109         
110         if (this.brand !== '') {
111             var cp =  Roo.bootstrap.version == 4 ? cn : cn[0].cn;
112             cp.unshift({ // changed from push ?? BS4 needs it at the start? - does this break or exsiting?
113                 tag: 'a',
114                 href: this.brand_href ? this.brand_href : '#',
115                 cls: 'navbar-brand',
116                 cn: [
117                 this.brand
118                 ]
119             });
120         }
121         
122         if(this.main){
123             cfg.cls += ' main-nav';
124         }
125         
126         
127         return cfg;
128
129         
130     },
131     getHeaderChildContainer : function()
132     {
133         if (this.srButton && this.el.select('.navbar-header').getCount()) {
134             return this.el.select('.navbar-header',true).first();
135         }
136         
137         return this.getChildContainer();
138     },
139     
140     
141     initEvents : function()
142     {
143         Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
144         
145         if (this.autohide) {
146             
147             var prevScroll = 0;
148             var ft = this.el;
149             
150             Roo.get(document).on('scroll',function(e) {
151                 var ns = Roo.get(document).getScroll().top;
152                 var os = prevScroll;
153                 prevScroll = ns;
154                 
155                 if(ns > os){
156                     ft.removeClass('slideDown');
157                     ft.addClass('slideUp');
158                     return;
159                 }
160                 ft.removeClass('slideUp');
161                 ft.addClass('slideDown');
162                  
163               
164           },this);
165         }
166     }    
167     
168 });
169
170
171
172  
173
174