From 58a9b89a654afabe671b562744e3734aa6061fc8 Mon Sep 17 00:00:00 2001 From: asomani Date: Fri, 4 Mar 2016 20:32:39 +0530 Subject: [PATCH] @trivial Ideally, A min width of switch must be maintained. If the parent div is hidden when the widget is initialized, The width of switch is set to 0. This can happen whenever width() returns incorrect value, which is well documented to be because of a number of reasons, like, display: block, width in %, input is hidden. --- jquery.switchbutton.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jquery.switchbutton.js b/jquery.switchbutton.js index 19757a7..d2bd728 100644 --- a/jquery.switchbutton.js +++ b/jquery.switchbutton.js @@ -222,8 +222,12 @@ _autoResize: function() { var onLabelWidth = this.$enabledLabel.width(), - offLabelWidth = this.$disabledLabel.width(), - spanPadding = this.$disabledSpan.innerWidth() - this.$disabledSpan.width() + offLabelWidth = this.$disabledLabel.width(); + //If width() return 0, then the min width of switch is maintained for default value. + if(offLabelWidth === 0) { + offLabelWidth = 32; + } + var spanPadding = this.$disabledSpan.innerWidth() - this.$disabledSpan.width(), handleMargins = this.$handle.outerWidth() - this.$handle.innerWidth(); var containerWidth = handleWidth = (onLabelWidth > offLabelWidth) ? onLabelWidth : offLabelWidth;