Przeglądaj źródła

Merge pull request #14 from BdMdesigN/Test

Merge Test nach master
Stein, Peter 11 lat temu
rodzic
commit
5df832059b

+ 16 - 6
examples/index.html

@@ -207,6 +207,22 @@
     </div>
 </div>
 
+<div class="row-fluid">
+    <div class="span12">
+        <h3>HTML text (mini-switch)</h3>
+
+        <div class="bs-docs-example">
+            <div class="switch switch-mini" data-on-label="<i class='switch-mini-icons icon-ok icon-white'></i>" data-off-label="<i class='switch-mini-icons icon-remove'></i>">
+                <input type="checkbox" checked />
+            </div>
+        </div>
+        <pre class="prettyprint linenums">
+&lt;div class="switch switch-mini" data-on-label="&lt;i class='switch-mini-icons icon-ok icon-white'>&lt;/i>" data-off-label="&lt;i class='switch-mini-icons icon-remove'>&lt;/i>">
+    &lt;input type="checkbox" checked />
+&lt;/div></pre>
+    </div>
+</div>
+
 <div class="row-fluid">
     <div class="span12">
         <h3>Event handler <small>javascript</small></h3>
@@ -247,7 +263,6 @@ $('#toggle-state-switch').bootstrapSwitch('setState', false); // true || false</
     </div>
 </div>
 
-
 <div class="row-fluid">
     <div class="span12">
         <h3>Destroy <small>javascript</small></h3>
@@ -281,7 +296,6 @@ $('#create-switch').wrap('&lt;div class="switch" />').parent().bootstrapSwitch()
     </div>
 </div>
 
-
 <div class="row-fluid">
     <div class="span12">
         <h3>Disabled <small>javascript</small></h3>
@@ -313,7 +327,6 @@ $('#disable-switch').bootstrapSwitch('setActive', false);  // true || false</pre
     </div>
 </div>
 
-
 <div class="row-fluid">
     <div class="span12">
         <h3>Radio <small>javascript</small></h3>
@@ -371,7 +384,6 @@ $('#disable-switch').bootstrapSwitch('setActive', false);  // true || false</pre
     </div>
 </div>
 
-
 <div class="row-fluid">
     <div class="span12">
         <h3>Radio <small>javascript (allow radios uncheck)</small></h3>
@@ -421,7 +433,6 @@ $('#disable-switch').bootstrapSwitch('setActive', false);  // true || false</pre
     </div>
 </div>
 
-
 <div class="row-fluid">
     <div class="span12">
         <h3>Form <small>- try to use tab, space and reset button</small></h3>
@@ -516,7 +527,6 @@ $('#disable-switch').bootstrapSwitch('setActive', false);  // true || false</pre
 </p>
 </div>
 
-
 <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
     <div class="modal-header">
         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

+ 13 - 12
static/js/bootstrap-switch.js

@@ -16,6 +16,7 @@
   "use strict";
 
   $.fn['bootstrapSwitch'] = function (method) {
+    var inputSelector = 'input[type!="hidden"]';
     var methods = {
       init: function () {
         return this.each(function () {
@@ -71,13 +72,13 @@
             $label = $('<label>')
               .html("&nbsp;")
               .addClass(myClasses)
-              .attr('for', $element.find('input[type!="hidden"]').attr('id'));
+              .attr('for', $element.find(inputSelector).attr('id'));
 
             if (icon) {
               $label.html('<i class="icon icon-' + icon + '"></i>');
             }
 
-            $div = $element.find('input[type!="hidden"]').wrap($('<div>')).parent().data('animated', false);
+            $div = $element.find(inputSelector).wrap($('<div>')).parent().data('animated', false);
 
             if ($element.data('animated') !== false)
               $div.addClass('switch-animate').data('animated', true);
@@ -88,10 +89,10 @@
               .append($switchRight);
 
             $element.find('>div').addClass(
-              $element.find('input[type!="hidden"]').is(':checked') ? 'switch-on' : 'switch-off'
+              $element.find(inputSelector).is(':checked') ? 'switch-on' : 'switch-off'
             );
 
-            if ($element.find('input[type!="hidden"]').is(':disabled'))
+            if ($element.find(inputSelector).is(':disabled'))
               $(this).addClass('deactivate');
 
             var changeStatus = function ($this) {
@@ -114,7 +115,7 @@
               changeStatus($(this));
             });
 
-            $element.find('input[type!="hidden"]').on('change', function (e, skipOnChange) {
+            $element.find(inputSelector).on('change', function (e, skipOnChange) {
               var $this = $(this)
                 , $element = $this.parent()
                 , thisState = $this.is(':checked')
@@ -216,8 +217,8 @@
               $form.bind('reset', function () {
                 setTimeout(function () {
                   $form.find('.switch').each(function () {
-                    var $input = $(this).find('input[type!="hidden"]');
-                    
+                    var $input = $(this).find(inputSelector);
+
                     $input.prop('checked', $input.is(':checked')).trigger('change');
                   });
                 }, 1);
@@ -231,7 +232,7 @@
         var $this = $(this);
 
         $this.toggleClass('deactivate');
-        $this.find('input[type!="hidden"]').prop('disabled', $this.is('.deactivate'));
+        $this.find(inputSelector).prop('disabled', $this.is('.deactivate'));
       },
       isActive: function () {
         return !$(this).hasClass('deactivate');
@@ -241,11 +242,11 @@
 
         if (active) {
           $this.removeClass('deactivate');
-          $this.find('input[type!="hidden"]').removeAttr('disabled');
+          $this.find(inputSelector).removeAttr('disabled');
         }
         else {
           $this.addClass('deactivate');
-          $this.find('input[type!="hidden"]').attr('disabled', 'disabled');
+          $this.find(inputSelector).attr('disabled', 'disabled');
         }
       },
       toggleState: function (skipOnChange) {
@@ -266,10 +267,10 @@
         }
       },
       setState: function (value, skipOnChange) {
-        $(this).find('input[type!="hidden"]').prop('checked', value).trigger('change', skipOnChange);
+        $(this).find(inputSelector).prop('checked', value).trigger('change', skipOnChange);
       },
       status: function () {
-        return $(this).find('input[type!="hidden"]').is(':checked');
+        return $(this).find(inputSelector).is(':checked');
       },
       destroy: function () {
         var $element = $(this)

+ 13 - 0
static/stylesheets/bootstrap-switch.css

@@ -33,6 +33,19 @@
 .has-switch.switch-mini {
   min-width: 72px;
 }
+.has-switch.switch-mini i.switch-mini-icons {
+  height: 1.20em;
+  min-height: 5px;
+  line-height: 8px;
+  padding-bottom: 0px;
+  padding-top: 0px;
+  vertical-align: text-top;
+  text-align: center;
+  transform: scale(0.6);
+  margin-top: -1px;
+  margin-bottom: -1px;
+  z-index: 500;
+}
 .has-switch.switch-small {
   min-width: 80px;
 }