Browse Source

Merge pull request #120 from frapontillo/master

Added `setTextLabel` and `setIconLabel` methods
Stein, Peter 11 years ago
parent
commit
4ee97aa2a5
4 changed files with 25 additions and 6 deletions
  1. 2 0
      README.md
  2. 5 0
      examples/index.html
  3. 18 6
      static/js/bootstrap-switch.js
  4. 0 0
      static/js/bootstrap-switch.min.js

+ 2 - 0
README.md

@@ -211,6 +211,8 @@ $('#mySwitch').bootstrapSwitch('setState', true);
 $('#mySwitch').bootstrapSwitch('setState', true || false, true); // sets the state without getting the switch-change event
 $('#mySwitch').bootstrapSwitch('setState', true || false, true); // sets the state without getting the switch-change event
 $('#mySwitch').bootstrapSwitch('setOnLabel', onValue); // sets the text of the "on" label
 $('#mySwitch').bootstrapSwitch('setOnLabel', onValue); // sets the text of the "on" label
 $('#mySwitch').bootstrapSwitch('setOffLabel', offValue); // sets the text of the "off" label
 $('#mySwitch').bootstrapSwitch('setOffLabel', offValue); // sets the text of the "off" label
+$('#mySwitch').bootstrapSwitch('setTextLabel', labelValue); // sets the text of the middle label
+$('#mySwitch').bootstrapSwitch('setIconLabel', iconValue); // sets the icon of the middle label
 $('#mySwitch').bootstrapSwitch('setOnClass', onClass); // sets the left color class
 $('#mySwitch').bootstrapSwitch('setOnClass', onClass); // sets the left color class
 $('#mySwitch').bootstrapSwitch('setOffClass', offClass); // sets the right color class
 $('#mySwitch').bootstrapSwitch('setOffClass', offClass); // sets the right color class
 $('#mySwitch').bootstrapSwitch('setAnimated', animated); // sets true or false for animation
 $('#mySwitch').bootstrapSwitch('setAnimated', animated); // sets true or false for animation

+ 5 - 0
examples/index.html

@@ -344,6 +344,9 @@ $('#label-switch').bootstrapSwitch('setOffLabel', 'O');</pre>
 &lt;div class="make-switch" data-text-label="TV">
 &lt;div class="make-switch" data-text-label="TV">
     &lt;input type="checkbox" checked>
     &lt;input type="checkbox" checked>
 &lt;/div></pre>
 &lt;/div></pre>
+            <pre class="prettyprint linenums">
+$('#label-text-switch').bootstrapSwitch('setTextLabel', 'Radio');</pre>
+        </div>
         </div>
         </div>
     </div>
     </div>
 
 
@@ -405,6 +408,8 @@ $('#label-switch').bootstrapSwitch('setOffLabel', 'O');</pre>
 &lt;div class="make-switch" data-label-icon="fui-video" data-on-label="&lt;i class='fui-check icon-white'>&lt;/i>" data-off-label="&lt;i class='fui-cross'>&lt;/i>">
 &lt;div class="make-switch" data-label-icon="fui-video" data-on-label="&lt;i class='fui-check icon-white'>&lt;/i>" data-off-label="&lt;i class='fui-cross'>&lt;/i>">
     &lt;input type="checkbox" checked>
     &lt;input type="checkbox" checked>
 &lt;/div></pre>
 &lt;/div></pre>
+            <pre class="prettyprint linenums">
+$('#label-icon-switch').bootstrapSwitch('setIconLabel', 'icon-remove');</pre>
         </div>
         </div>
     </div>
     </div>
 
 

+ 18 - 6
static/js/bootstrap-switch.js

@@ -42,7 +42,7 @@
 
 
             $element.addClass('has-switch');
             $element.addClass('has-switch');
 
 
-            if ($element.data('on') !== undefined)
+            if ($element.data('on'))
               color = "switch-" + $element.data('on');
               color = "switch-" + $element.data('on');
 
 
             if ($element.data('on-label') !== undefined)
             if ($element.data('on-label') !== undefined)
@@ -64,7 +64,7 @@
               .html(onLabel);
               .html(onLabel);
 
 
             color = '';
             color = '';
-            if ($element.data('off') !== undefined)
+            if ($element.data('off'))
               color = "switch-" + $element.data('off');
               color = "switch-" + $element.data('off');
 
 
             $switchRight = $('<span>')
             $switchRight = $('<span>')
@@ -292,11 +292,13 @@
       setOnClass: function (value) {
       setOnClass: function (value) {
         var $switchLeft = $(this).find(".switch-left");
         var $switchLeft = $(this).find(".switch-left");
         var color = '';
         var color = '';
-        if (value !== undefined) {
+        if (value) {
+          // Delete the old color
           if ($(this).attr('data-on') !== undefined) {
           if ($(this).attr('data-on') !== undefined) {
-            color = "switch-" + $(this).attr('data-on')
+            color = "switch-" + $(this).attr('data-on');
           }
           }
           $switchLeft.removeClass(color);
           $switchLeft.removeClass(color);
+          // Add the new color
           color = "switch-" + value;
           color = "switch-" + value;
           $switchLeft.addClass(color);
           $switchLeft.addClass(color);
         }
         }
@@ -304,11 +306,13 @@
       setOffClass: function (value) {
       setOffClass: function (value) {
         var $switchRight = $(this).find(".switch-right");
         var $switchRight = $(this).find(".switch-right");
         var color = '';
         var color = '';
-        if (value !== undefined) {
+        if (value) {
+          // Delete the old color
           if ($(this).attr('data-off') !== undefined) {
           if ($(this).attr('data-off') !== undefined) {
-            color = "switch-" + $(this).attr('data-off')
+            color = "switch-" + $(this).attr('data-off');
           }
           }
           $switchRight.removeClass(color);
           $switchRight.removeClass(color);
+          // Add the new color
           color = "switch-" + value;
           color = "switch-" + value;
           $switchRight.addClass(color);
           $switchRight.addClass(color);
         }
         }
@@ -342,6 +346,14 @@
           }
           }
         });
         });
       },
       },
+      setTextLabel: function(value) {
+        var $label = $(this).find("label");
+        $label.html('' + value || '&nbsp' + '');
+      },
+      setTextIcon: function(value) {
+        var $label = $(this).find("label");''
+        $label.html(value ? '<i class="icon ' + value + '"></i>' : '&nbsp;');
+      },
       status: function () {
       status: function () {
         return $(this).find(inputSelector).is(':checked');
         return $(this).find(inputSelector).is(':checked');
       },
       },

File diff suppressed because it is too large
+ 0 - 0
static/js/bootstrap-switch.min.js


Some files were not shown because too many files changed in this diff