Browse Source

Merge branch 'master' of git://github.com/nostalgiaz/bootstrap-switch.git

Aimeast 12 years ago
parent
commit
4211129bb1

+ 8 - 4
README.md

@@ -11,10 +11,10 @@ Just include Twitter Bootstrap, jQuery, Bootstrap Switch CSS and Javascript
 ``` html
 ``` html
 <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8;" />
 <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8;" />
 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
-<link rel="stylesheet" href="bootstrapSwitch.css">
+<link rel="stylesheet" href="bootstrap-switch.css">
 
 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
-<script src="bootstrapSwitch.js"></script>  // master
+<script src="bootstrap-switch.js"></script>  // master
 <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/1.3/bootstrapSwitch.min.js">  // from cdnjs.com
 <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/1.3/bootstrapSwitch.min.js">  // from cdnjs.com
 ```
 ```
 
 
@@ -22,9 +22,13 @@ Less
 ----
 ----
 If you want to use your bootstrap vars edit bootstrapSwitch.less and then compile the less file
 If you want to use your bootstrap vars edit bootstrapSwitch.less and then compile the less file
 ``` bash
 ``` bash
-lessc static/less/bootstrapSwitch.less static/stylesheets/bootstrapSwitch.css
+lessc static/less/bootstrap-switch.less static/stylesheets/bootstrap-switch.css
 ```
 ```
 
 
+Supported browsers
+------------------
+I'm not going to support ancient browsers! (it works on IE8+)
+
 Basic Example
 Basic Example
 -------------
 -------------
 ``` html
 ``` html
@@ -44,7 +48,7 @@ Large, small or mini
 Colors
 Colors
 ------
 ------
 ``` html
 ``` html
-<div class="switch" data-on="danger" data-off="warning">  <!-- primary, info, success, warning and danger -->
+<div class="switch" data-on="danger" data-off="warning">  <!-- primary, info, success, warning, danger and default -->
     <input type="checkbox">
     <input type="checkbox">
 </div>
 </div>
 ```
 ```

+ 18 - 5
examples/index.html

@@ -7,7 +7,7 @@
     <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8;" />
     <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8;" />
 
 
     <link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
     <link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
-    <link rel="stylesheet" href="../static/stylesheets/bootstrapSwitch.css">
+    <link rel="stylesheet" href="../static/stylesheets/bootstrap-switch.css">
     <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css">
     <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css">
     <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/docs.css">
     <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/docs.css">
 
 
@@ -108,7 +108,10 @@
             <div class="switch" data-on="warning" data-off="danger">
             <div class="switch" data-on="warning" data-off="danger">
                 <input type="checkbox" checked />
                 <input type="checkbox" checked />
             </div>
             </div>
-            <div class="switch" data-on="danger" data-off="primary">
+            <div class="switch" data-on="danger" data-off="default">
+                <input type="checkbox" checked />
+            </div>
+            <div class="switch" data-on="default" data-off="primary">
                 <input type="checkbox" checked />
                 <input type="checkbox" checked />
             </div>
             </div>
         </div>
         </div>
@@ -129,7 +132,10 @@
     &lt;input type="checkbox" checked />
     &lt;input type="checkbox" checked />
 &lt;/div>
 &lt;/div>
 
 
-&lt;div class="switch" data-on="danger" data-off="primary">
+&lt;div class="switch" data-on="danger" data-off="default">
+    &lt;input type="checkbox" checked />
+&lt;/div>
+&lt;div class="switch" data-on="default" data-off="primary">
     &lt;input type="checkbox" checked />
     &lt;input type="checkbox" checked />
 &lt;/div>
 &lt;/div>
 </pre>
 </pre>
@@ -228,11 +234,13 @@ $('#mySwitch').on('switch-change', function (e, data) {
             </div>
             </div>
             <br>
             <br>
             <br>
             <br>
+            <div id="toggle-state-switch-button-status" class="btn btn-primary">Status!</div>
             <div id="toggle-state-switch-button-on" class="btn btn-primary">ON!</div>
             <div id="toggle-state-switch-button-on" class="btn btn-primary">ON!</div>
             <div id="toggle-state-switch-button" class="btn btn-primary">Toggle me!</div>
             <div id="toggle-state-switch-button" class="btn btn-primary">Toggle me!</div>
             <div id="toggle-state-switch-button-off" class="btn btn-primary">OFF!</div>
             <div id="toggle-state-switch-button-off" class="btn btn-primary">OFF!</div>
         </div>
         </div>
         <pre class="prettyprint linenums">
         <pre class="prettyprint linenums">
+$('#toggle-state-switch').bootstrapSwitch('status'); // true || false
 $('#toggle-state-switch').bootstrapSwitch('toggleState');
 $('#toggle-state-switch').bootstrapSwitch('toggleState');
 $('#toggle-state-switch').bootstrapSwitch('setState', false); // true || false</pre>
 $('#toggle-state-switch').bootstrapSwitch('setState', false); // true || false</pre>
     </div>
     </div>
@@ -278,8 +286,9 @@ $('#create-switch').wrap('&lt;div class="switch" />').parent().bootstrapSwitch()
         <h3>Disabled <small>javascript</small></h3>
         <h3>Disabled <small>javascript</small></h3>
 
 
         <div class="bs-docs-example">
         <div class="bs-docs-example">
+            <label for="disable-switch-input">amazing label</label>
             <div id="disable-switch" class="switch">
             <div id="disable-switch" class="switch">
-                <input type="checkbox" checked />
+                <input id="disable-switch-input" type="checkbox" checked />
             </div>
             </div>
             <br>
             <br>
             <br>
             <br>
@@ -409,7 +418,7 @@ $('#disable-switch').bootstrapSwitch('setActive', false);  // true || false</pre
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
 <script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
 <script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
 <script src="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.js"></script>
 <script src="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.js"></script>
-<script src="../static/js/bootstrapSwitch.js"></script>
+<script src="../static/js/bootstrap-switch.js"></script>
 <script>
 <script>
     window.prettyPrint && prettyPrint();
     window.prettyPrint && prettyPrint();
     $('#mySwitch').on('switch-change', function (e, data) {
     $('#mySwitch').on('switch-change', function (e, data) {
@@ -426,6 +435,10 @@ $('#disable-switch').bootstrapSwitch('setActive', false);  // true || false</pre
         $('#toggle-state-switch').bootstrapSwitch('setState', true);
         $('#toggle-state-switch').bootstrapSwitch('setState', true);
     });
     });
 
 
+    $('#toggle-state-switch-button-status').on('click', function () {
+        alert($('#toggle-state-switch').bootstrapSwitch('status'));
+    });
+
     $('#toggle-state-switch-button-off').on('click', function () {
     $('#toggle-state-switch-button-off').on('click', function () {
         $('#toggle-state-switch').bootstrapSwitch('setState', false);
         $('#toggle-state-switch').bootstrapSwitch('setState', false);
     });
     });

+ 15 - 5
static/js/bootstrapSwitch.js → static/js/bootstrap-switch.js

@@ -1,5 +1,5 @@
 /* ============================================================
 /* ============================================================
- * bootstrapSwitch v1.3 by Larentis Mattia @spiritualGuru
+ * bootstrapSwitch v1.4 by Larentis Mattia @spiritualGuru
  * http://www.larentis.eu/switch/
  * http://www.larentis.eu/switch/
  * ============================================================
  * ============================================================
  * Licensed under the Apache License, Version 2.0
  * Licensed under the Apache License, Version 2.0
@@ -218,15 +218,25 @@
         );
         );
       },
       },
       toggleActivation: function () {
       toggleActivation: function () {
-        $(this).toggleClass('deactivate');
+        var $this = $(this);
+
+        $this.toggleClass('deactivate');
+        $this.find('input:checkbox').attr('disabled', $this.is('.deactivate'));
       },
       },
       isActive: function () {
       isActive: function () {
         return !$(this).hasClass('deactivate');
         return !$(this).hasClass('deactivate');
       },
       },
       setActive: function (active) {
       setActive: function (active) {
-        if (active)
-          $(this).removeClass('deactivate');
-        else $(this).addClass('deactivate');
+        var $this = $(this);
+
+        if (active) {
+          $this.removeClass('deactivate');
+          $this.find('input:checkbox').attr('disabled', false);
+        }
+        else {
+          $this.addClass('deactivate');
+          $this.find('input:checkbox').attr('disabled', true);
+        }
       },
       },
       toggleState: function (skipOnChange) {
       toggleState: function (skipOnChange) {
         var $input = $(this).find('input:checkbox');
         var $input = $(this).find('input:checkbox');

+ 5 - 1
static/less/bootstrapSwitch.less → static/less/bootstrap-switch.less

@@ -1,5 +1,5 @@
 /* ============================================================
 /* ============================================================
- * bootstrapSwitch v1.3 by Larentis Mattia @spiritualGuru
+ * bootstrapSwitch v1.4 by Larentis Mattia @spiritualGuru
  * http://www.larentis.eu/switch/
  * http://www.larentis.eu/switch/
  * ============================================================
  * ============================================================
  * Licensed under the Apache License, Version 2.0
  * Licensed under the Apache License, Version 2.0
@@ -152,5 +152,9 @@
     &.switch-danger {
     &.switch-danger {
       .buttonBackground(@btnDangerBackgroundHighlight, @btnDangerBackground);
       .buttonBackground(@btnDangerBackgroundHighlight, @btnDangerBackground);
     }
     }
+
+    &.switch-default {
+      .buttonBackground(@btnBackgroundHighlight, @btnBackground, @grayDark, 0 1px 1px rgba(255,255,255,.75));
+    }
   }
   }
 }
 }

+ 33 - 1
static/stylesheets/bootstrapSwitch.css → static/stylesheets/bootstrap-switch.css

@@ -1,5 +1,5 @@
 /* ============================================================
 /* ============================================================
- * bootstrapSwitch v1.2 by Larentis Mattia @spiritualGuru
+ * bootstrapSwitch v1.3 by Larentis Mattia @spiritualGuru
  * http://www.larentis.eu/switch/
  * http://www.larentis.eu/switch/
  * ============================================================
  * ============================================================
  * Licensed under the Apache License, Version 2.0
  * Licensed under the Apache License, Version 2.0
@@ -357,3 +357,35 @@
 .has-switch span.switch-danger.active {
 .has-switch span.switch-danger.active {
   background-color: #e9322d \9;
   background-color: #e9322d \9;
 }
 }
+.has-switch span.switch-default {
+  color: #333333;
+  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
+  background-color: #f0f0f0;
+  background-image: -moz-linear-gradient(top, #e6e6e6, #ffffff);
+  background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#e6e6e6), to(#ffffff));
+  background-image: -webkit-linear-gradient(top, #e6e6e6, #ffffff);
+  background-image: -o-linear-gradient(top, #e6e6e6, #ffffff);
+  background-image: linear-gradient(to bottom, #e6e6e6, #ffffff);
+  background-repeat: repeat-x;
+  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffe6e6e6', endColorstr='#ffffffff', GradientType=0);
+  border-color: #ffffff #ffffff #d9d9d9;
+  border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
+  *background-color: #ffffff;
+  /* Darken IE7 buttons by default so they stand out more given they won't have borders */
+
+  filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
+}
+.has-switch span.switch-default:hover,
+.has-switch span.switch-default:focus,
+.has-switch span.switch-default:active,
+.has-switch span.switch-default.active,
+.has-switch span.switch-default.disabled,
+.has-switch span.switch-default[disabled] {
+  color: #333333;
+  background-color: #ffffff;
+  *background-color: #f2f2f2;
+}
+.has-switch span.switch-default:active,
+.has-switch span.switch-default.active {
+  background-color: #e6e6e6 \9;
+}