sync
[roojs1] / roojs-bootstrap-debug.js
index 87e5a14..f1e4aa9 100644 (file)
@@ -1745,8 +1745,9 @@ Roo.bootstrap.MenuMgr = function(){
    // private this should really trigger on mouseup..
    function onMouseDown(e){
         Roo.log("on Mouse Up");
-        if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu") && !e.getTarget('.user-menu')){
-            Roo.log("hideAll");
+        
+        if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
+            Roo.log("MenuManager hideAll");
             hideAll();
             e.stopEvent();
         }
@@ -1862,6 +1863,7 @@ Roo.bootstrap.MenuMgr = function(){
  * @extends Roo.bootstrap.Component
  * Bootstrap Menu class - container for MenuItems
  * @cfg {String} type (dropdown|treeview|submenu) type of menu
+ * @cfg {bool} hidden  if the menu should be hidden when rendered.
  * 
  * @constructor
  * Create a new Menu
@@ -1871,7 +1873,7 @@ Roo.bootstrap.MenuMgr = function(){
 
 Roo.bootstrap.Menu = function(config){
     Roo.bootstrap.Menu.superclass.constructor.call(this, config);
-    if (this.registerMenu) {
+    if (this.registerMenu && this.type != 'treeview')  {
         Roo.bootstrap.MenuMgr.register(this);
     }
     this.addEvents({
@@ -1949,6 +1951,7 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
     
     hidden:true,
     
+        
     parentMenu : false,
     
     getChildContainer : function() {
@@ -1986,6 +1989,7 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
         
         this.triggerEl.addClass('dropdown-toggle');
         
+        
         if (Roo.isTouch) {
             this.el.on('touchstart'  , this.onTouch, this);
         }
@@ -2139,7 +2143,8 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
      * Hides this menu and optionally all parent menus
      * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
      */
-    hide : function(deep){
+    hide : function(deep)
+    {
         
         this.hideMenuItems();
         if(this.el && this.isVisible()){
@@ -2163,7 +2168,11 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
         Roo.log('trigger press');
         //Roo.log(e.getTarget());
        // Roo.log(this.triggerEl.dom);
-        if (Roo.get(e.getTarget()).findParent('.dropdown-menu')) {
+       
+        // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
+        var pel = Roo.get(e.getTarget());
+        if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
+           
             return;
         }
         
@@ -2183,8 +2192,12 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
     
     hideMenuItems : function()
     {
+        Roo.log("hide Menu Items");
+        if (!this.el) { 
+            return;
+        }
         //$(backdrop).remove()
-        Roo.select('.open',true).each(function(aa) {
+        this.el.select('.open',true).each(function(aa) {
             
             aa.removeClass('open');
           //var parent = getParent($(this))
@@ -2193,7 +2206,7 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
            //$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
           //if (e.isDefaultPrevented()) return
            //$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
-        })
+        });
     },
     addxtypeChild : function (tree, cntr) {
         var comp= Roo.bootstrap.Menu.superclass.addxtypeChild.call(this, tree, cntr);
@@ -2224,8 +2237,11 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
  * Bootstrap MenuItem class
  * @cfg {String} html the menu label
  * @cfg {String} href the link
- * @cfg {Boolean} preventDefault (true | false) default true
- * @cfg {Boolean} isContainer (true | false) default false
+ * @cfg {Boolean} preventDefault do not trigger A href on clicks.
+ * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
+ * @cfg {Boolean} active  used on sidebars to highlight active itesm
+ * @cfg {String} fa favicon to show on left of menu item.
+ * @cfg {Roo.bootsrap.Menu} menu the child menu.
  * 
  * 
  * @constructor
@@ -2254,6 +2270,8 @@ Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component,  {
     html : false,
     preventDefault: true,
     isContainer : false,
+    active : false,
+    fa: false,
     
     getAutoCreate : function(){
         
@@ -2263,30 +2281,56 @@ Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component,  {
                 cls: 'dropdown-menu-item'
             };
         }
+        var ctag = {
+            tag: 'span',
+            html: 'Link'
+        };
+        
+        var anc = {
+            tag : 'a',
+            href : '#',
+            cn : [  ]
+        };
+        
+        if (this.fa !== false) {
+            anc.cn.push({
+                tag : 'i',
+                cls : 'fa fa-' + this.fa
+            });
+        }
+        
+        anc.cn.push(ctag);
+        
         
         var cfg= {
             tag: 'li',
             cls: 'dropdown-menu-item',
-            cn: [
-                    {
-                        tag : 'a',
-                        href : '#',
-                        html : 'Link'
-                    }
-                ]
+            cn: [ anc ]
         };
         if (this.parent().type == 'treeview') {
             cfg.cls = 'treeview-menu';
         }
+        if (this.active) {
+            cfg.cls += ' active';
+        }
+        
+        
         
-        cfg.cn[0].href = this.href || cfg.cn[0].href ;
-        cfg.cn[0].html = this.html || cfg.cn[0].html ;
+        anc.href = this.href || cfg.cn[0].href ;
+        ctag.html = this.html || cfg.cn[0].html ;
         return cfg;
     },
     
-    initEvents: function() {
-        
-        //this.el.select('a').on('click', this.onClick, this);
+    initEvents: function()
+    {
+        if (this.parent().type == 'treeview') {
+            this.el.select('a').on('click', this.onClick, this);
+        }
+        if (this.menu) {
+            this.menu.parentType = this.xtype;
+            this.menu.triggerEl = this.el;
+            this.menu = this.addxtype(Roo.apply({}, this.menu));
+        }
         
     },
     onClick : function(e)
@@ -2664,9 +2708,20 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
     {
         //this.el.select('.modal-footer').()
     },
+    diff : false,
+    
     resizeTo: function(w,h)
     {
-        // skip..
+        // skip.. ?? why??
+        
+        this.el.select('.modal-dialog',true).first().setWidth(w);
+        if (this.diff === false) {
+            this.diff = this.el.select('.modal-dialog',true).first().getHeight() - this.el.select('.modal-body',true).first().getHeight();
+        }
+        
+        this.el.select('.modal-body',true).first().setHeight(h-this.diff);
+        
+        
     },
     setContentSize  : function(w, h)
     {
@@ -3656,7 +3711,7 @@ Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
     },
     getHeaderChildContainer : function()
     {
-        if (this.el.select('.navbar-header').getCount()) {
+        if (this.srButton && this.el.select('.navbar-header').getCount()) {
             return this.el.select('.navbar-header',true).first();
         }
         
@@ -4165,11 +4220,16 @@ Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component,  {
     
     onClick : function(e)
     {
+        if (e.getTarget('.dropdown-menu-item')) {
+            // did you click on a menu itemm.... - then don't trigger onclick..
+            return;
+        }
+        
         if(
                 this.preventDefault || 
                 this.href == '#' 
         ){
-            
+            Roo.log("NavItem - prevent Default?");
             e.preventDefault();
         }
         
@@ -4203,7 +4263,7 @@ Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component,  {
             if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
                 return; // ignore... - it's a 'hash' to another page.
             }
-            
+            Roo.log("NavItem - prevent Default?");
             e.preventDefault();
             this.scrollToElement(e);
         }
@@ -4347,6 +4407,7 @@ Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component,  {
  * @extends Roo.bootstrap.NavItem
  * Bootstrap Navbar.NavSidebarItem class
  * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
+ * {bool} open is the menu open
  * @constructor
  * Create a new Navbar Button
  * @param {Object} config The config object
@@ -4377,6 +4438,8 @@ Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem,  {
     
     badgeWeight : 'default',
     
+    open: false,
+    
     getAutoCreate : function(){
         
         
@@ -4405,7 +4468,9 @@ Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem,  {
         if (this.disabled) {
             cfg.cls += ' disabled';
         }
-        
+        if (this.open) {
+            cfg.cls += ' open x-open';
+        }
         // left icon..
         if (this.glyphicon || this.icon) {
             var c = this.glyphicon  ? ('glyphicon glyphicon-'+this.glyphicon)  : this.icon;
@@ -4434,6 +4499,12 @@ Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem,  {
     
     initEvents : function()
     { 
+        if (typeof (this.menu) != 'undefined') {
+            this.menu.parentType = this.xtype;
+            this.menu.triggerEl = this.el;
+            this.menu = this.addxtype(Roo.apply({}, this.menu));
+        }
+        
         this.el.on('click', this.onClick, this);