Ver código fonte

Merge pull request #322 from root-talis/develop

Added "radioAllOff" option.
Emanuele Marchi 11 anos atrás
pai
commit
c830dce60b

+ 12 - 2
dist/js/bootstrap-switch.js

@@ -44,7 +44,8 @@
           offText: this.$element.data("off-text"),
           offText: this.$element.data("off-text"),
           labelText: this.$element.data("label-text"),
           labelText: this.$element.data("label-text"),
           baseClass: this.$element.data("base-class"),
           baseClass: this.$element.data("base-class"),
-          wrapperClass: this.$element.data("wrapper-class")
+          wrapperClass: this.$element.data("wrapper-class"),
+          radioAllOff: this.$element.data("radio-all-off")
         }, options);
         }, options);
         this.$wrapper = $("<div>", {
         this.$wrapper = $("<div>", {
           "class": (function(_this) {
           "class": (function(_this) {
@@ -120,7 +121,7 @@
         if (this.options.disabled || this.options.readonly || this.options.indeterminate) {
         if (this.options.disabled || this.options.readonly || this.options.indeterminate) {
           return this.$element;
           return this.$element;
         }
         }
-        if (this.options.state && this.$element.is(':radio')) {
+        if (this.options.state && !this.options.radioAllOff && this.$element.is(':radio')) {
           return this.$element;
           return this.$element;
         }
         }
         value = !!value;
         value = !!value;
@@ -285,6 +286,14 @@
         return this.$element;
         return this.$element;
       };
       };
 
 
+      BootstrapSwitch.prototype.radioAllOff = function(value) {
+        if (typeof value === "undefined") {
+          return this.options.radioAllOff;
+        }
+        this.options.radioAllOff = value;
+        return this.$element;
+      };
+
       BootstrapSwitch.prototype.onInit = function(value) {
       BootstrapSwitch.prototype.onInit = function(value) {
         if (typeof value === "undefined") {
         if (typeof value === "undefined") {
           return this.options.onInit;
           return this.options.onInit;
@@ -514,6 +523,7 @@
       labelText: "&nbsp;",
       labelText: "&nbsp;",
       baseClass: "bootstrap-switch",
       baseClass: "bootstrap-switch",
       wrapperClass: "wrapper",
       wrapperClass: "wrapper",
+      radioAllOff: false,
       onInit: function() {},
       onInit: function() {},
       onSwitchChange: function() {}
       onSwitchChange: function() {}
     };
     };

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/js/bootstrap-switch.min.js


+ 9 - 0
documentation-3.html

@@ -111,6 +111,7 @@
             </tr>
             </tr>
             <tr>
             <tr>
               <td>indeterminate</td>
               <td>indeterminate</td>
+              <td></td>
               <td>Boolean</td>
               <td>Boolean</td>
               <td>indeterminate state</td>
               <td>indeterminate state</td>
               <td>true, false</td>
               <td>true, false</td>
@@ -192,6 +193,14 @@
                 <pre><code class="javascript">function(event, state) {}</code></pre>
                 <pre><code class="javascript">function(event, state) {}</code></pre>
               </td>
               </td>
             </tr>
             </tr>
+            <tr>
+              <td>radioAllOff</td>
+              <td>data-radio-all-off</td>
+              <td>Boolean</td>
+              <td>Allow this radio button to be unchecked by the user</td>
+              <td>true, false</td>
+              <td>false</td>
+            </tr>
           </tbody>
           </tbody>
         </table>
         </table>
         <h3>Global Defaults Overriding</h3>
         <h3>Global Defaults Overriding</h3>

+ 9 - 1
src/coffee/bootstrap-switch.coffee

@@ -18,6 +18,7 @@ do ($ = window.jQuery, window) ->
         labelText: @$element.data "label-text"
         labelText: @$element.data "label-text"
         baseClass: @$element.data "base-class"
         baseClass: @$element.data "base-class"
         wrapperClass: @$element.data "wrapper-class"
         wrapperClass: @$element.data "wrapper-class"
+        radioAllOff: @$element.data "radio-all-off"
       , options
       , options
       @$wrapper = $ "<div>",
       @$wrapper = $ "<div>",
         class: do =>
         class: do =>
@@ -73,7 +74,7 @@ do ($ = window.jQuery, window) ->
     state: (value, skip) ->
     state: (value, skip) ->
       return @options.state if typeof value is "undefined"
       return @options.state if typeof value is "undefined"
       return @$element if @options.disabled or @options.readonly or @options.indeterminate
       return @$element if @options.disabled or @options.readonly or @options.indeterminate
-      return @$element if @options.state and @$element.is ':radio'
+      return @$element if @options.state and not @options.radioAllOff and @$element.is ':radio'
 
 
       value = not not value
       value = not not value
 
 
@@ -204,6 +205,12 @@ do ($ = window.jQuery, window) ->
       @options.wrapperClass = value
       @options.wrapperClass = value
       @$element
       @$element
 
 
+    radioAllOff: (value) ->
+      return @options.radioAllOff if typeof value is "undefined"
+
+      @options.radioAllOff = value
+      @$element
+
     onInit: (value) ->
     onInit: (value) ->
       return @options.onInit if typeof value is "undefined"
       return @options.onInit if typeof value is "undefined"
 
 
@@ -378,6 +385,7 @@ do ($ = window.jQuery, window) ->
     labelText: "&nbsp;"
     labelText: "&nbsp;"
     baseClass: "bootstrap-switch"
     baseClass: "bootstrap-switch"
     wrapperClass: "wrapper"
     wrapperClass: "wrapper"
+    radioAllOff: false
     onInit: ->
     onInit: ->
     onSwitchChange: ->
     onSwitchChange: ->
 
 

+ 9 - 0
src/docs/documentation-3.jade

@@ -53,6 +53,7 @@ block content
           td false
           td false
         tr
         tr
           td indeterminate
           td indeterminate
+          td
           td Boolean
           td Boolean
           td indeterminate state
           td indeterminate state
           td true, false
           td true, false
@@ -120,6 +121,14 @@ block content
           td Callback function to execute on switch state change
           td Callback function to execute on switch state change
           td Function
           td Function
           td: pre: code.javascript function(event, state) {}
           td: pre: code.javascript function(event, state) {}
+        tr
+          td radioAllOff
+          td data-radio-all-off
+          td Boolean
+          td Allow this radio button to be unchecked by the user
+          td true, false
+          td false
+
 
 
     h3 Global Defaults Overriding
     h3 Global Defaults Overriding
 
 

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff