Uncommited changes synced
[roojs1] / roojs-bootstrap-debug.js
index f263658..3f07ceb 100644 (file)
@@ -1,4 +1,18 @@
-/*
+/**
+ * set the version of bootstrap based on the stylesheet...
+ *
+ */
+
+Roo.bootstrap.version = (
+        function() {
+                var ret=3;
+                Roo.each(document.styleSheets[0], function(s) {
+                    if (s.href.match(/css-bootstrap4/)) {
+                        ret=4;
+                    }
+                });
+        return ret;
+})();/*
  * - LGPL
  *
  * base class for bootstrap elements.
@@ -540,6 +554,17 @@ Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component,  {
         }
         
         return cfg;
+    },
+    /**
+     * Add a button to the group (similar to NavItem API.)
+     */
+    addItem : function(cfg)
+    {
+        var cn = new Roo.bootstrap.Button(cfg);
+        //this.register(cn);
+        cn.parentId = this.id;
+        cn.onRender(this.el, null);
+        return cn;
     }
    
 });
@@ -556,7 +581,9 @@ Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component,  {
  * @extends Roo.bootstrap.Component
  * Bootstrap Button class
  * @cfg {String} html The button content
- * @cfg {String} weight (default | primary | success | info | warning | danger | link ) default 
+ * @cfg {String} weight (default | primary | secondary | success | info | warning | danger | link ) default
+ * @cfg {String} badge_weight (default | primary | secondary | success | info | warning | danger | link ) default (same as button)
+ * @cfg {Boolean} outline default false (except for weight=default which emulates old behaveiour with an outline)
  * @cfg {String} size ( lg | sm | xs)
  * @cfg {String} tag ( a | input | submit)
  * @cfg {String} href empty or href
@@ -582,7 +609,7 @@ Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component,  {
 
 Roo.bootstrap.Button = function(config){
     Roo.bootstrap.Button.superclass.constructor.call(this, config);
-    this.weightClass = ["btn-default", 
+    this.weightClass = ["btn-default btn-outline-secondary", 
                        "btn-primary", 
                        "btn-success", 
                        "btn-info", 
@@ -614,6 +641,8 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
     html: false,
     active: false,
     weight: '',
+    badge_weight: '',
+    outline : false,
     size: '',
     tag: 'button',
     href: '',
@@ -667,7 +696,7 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
                 ]
             };
             
-            if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
+            if (['default', 'secondary' , 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
                 cfg.cls += ' '+this.weight;
             }
             
@@ -691,9 +720,15 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
             //if (this.parentType != 'Navbar') {
             this.weight = this.weight.length ?  this.weight : 'default';
             //}
-            if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
+            if (['default', 'primary', 'secondary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
                 
-                cfg.cls += ' btn-' + this.weight;
+                var outline = this.outline || this.weight == 'default' ? 'outline-' : '';
+                var weight = this.weight == 'default' ? 'secondary' : this.weight;
+                cfg.cls += ' btn-' + outline + weight;
+                if (this.weight == 'default') {
+                    // BC
+                    cfg.cls += ' btn-' + this.weight;
+                }
             }
         } else if (this.theme==='glow') {
             
@@ -782,12 +817,15 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
                         };
                 
             }
+            var bw = this.badge_weight.length ? this.badge_weight :
+                (this.weight.length ? this.weight : 'secondary');
+            bw = bw == 'default' ? 'secondary' : bw;
             
             cfg.cn = [
                 value,
                 {
                     tag: 'span',
-                    cls: 'badge',
+                    cls: 'badge badge-' + bw,
                     html: this.badge
                 }
             ];
@@ -921,7 +959,13 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
     setWeight : function(str)
     {
        this.el.removeClass(this.weightClass);
-        this.el.addClass('btn-' + str);        
+        this.weight = str;
+        var outline = this.outline ? 'outline-' : '';
+        if (str == 'default') {
+            this.el.addClass('btn-default btn-outline-secondary');        
+            return;
+        }
+        this.el.addClass('btn-' + outline + str);        
     }
     
     
@@ -1988,6 +2032,8 @@ Roo.bootstrap.Menu = function(config){
     if (this.registerMenu && this.type != 'treeview')  {
         Roo.bootstrap.MenuMgr.register(this);
     }
+    
+    
     this.addEvents({
         /**
          * @event beforeshow
@@ -2105,8 +2151,13 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
         
         this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
         
-        this.triggerEl.addClass('dropdown-toggle');
-        
+       
+       if (this.triggerEl.hasClass('nav-item')) {
+           // dropdown toggle on the 'a' in BS4?
+           this.triggerEl.select('.nav-link',true).first().addClass('dropdown-toggle');
+       } else {
+           this.triggerEl.addClass('dropdown-toggle');
+       }
         if (Roo.isTouch) {
             this.el.on('touchstart'  , this.onTouch, this);
         }
@@ -2241,6 +2292,7 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
         this.hideMenuItems();
         this.hidden = false;
         this.triggerEl.addClass('open');
+       this.el.addClass('show');
         
         // reassign x when hitting right
         if(this.el.getWidth() + xy[0] >= Roo.lib.Dom.getViewWidth()){
@@ -2290,6 +2342,7 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
                 this.activeItem = null;
             }
             this.triggerEl.removeClass('open');;
+           this.el.removeClass('show');
             this.hidden = true;
             this.fireEvent("hide", this);
         }
@@ -2438,7 +2491,7 @@ Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component,  {
         if(this.isContainer){
             return {
                 tag: 'li',
-                cls: 'dropdown-menu-item'
+                cls: 'dropdown-menu-item dropdown-item'
             };
         }
         var ctag = {
@@ -2464,7 +2517,7 @@ Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component,  {
         
         var cfg= {
             tag: 'li',
-            cls: 'dropdown-menu-item',
+            cls: 'dropdown-menu-item dropdown-item',
             cn: [ anc ]
         };
         if (this.parent().type == 'treeview') {
@@ -2736,7 +2789,7 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
         };
 
         var header = [];
-        if (this.allow_close) {
+        if (this.allow_close && Roo.bootstrap.version == 3) {
             header.push({
                 tag: 'button',
                 cls : 'close',
@@ -2746,6 +2799,14 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
 
         header.push(title);
 
+        if (this.allow_close && Roo.bootstrap.version == 4) {
+            header.push({
+                tag: 'button',
+                cls : 'close',
+                html : '&times'
+            });
+        }
+        
         var size = '';
 
         if(this.size.length){
@@ -2878,15 +2939,19 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
         }
 
         //this.el.setStyle('display', 'block');
-        this.el.removeClass('hideing');        
-        this.el.addClass('show');
+        this.el.removeClass('hideing');
+        this.el.dom.style.display='block';
+        
+        Roo.get(document.body).addClass('modal-open');
  
         if(this.animate){  // element has 'fade'  - so stuff happens after .3s ?- not sure why the delay?
             var _this = this;
             (function(){
+                this.el.addClass('show');
                 this.el.addClass('in');
             }).defer(50, this);
         }else{
+            this.el.addClass('show');
             this.el.addClass('in');
         }
 
@@ -2899,8 +2964,10 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
         
         this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true),   Roo.lib.Dom.getViewHeight(true));
         this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
+        this.maskEl.dom.style.display = 'block';
         this.maskEl.addClass('show');
         
+        
         this.resize();
         
         this.fireEvent('show', this);
@@ -2919,23 +2986,33 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
     hide : function()
     {
         if(this.fireEvent("beforehide", this) !== false){
+            
             this.maskEl.removeClass('show');
+            
+            this.maskEl.dom.style.display = '';
             Roo.get(document.body).removeClass("x-body-masked");
             this.el.removeClass('in');
             this.el.select('.modal-dialog', true).first().setStyle('transform','');
 
             if(this.animate){ // why
                 this.el.addClass('hideing');
+                this.el.removeClass('show');
                 (function(){
                     if (!this.el.hasClass('hideing')) {
                         return; // it's been shown again...
                     }
-                    this.el.removeClass('show');
+                    
+                    this.el.dom.style.display='';
+
+                    Roo.get(document.body).removeClass('modal-open');
                     this.el.removeClass('hideing');
                 }).defer(150,this);
                 
             }else{
-                 this.el.removeClass('show');
+                this.el.removeClass('show');
+                this.el.dom.style.display='';
+                Roo.get(document.body).removeClass('modal-open');
+
             }
             this.fireEvent('hide', this);
         }
@@ -3836,7 +3913,7 @@ Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component,  {
  * 
  * @cfg {String} tag (header|footer|nav|div) default is nav 
 
- * 
+ * @cfg {String} weight (light|primary|secondary|success|danger|warning|info|dark|white) default is light.
  * 
  * 
  * @constructor
@@ -3857,7 +3934,7 @@ Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar,  {
     arrangement: '',
     align : false,
     
-    
+    weight : 'light',
     
     main : false,
     
@@ -3870,8 +3947,13 @@ Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar,  {
         
         var cfg = {
             tag : this.tag || 'div',
-            cls : 'navbar'
+            cls : 'navbar navbar-expand-lg'
         };
+       if (['light','white'].indexOf(this.weight) > -1) {
+           cfg.cls += ['light','white'].indexOf(this.weight) > -1 ? ' navbar-light' : ' navbar-dark';
+       }
+       cfg.cls += ' bg-' + this.weight;
+       
          
        
         cfg.cn = [
@@ -3930,7 +4012,8 @@ Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar,  {
  * - LGPL
  *
  * navbar
- * 
+ * navbar-fixed-top
+ * navbar-expand-md  fixed-top 
  */
 
 /**
@@ -3971,7 +4054,7 @@ Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
         
         var   cfg = {
             tag: this.nav || 'nav',
-            cls: 'navbar',
+            cls: 'navbar navbar-expand-md',
             role: 'navigation',
             cn: []
         };
@@ -3990,7 +4073,7 @@ Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
                     {
                         tag: 'button',
                         type: 'button',
-                        cls: 'navbar-toggle',
+                        cls: 'navbar-toggle navbar-toggler',
                         'data-toggle': 'collapse',
                         cn: [
                             {
@@ -4000,7 +4083,7 @@ Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
                             },
                             {
                                 tag: 'span',
-                                cls: 'icon-bar'
+                                cls: 'icon-bar navbar-toggler-icon'
                             },
                             {
                                 tag: 'span',
@@ -4022,10 +4105,10 @@ Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
             cn : []
         });
         
-        cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
+        cfg.cls += this.inverse ? ' navbar-inverse navbar-dark bg-dark' : ' navbar-default';
         
         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..
             
@@ -4225,15 +4308,17 @@ Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component,  {
             };
             
             if (this.align === 'right') {
-                cfg.cls += ' navbar-right';
+                cfg.cls += ' navbar-right ml-md-auto';
             } else {
                 cfg.cls += ' navbar-left';
             }
         }
         
         if (this.align === 'right') {
-            cfg.cls += ' navbar-right';
-        }
+            cfg.cls += ' navbar-right ml-md-auto';
+        } else {
+           cfg.cls += ' mr-auto';
+       }
         
         if (this.inverse) {
             cfg.cls += ' navbar-inverse';
@@ -4518,7 +4603,9 @@ Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component,  {
                     html: this.html || ''
                 }
             ];
-            
+            if (this.tagtype == 'a') {
+               cfg.cn[0].cls = 'nav-link';
+           }
             if (this.icon) {
                 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
             }
@@ -4535,7 +4622,7 @@ Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component,  {
             
             if (this.badge !== '') {
                  
-                cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
+                cfg.cn[0].html += ' <span class="badge badge-secondary">' + this.badge + '</span>';
             }
         }
         
@@ -7919,7 +8006,7 @@ Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component,  {
             cls : ''
         };
         if (this.parent().xtype.match(/^Nav/)) {
-            cfg.cls = 'navbar-form navbar-' + this.align;
+            cfg.cls = 'navbar-form form-inline navbar-' + this.align;
 
         }
 
@@ -17582,11 +17669,11 @@ Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component,  {
                     cn : [
                         {
                             tag: 'h3',
-                            cls: 'popover-title',
+                            cls: 'popover-title popover-header',
                             html : this.title
                         },
                         {
-                            cls : 'popover-content',
+                            cls : 'popover-content popover-body',
                             html : this.html
                         }
                     ]
@@ -17711,7 +17798,10 @@ Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component,  {
         if (this.html !== false) {
             this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
         }
-        this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
+        this.el.removeClass([
+            'fade','top','bottom', 'left', 'right','in',
+            'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
+        ]);
         if (!this.title.length) {
             this.el.select('.popover-title',true).hide();
         }
@@ -17772,10 +17862,10 @@ Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component,  {
 });
 
 Roo.bootstrap.Popover.alignment = {
-    'left' : ['r-l', [-10,0], 'right'],
-    'right' : ['l-r', [10,0], 'left'],
-    'bottom' : ['t-b', [0,10], 'top'],
-    'top' : [ 'b-t', [0,-10], 'bottom']
+    'left' : ['r-l', [-10,0], 'right bs-popover-right'],
+    'right' : ['l-r', [10,0], 'left bs-popover-left'],
+    'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
+    'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
 };
 
  /*
@@ -19035,7 +19125,6 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input,  {
         if(this.isInline) {
             return;
         }
-        Roo.log(this.picker());
         this.picker().hide();
         this.viewMode = this.startViewMode;
         this.showMode();
@@ -19171,7 +19260,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input,  {
             case 18: // alt
                 break;
             default :
-                this.hide();
+                this.hidePopup();
                 
         }
     },
@@ -24633,7 +24722,11 @@ Roo.bootstrap.PagingToolbar = function(config)
         this.bind(this.ds);
     }
     
-    this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
+    if (Roo.bootstrap.version == 4) {
+        this.navgroup = new Roo.bootstrap.ButtonGroup({ cls: 'pagination' });
+    } else {
+        this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
+    }
     
 };
 
@@ -24732,8 +24825,8 @@ Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
         
         this.first = this.navgroup.addItem({
             tooltip: this.firstText,
-            cls: "prev",
-            icon : 'fa fa-backward',
+            cls: "prev btn-outline-secondary",
+            html : ' <i class="fa fa-step-backward"></i>',
             disabled: true,
             preventDefault: true,
             listeners : { click : this.onClick.createDelegate(this, ["first"]) }
@@ -24741,8 +24834,8 @@ Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
         
         this.prev =  this.navgroup.addItem({
             tooltip: this.prevText,
-            cls: "prev",
-            icon : 'fa fa-step-backward',
+            cls: "prev btn-outline-secondary",
+            html : ' <i class="fa fa-backward"></i>',
             disabled: true,
             preventDefault: true,
             listeners : { click :  this.onClick.createDelegate(this, ["prev"]) }
@@ -24752,8 +24845,8 @@ Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
         
         var field = this.navgroup.addItem( {
             tagtype : 'span',
-            cls : 'x-paging-position',
-            
+            cls : 'x-paging-position  btn-outline-secondary',
+             disabled: true,
             html : this.beforePageText  +
                 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
                 '<span class="x-paging-after">' +  String.format(this.afterPageText, 1) + '</span>'
@@ -24769,16 +24862,16 @@ Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
         //this.addSeparator();
         this.next = this.navgroup.addItem({
             tooltip: this.nextText,
-            cls: "next",
-            html : ' <i class="fa fa-step-forward">',
+            cls: "next btn-outline-secondary",
+            html : ' <i class="fa fa-forward"></i>',
             disabled: true,
             preventDefault: true,
             listeners : { click :  this.onClick.createDelegate(this, ["next"]) }
         });
         this.last = this.navgroup.addItem({
             tooltip: this.lastText,
-            icon : 'fa fa-forward',
-            cls: "next",
+            html : ' <i class="fa fa-step-forward"></i>',
+            cls: "next btn-outline-secondary",
             disabled: true,
             preventDefault: true,
             listeners : { click :  this.onClick.createDelegate(this, ["last"]) }
@@ -24786,7 +24879,8 @@ Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
     //this.addSeparator();
         this.loading = this.navgroup.addItem({
             tooltip: this.refreshText,
-            icon: 'fa fa-refresh',
+            cls: "btn-outline-secondary",
+            html : ' <i class="fa fa-refresh"></i>',
             preventDefault: true,
             listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
         });
@@ -39879,6 +39973,8 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
         
         allowed: '0123456789',
         
+        max_length: 15,
+        
         /**
          * @cfg {String} defaultDialCode The default dial code when initializing the input
          */
@@ -39923,6 +40019,8 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
             var input =  {
                 tag: 'input',
                 id : id,
+                // type: 'number', -- do not use number - we get the flaky up/down arrows.
+                maxlength: this.max_length,
                 cls : 'form-control tel-input',
                 autocomplete: 'new-password'
             };
@@ -40136,6 +40234,7 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
             this.list.on('mouseover', this.onViewOver, this);
             this.list.on('mousemove', this.onViewMove, this);
             this.inputEl().on("keyup", this.onKeyUp, this);
+            this.inputEl().on("keypress", this.onKeyPress, this);
             
             this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
 
@@ -40385,26 +40484,15 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
             return this.el.select('input.hidden-tel-input',true).first();
         },
         
+        // after setting val
         onKeyUp : function(e){
-            
-            var k = e.getKey();
-            var c = e.getCharCode();
-            
-            if(
-                    (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
-                    this.allowed.indexOf(String.fromCharCode(c)) === -1
-            ){
-                e.stopEvent();
-            }
-            
-            // if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
-            //     return;
-            // }
-            if(this.allowed.indexOf(String.fromCharCode(c)) === -1){
+            this.setValue(this.getValue());
+        },
+        
+        onKeyPress : function(e){
+            if(this.allowed.indexOf(String.fromCharCode(e.getCharCode())) === -1){
                 e.stopEvent();
             }
-            
-            this.setValue(this.getValue());
         }
         
 });
@@ -40480,7 +40568,10 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
      * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
      */
     thousandsDelimiter : false,
-    
+    /**
+     * @cfg {Number} max_length Maximum input field length allowed (defaults to Number.MAX_VALUE)
+     */
+    max_length: false,
     
     inputlg : 9,
     inputmd : 9,
@@ -40514,6 +40605,10 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
             cls: 'hidden-number-input'
         };
         
+        if(this.max_length) {
+            input.maxlength = this.max_length; 
+        }
+        
         if (this.name) {
             hiddenInput.name = this.name;
         }