b4 column hidden
[roojs1] / Roo / bootstrap / NavHeaderbar.js
index b98b634..052c107 100644 (file)
@@ -2,7 +2,8 @@
  * - LGPL
  *
  * navbar
- * 
+ * navbar-fixed-top
+ * navbar-expand-md  fixed-top 
  */
 
 /**
  * @cfg {String} brand what is brand
  * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
  * @cfg {String} brand_href href of the brand
- * @cfg {Boolean} srButton generate the sr-only button (true | false) default true
+ * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button   default true
  * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
+ * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
+ * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
  * 
  * @constructor
  * Create a new Sidebar
@@ -24,6 +27,7 @@
 
 Roo.bootstrap.NavHeaderbar = function(config){
     Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
+      
 };
 
 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
@@ -33,60 +37,76 @@ Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
     brand_href: false,
     srButton : true,
     autohide : false,
+    desktopCenter : false,
+   
     
     getAutoCreate : function(){
         
         var   cfg = {
             tag: this.nav || 'nav',
-            cls: 'navbar',
+            cls: 'navbar navbar-expand-md',
             role: 'navigation',
             cn: []
         };
         
+        var cn = cfg.cn;
+        if (this.desktopCenter) {
+            cn.push({cls : 'container', cn : []});
+            cn = cn[0].cn;
+        }
+        
         if(this.srButton){
-            cfg.cn.push({
-                tag: 'div',
-                cls: 'navbar-header',
+            var btn = {
+                tag: 'button',
+                type: 'button',
+                cls: 'navbar-toggle navbar-toggler',
+                'data-toggle': 'collapse',
                 cn: [
                     {
-                        tag: 'button',
-                        type: 'button',
-                        cls: 'navbar-toggle',
-                        'data-toggle': 'collapse',
-                        cn: [
-                            {
-                                tag: 'span',
-                                cls: 'sr-only',
-                                html: 'Toggle navigation'
-                            },
-                            {
-                                tag: 'span',
-                                cls: 'icon-bar'
-                            },
-                            {
-                                tag: 'span',
-                                cls: 'icon-bar'
-                            },
-                            {
-                                tag: 'span',
-                                cls: 'icon-bar'
-                            }
-                        ]
+                        tag: 'span',
+                        cls: 'sr-only',
+                        html: 'Toggle navigation'
+                    },
+                    {
+                        tag: 'span',
+                        cls: 'icon-bar navbar-toggler-icon'
+                    },
+                    {
+                        tag: 'span',
+                        cls: 'icon-bar'
+                    },
+                    {
+                        tag: 'span',
+                        cls: 'icon-bar'
                     }
                 ]
+            };
+            
+            cn.push( Roo.bootstrap.version == 4 ? btn : {
+                tag: 'div',
+                cls: 'navbar-header',
+                cn: [
+                    btn
+                ]
             });
         }
         
-        cfg.cn.push({
+        cn.push({
             tag: 'div',
-            cls: 'collapse navbar-collapse',
+            cls: Roo.bootstrap.version == 4  ? 'nav flex-row roo-navbar-collapse collapse navbar-collapse' : 'collapse navbar-collapse roo-navbar-collapse',
             cn : []
         });
         
-        cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
+        cfg.cls += this.inverse ? ' navbar-inverse navbar-dark bg-dark' : ' navbar-default';
+        
+        if (['light','white'].indexOf(this.weight) > -1) {
+           cfg.cls += ['light','white'].indexOf(this.weight) > -1 ? ' navbar-light' : ' navbar-dark';
+       }
+       cfg.cls += ' bg-' + this.weight;
+        
         
         if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
-            cfg.cls += ' navbar-' + this.position;
+            cfg.cls += ' navbar-' + this.position + ' ' + this.position ;
             
             // tag can override this..
             
@@ -94,7 +114,8 @@ Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
         }
         
         if (this.brand !== '') {
-            cfg.cn[0].cn.push({
+            var cp =  Roo.bootstrap.version == 4 ? cn : cn[0].cn;
+            cp.unshift({ // changed from push ?? BS4 needs it at the start? - does this break or exsiting?
                 tag: 'a',
                 href: this.brand_href ? this.brand_href : '#',
                 cls: 'navbar-brand',
@@ -113,32 +134,49 @@ Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
 
         
     },
+    getHeaderChildContainer : function()
+    {
+        if (this.srButton && this.el.select('.navbar-header').getCount()) {
+            return this.el.select('.navbar-header',true).first();
+        }
+        
+        return this.getChildContainer();
+    },
+    
+    getChildContainer : function()
+    {
+        
+       return this.el.select('.roo-navbar-collapse',true).first();
+        
+       
+    },
+    
     initEvents : function()
     {
         Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
         
         if (this.autohide) {
+            
             var prevScroll = 0;
+            var ft = this.el;
+            
             Roo.get(document).on('scroll',function(e) {
                 var ns = Roo.get(document).getScroll().top;
                 var os = prevScroll;
                 prevScroll = ns;
-                var ft = this.select('.navbar-fixed-top').first();
+                
                 if(ns > os){
                     ft.removeClass('slideDown');
                     ft.addClass('slideUp');
                     return;
                 }
-                ft.removeClass('slideUp').
+                ft.removeClass('slideUp');
                 ft.addClass('slideDown');
                  
               
           },this);
         }
     }    
-          
-      
-    
     
 });