From 66ffa68210fdec09f53ac6b3f5c209be1ce7c166 Mon Sep 17 00:00:00 2001 From: openlife Date: Thu, 13 Sep 2012 16:09:59 +0300 Subject: [PATCH] Update jquery/iphone-style-checkboxes.js Fix bug of width when checkbox are hidden. Modification on function optionallyResize. --- jquery/iphone-style-checkboxes.js | 43 +++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/jquery/iphone-style-checkboxes.js b/jquery/iphone-style-checkboxes.js index 8339577..d9d4139 100644 --- a/jquery/iphone-style-checkboxes.js +++ b/jquery/iphone-style-checkboxes.js @@ -47,22 +47,33 @@ } }; iOSCheckbox.prototype.optionallyResize = function(mode) { - var newWidth, offLabelWidth, onLabelWidth; - onLabelWidth = this._getDimension(this.onLabel, "width"); - offLabelWidth = this._getDimension(this.offLabel, "width"); - if (mode === "container") { - newWidth = onLabelWidth > offLabelWidth ? onLabelWidth : offLabelWidth; - newWidth += this._getDimension(this.handle, "width") + this.handleMargin; - return this.container.css({ - width: newWidth - }); - } else { - newWidth = onLabelWidth > offLabelWidth ? onLabelWidth : offLabelWidth; - return this.handle.css({ - width: newWidth - }); - } - }; + var newWidth, offLabelWidth, onLabelWidth; + onLabelWidth = this._getDimension(this.onLabel, "width"); + offLabelWidth = this._getDimension(this.offLabel, "width"); + + //--- bugfix start ---- + if(onLabelWidth==0){ + var cloned=$(this.container).clone(); + cloned.appendTo('body').wrap('
'); + onLabelWidth = this._getDimension(cloned.find('.'+this.labelOnClass), "width"); + offLabelWidth = this._getDimension(cloned.find('.'+this.labelOffClass), "width"); + cloned.unwrap().remove(); + } + //--- bugfix end---- + + if (mode === "container") { + newWidth = onLabelWidth > offLabelWidth ? onLabelWidth : offLabelWidth; + newWidth += this._getDimension(this.handle, "width") + this.handleMargin; + return this.container.css({ + width: newWidth + }); + } else { + newWidth = onLabelWidth > offLabelWidth ? onLabelWidth : offLabelWidth; + return this.handle.css({ + width: newWidth + }); + } + }; iOSCheckbox.prototype.onMouseDown = function(event) { var x; event.preventDefault();