Roo/bootstrap/Button.js
[roojs1] / Roo / bootstrap / Button.js
index 19e15ee..1385b61 100644 (file)
@@ -40,10 +40,16 @@ Roo.bootstrap.Button = function(config){
         // raw events
         /**
          * @event click
-         * The raw click event for the entire grid.
+         * When a butotn is pressed
          * @param {Roo.EventObject} e
          */
-        "click" : true
+        "click" : true,
+         /**
+         * @event toggle
+         * After the button has been toggles
+         * @param {Roo.EventObject} e
+         */
+        "toggle" : true
     });
 };
 
@@ -70,6 +76,10 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
     name: false,
     target: false,
     
+    
+    pressed : null,
+    
+    
     getAutoCreate : function(){
         
         var cfg = {
@@ -86,7 +96,7 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
         }
         cfg.html = this.html || cfg.html;
         
-        if (this.toggle===true) {
+        if (this.toggle === true) {
             cfg={
                 tag: 'div',
                 cls: 'slider-frame roo-button',
@@ -122,9 +132,9 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
         if (this.theme==='default') {
             cfg.cls = 'btn roo-button';
             
-            if (this.parentType != 'Navbar') {
-                this.weight = this.weight.length ?  this.weight : 'default';
-            }
+            //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;
@@ -182,7 +192,9 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
             
             delete cfg.html;
             
-        } 
+        }
+        
+       cfg.cls += this.parentType === 'Navbar' ?  ' navbar-btn' : '';
         
         if (this.glyphicon) {
             cfg.html = ' ' + cfg.html;
@@ -266,6 +278,12 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
         if(this.preventDefault){
             e.preventDefault();
         }
+        if (this.pressed === true || this.pressed === false) {
+            this.pressed = !this.pressed;
+            this[this.pressed ? 'addClass' : 'removeClass']('active');
+            this.fireEvent('toggle', this,e);
+        }
+        
         
         this.fireEvent('click', this, e);
     }