Roo/bootstrap/Button.js
[roojs1] / Roo / bootstrap / Button.js
index 556802c..3515280 100644 (file)
@@ -40,10 +40,17 @@ 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
+         * @param {boolean} pressed (also available as button.pressed)
+         */
+        "toggle" : true
     });
 };
 
@@ -70,7 +77,8 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
     name: false,
     target: false,
     
-    pressed : false,
+    
+    pressed : null,
     
     
     getAutoCreate : function(){
@@ -89,7 +97,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',
@@ -267,15 +275,57 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
     },
     onClick : function(e)
     {
+        if (this.disabled) {
+            return;
+        }
+        
         Roo.log('button on click ');
         if(this.preventDefault){
             e.preventDefault();
         }
+        if (this.pressed === true || this.pressed === false) {
+            this.pressed = !this.pressed;
+            this.el[this.pressed ? 'addClass' : 'removeClass']('active');
+            this.fireEvent('toggle', this, e, this.pressed);
+        }
+        
         
         this.fireEvent('click', this, e);
+    },
+    enable : function()
+    {
+        this.disabled = false;
+        this.el.removeClass('disabled');
+    },
+    disable : function()
+    {
+        this.disabled = true;
+        this.el.addClass('disabled');
+    },
+     /**
+     * sets the active state on/off, 
+     * @param {Boolean} state (optional) Force a particular state
+     */
+    setActive : function(v) {
+        
+        this.el[v ? 'addClass' : 'removeClass']('active');
+        
+        
+    },
+     /**
+     * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
+     * @param {Boolean} state (optional) Force a particular state
+     */
+    toggleActive : function()
+    {
+       var active = this.el.hasClass('active');
+       this.setActive(!active);
+       
+        
     }
     
     
+    
 });
 
  
\ No newline at end of file