From 0d165ce69a5f920dde7ae43cadc7b127872a4050 Mon Sep 17 00:00:00 2001 From: ramaroberto Date: Sat, 8 Aug 2015 01:04:42 -0300 Subject: [PATCH 1/2] Fix #23 - Restores label basic functionality --- js/bootstrap-toggle.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/bootstrap-toggle.js b/js/bootstrap-toggle.js index 533914e..00049ef 100644 --- a/js/bootstrap-toggle.js +++ b/js/bootstrap-toggle.js @@ -33,6 +33,17 @@ } Toggle.prototype.defaults = function() { + if (this.$element.parent().prop('tagName') == 'LABEL') { + this.$element.parent().click( function(e) { + if (!$(e.toElement).hasClass('toggle-off') && + !$(e.toElement).hasClass('toggle-on')) { + var $checkbox = $(this) + .find('input[type=checkbox][data-toggle^=toggle]').first() + $checkbox.bootstrapToggle('toggle') + e.preventDefault() + } + }) + } return { on: this.$element.attr('data-on') || Toggle.DEFAULTS.on, off: this.$element.attr('data-off') || Toggle.DEFAULTS.off, From a943e4f051e6f60b0714339b94aaa437c39e3e2e Mon Sep 17 00:00:00 2001 From: ramaroberto Date: Thu, 13 Aug 2015 12:48:57 -0300 Subject: [PATCH 2/2] Added missing class --- js/bootstrap-toggle.js | 3 ++- js/bootstrap-toggle.min.js | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/bootstrap-toggle.js b/js/bootstrap-toggle.js index 00049ef..01298c0 100644 --- a/js/bootstrap-toggle.js +++ b/js/bootstrap-toggle.js @@ -36,7 +36,8 @@ if (this.$element.parent().prop('tagName') == 'LABEL') { this.$element.parent().click( function(e) { if (!$(e.toElement).hasClass('toggle-off') && - !$(e.toElement).hasClass('toggle-on')) { + !$(e.toElement).hasClass('toggle-on') && + !$(e.toElement).hasClass('toggle-handle')) { var $checkbox = $(this) .find('input[type=checkbox][data-toggle^=toggle]').first() $checkbox.bootstrapToggle('toggle') diff --git a/js/bootstrap-toggle.min.js b/js/bootstrap-toggle.min.js index 3711320..d00d2d2 100644 --- a/js/bootstrap-toggle.min.js +++ b/js/bootstrap-toggle.min.js @@ -1,9 +1,8 @@ -/*! ======================================================================== +/* ======================================================================== * Bootstrap Toggle: bootstrap-toggle.js v2.2.0 * http://www.bootstraptoggle.com * ======================================================================== * Copyright 2014 Min Hur, The New York Times Company * Licensed under MIT * ======================================================================== */ -+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.toggle"),f="object"==typeof b&&b;e||d.data("bs.toggle",e=new c(this,f)),"string"==typeof b&&e[b]&&e[b]()})}var c=function(b,c){this.$element=a(b),this.options=a.extend({},this.defaults(),c),this.render()};c.VERSION="2.2.0",c.DEFAULTS={on:"On",off:"Off",onstyle:"primary",offstyle:"default",size:"normal",style:"",width:null,height:null},c.prototype.defaults=function(){return{on:this.$element.attr("data-on")||c.DEFAULTS.on,off:this.$element.attr("data-off")||c.DEFAULTS.off,onstyle:this.$element.attr("data-onstyle")||c.DEFAULTS.onstyle,offstyle:this.$element.attr("data-offstyle")||c.DEFAULTS.offstyle,size:this.$element.attr("data-size")||c.DEFAULTS.size,style:this.$element.attr("data-style")||c.DEFAULTS.style,width:this.$element.attr("data-width")||c.DEFAULTS.width,height:this.$element.attr("data-height")||c.DEFAULTS.height}},c.prototype.render=function(){this._onstyle="btn-"+this.options.onstyle,this._offstyle="btn-"+this.options.offstyle;var b="large"===this.options.size?"btn-lg":"small"===this.options.size?"btn-sm":"mini"===this.options.size?"btn-xs":"",c=a('