Permalink
Browse files

make sure input is a checkbox tp prevent other inputs (and hidden one…

…s) are not also wrapped.
  • Loading branch information...
1 parent 113b493 commit 0e2a51a196786a65f527ce793d38c7876a82a5d9 Stephan Ziep committed Nov 15, 2012
Showing with 12 additions and 9 deletions.
  1. +12 −9 static/js/jquery.toggle.buttons.js
@@ -15,6 +15,7 @@
$.fn.toggleButtons = function (method) {
var $element
, $div
+ , $cb
, transitionSpeed = 0.05
, methods = {
init: function (opt) {
@@ -51,12 +52,14 @@
$spanRight = $('<span></span>').addClass("labelRight").text(options.label.disabled === undefined ? "OFF " : options.label.disabled);
// html layout
- $div = $element.find('input:checkbox').wrap($('<div></div>')).parent();
+ $cb = $element.find('input:checkbox')
+
+ $div = $cb.wrap($('<div></div>')).parent();
$div.append($spanLeft);
- $div.append($('<label></label>').attr('for', $element.find('input').attr('id')));
+ $div.append($('<label></label>').attr('for', $cb.attr('id')));
$div.append($spanRight);
- if ($element.find('input').is(':checked'))
+ if ($cb.is(':checked'))
$element.find('>div').css('left', "0");
else $element.find('>div').css('left', "-50%");
@@ -88,7 +91,7 @@
.filter('span')
.css('line-height', options.height + "px");
- if ($element.find('input').is(':disabled'))
+ if ($cb.is(':disabled'))
$(this).addClass('deactivate');
$element.find('span').css(options.font);
@@ -134,7 +137,7 @@
changeStatus($(this));
});
- $('.toggle-button').find('input').on('change', function (e, skipOnChange) {
+ $('.toggle-button').find('input:checkbox').on('change', function (e, skipOnChange) {
var $element = $(this).parent()
, active = $(this).is(':checked')
, $toggleButton = $(this).closest('.toggle-button');
@@ -177,7 +180,7 @@
$(this).on('click touchend', function (e) {
var $target = $(e.target)
- , $myCheckBox = $target.siblings('input');
+ , $myCheckBox = $target.siblings('input:checkbox');
e.stopImmediatePropagation();
e.preventDefault();
@@ -193,7 +196,7 @@
});
$(this).on('mouseleave', function (e) {
- var $myCheckBox = $(this).siblings('input');
+ var $myCheckBox = $(this).siblings('input:checkbox');
e.preventDefault();
e.stopImmediatePropagation();
@@ -223,11 +226,11 @@
$(this).toggleClass('deactivate');
},
toggleState: function (skipOnChange) {
- var $input = $(this).find('input');
+ var $input = $(this).find('input:checkbox');
$input.attr('checked', !$input.is(':checked')).trigger('change', skipOnChange);
},
setState: function(value, skipOnChange) {
- $(this).find('input').attr('checked', value).trigger('change', skipOnChange);
+ $(this).find('input:checkbox').attr('checked', value).trigger('change', skipOnChange);
},
status: function () {
return $(this).find('input:checkbox').is(':checked');

0 comments on commit 0e2a51a

Please sign in to comment.