Roo/bootstrap/Button.js
[roojs1] / Roo / bootstrap / Button.js
index efb0eb7..7f2562c 100644 (file)
@@ -10,7 +10,7 @@
  * @extends Roo.bootstrap.Component
  * Bootstrap Button class
  * @cfg {String} html The button content
- * @cfg {String} weight default (or empty) | primary | success | info | warning | danger
+ * @cfg {String} weight default (or empty) | primary | success | info | warning | danger | link
  * @cfg {String} size empty | lg | sm | xs
  * @cfg {String} tag empty | a | input | submit
  * @cfg {String} href empty or href
@@ -24,6 +24,9 @@
  * @cfg {String} ontext text for on toggle state
  * @cfg {String} offtext text for off toggle state
  * @cfg {Boolean} defaulton true | false
+ * @cfg {Boolean} preventDefault (true | false) default true
+ * @cfg {Boolean} removeClass true | false remove the standard class..
+ * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
  * 
  * @constructor
  * Create a new button
@@ -62,13 +65,21 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
     ontext: 'ON',
     offtext: 'OFF',
     defaulton: true,
+    preventDefault: true,
+    removeClass: false,
+    name: false,
+    target: false,
+    
+    pressed : false,
+    
     
     getAutoCreate : function(){
         
         var cfg = {
             tag : 'button',
-            html: 'hello'
-        }
+            cls : 'roo-button',
+            html: ''
+        };
         
         if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
             throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
@@ -81,7 +92,7 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
         if (this.toggle===true) {
             cfg={
                 tag: 'div',
-                cls: 'slider-frame',
+                cls: 'slider-frame roo-button',
                 cn: [
                     {
                         tag: 'span',
@@ -110,28 +121,28 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
             return cfg;
         }
         
-        if (true) {
-            if (this.theme==='default') {
-                cfg.cls = 'btn'
-                
-                if (this.parentType != 'Navbar') {
-                    this.weight = this.weight.length ?  this.weight : 'default';
-                }
-                if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
-                    
-                    cfg.cls += ' btn-' + this.weight;
-                }
-            } else if (this.theme==='glow') {
+         
+        if (this.theme==='default') {
+            cfg.cls = 'btn roo-button';
+            
+            //if (this.parentType != 'Navbar') {
+            this.weight = this.weight.length ?  this.weight : 'default';
+            //}
+            if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
                 
-                cfg.tag = 'a';
-                cfg.cls='btn-glow'
+                cfg.cls += ' btn-' + this.weight;
+            }
+        } else if (this.theme==='glow') {
+            
+            cfg.tag = 'a';
+            cfg.cls = 'btn-glow roo-button';
+            
+            if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
                 
-                if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
-                    
-                    cfg.cls += ' ' + this.weight;
-                }
+                cfg.cls += ' ' + this.weight;
             }
         }
+   
         
         if (this.inverse) {
             this.cls += ' inverse';
@@ -142,15 +153,28 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
             cfg.cls += ' active';
         }
         
+        if (this.disabled) {
+            cfg.disabled = 'disabled';
+        }
+        
+        if (this.items) {
+            Roo.log('changing to ul' );
+            cfg.tag = 'ul';
+            this.glyphicon = 'caret';
+        }
+        
         cfg.cls += this.size.length ? (' btn-' + this.size) : '';
          
         //gsRoo.log(this.parentType);
-        if (this.parentType === 'Navbar') {
+        if (this.parentType === 'Navbar' && !this.parent().bar) {
+            Roo.log('changing to li?');
+            
             cfg.tag = 'li';
             
             cfg.cls = '';
             cfg.cn =  [{
                 tag : 'a',
+                cls : 'roo-button',
                 html : this.html,
                 href : this.href || '#'
             }];
@@ -161,22 +185,9 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
             
             delete cfg.html;
             
-        } else if (this.menu) {
-            cfg.tag = 'a'
-            cfg.cls += ' dropdown test';
         }
         
-        
-        
-        if (this.disabled) {
-            cfg.disabled = 'disabled';
-        }
-        
-        if (this.items) {
-            Roo.log('changing to ul' );
-            cfg.tag = 'ul';
-            this.glyphicon = 'caret';
-        }
+       cfg.cls += this.parentType === 'Navbar' ?  ' navbar-btn' : '';
         
         if (this.glyphicon) {
             cfg.html = ' ' + cfg.html;
@@ -194,41 +205,77 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
             
             cfg.tag = 'a';
             
-            cfg.cls='btn';
+//            cfg.cls='btn roo-button';
             
             cfg.href=this.href;
             
+            var value = cfg.html;
+            
+            if(this.glyphicon){
+                value = {
+                            tag: 'span',
+                            cls: 'glyphicon glyphicon-' + this.glyphicon,
+                            html: this.html
+                        };
+                
+            }
+            
             cfg.cn = [
-                cfg.html,
+                value,
                 {
                     tag: 'span',
                     cls: 'badge',
                     html: this.badge
                 }
-            ]
+            ];
             
             cfg.html='';
         }
         
+        if (this.menu) {
+            cfg.cls += ' dropdown';
+            cfg.html = typeof(cfg.html) != 'undefined' ? cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
+        }
+        
         if (cfg.tag !== 'a' && this.href !== '') {
             throw "Tag must be a to set href.";
         } else if (this.href.length > 0) {
             cfg.href = this.href;
         }
         
+        if(this.removeClass){
+            cfg.cls = '';
+        }
+        
+        if(this.target){
+            cfg.target = this.target;
+        }
+        
         return cfg;
     },
     initEvents: function() {
        // Roo.log('init events?');
-       // Roo.log(this.el.dom);
-        this.el.select('a',true).on('click',
-                function(e) {
-                    this.fireEvent('click', this);
-                },
-                this
-        );
+//        Roo.log(this.el.dom);
+       if (this.el.hasClass('roo-button')) {
+            this.el.on('click', this.onClick, this);
+       } else {
+            this.el.select('.roo-button').on('click', this.onClick, this);
+       }
+       
+       
+        
+    },
+    onClick : function(e)
+    {
+        Roo.log('button on click ');
+        if(this.preventDefault){
+            e.preventDefault();
+        }
+        
+        this.fireEvent('click', this, e);
     }
-   
+    
+    
 });
 
  
\ No newline at end of file