Roo/bootstrap/Button.js
[roojs1] / Roo / bootstrap / Button.js
index e797a70..b9f0a00 100644 (file)
@@ -10,7 +10,7 @@
  * @extends Roo.bootstrap.Component
  * Bootstrap Button class
  * @cfg {String} html The button content
- * @cfg {String} weight (  primary | success | info | warning | danger | link ) default 
+ * @cfg {String} weight (default | primary | success | info | warning | danger | link ) default 
  * @cfg {String} size ( lg | sm | xs)
  * @cfg {String} tag ( a | input | submit)
  * @cfg {String} href empty or href
@@ -20,7 +20,8 @@
  * @cfg {String} badge text for badge
  * @cfg {String} theme default 
  * @cfg {Boolean} inverse 
- * @cfg {Boolean} toggle 
+ * @cfg {Boolean} toggle is it a slidy toggle button
+ * @cfg {Boolean} pressed (true|false) default null - if the button ahs active state
  * @cfg {String} ontext text for on toggle state
  * @cfg {String} offtext text for off toggle state
  * @cfg {Boolean} defaulton 
 
 Roo.bootstrap.Button = function(config){
     Roo.bootstrap.Button.superclass.constructor.call(this, config);
+    this.weightClass = ["btn-default", 
+                       "btn-primary", 
+                       "btn-success", 
+                       "btn-info", 
+                       "btn-warning",
+                       "btn-danger",
+                       "btn-link"
+                      ],  
     this.addEvents({
         // raw events
         /**
          * @event click
          * When a butotn is pressed
+         * @param {Roo.bootstrap.Button} this
          * @param {Roo.EventObject} e
          */
         "click" : true,
@@ -292,6 +302,7 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
             return;
         }
         
+        
         Roo.log('button on click ');
         if(this.preventDefault){
             e.preventDefault();
@@ -341,10 +352,24 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
        
         
     },
+     /**
+     * get the current active state
+     * @return {boolean} true if it's active
+     */
+    isActive : function()
+    {
+        return this.el.hasClass('active');
+    },
+    /**
+     * set the text of the first selected button
+     */
     setText : function(str)
     {
         this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
     },
+    /**
+     * get the text of the first selected button
+     */
     getText : function()
     {
         return this.el.select('.roo-button-text',true).first().dom.innerHTML;
@@ -357,6 +382,11 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
     show: function() {
        
         this.el.show();   
+    },
+    setWeight : function(str)
+    {
+       this.el.removeClass(this.weightClass);
+        this.el.addClass('btn-' + str);        
     }