From 8e68ac9de8889d555c48db24dcdbfb3cf8091f24 Mon Sep 17 00:00:00 2001 From: Hugh Anderson Date: Thu, 4 May 2017 21:30:16 -0400 Subject: [PATCH] Fix unclickable switch center This change fixes a long-standing issue with the white portion of the Off switch being not clickable. Issues reported on it here: https://github.com/Bttstrp/bootstrap-switch/issues/481 and here: https://github.com/Bttstrp/bootstrap-switch/issues/628 and here, all the same bug, reported since couple of years https://github.com/Bttstrp/bootstrap-switch/issues/467 Plunker to demonstrate bug (uses existing code) https://plnkr.co/edit/wXJvctugqNAx00rgUfeg?p=preview Plunker to demonstrate fix (uses this fork) https://plnkr.co/edit/DY1Icvv4HyDi2D0PkfdU?p=preview When using these Plunkers, set the switch to Off state. Try clicking on the white part of the switch (the part that doesn't say "Off") - notice that it does not switch off in the first Plunker (with bug) and that it correctly switches off in the second Plunker (with my fix) --- src/js/bootstrap-switch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/bootstrap-switch.js b/src/js/bootstrap-switch.js index 32af33de..009f0b30 100644 --- a/src/js/bootstrap-switch.js +++ b/src/js/bootstrap-switch.js @@ -508,7 +508,7 @@ class BootstrapSwitch { if (this._dragStart == null) { return } const difference = (event.pageX || event.originalEvent.touches[0].pageX) - this._dragStart event.preventDefault() - if (difference < -this._handleWidth || difference > 0) { return } + if (difference <= -this._handleWidth || difference > 0) { return } this._dragEnd = difference this.$container.css('margin-left', `${this._dragEnd}px`) },