From 0a696fd5d499424dd00db22fc659509517bbd6a6 Mon Sep 17 00:00:00 2001 From: Gareth Blain Date: Fri, 29 Apr 2016 12:38:09 +0100 Subject: [PATCH] I used a modified nietha's solution from this ticket (https://github.com/minhur/bootstrap-toggle/issues/106) to fix the issue with the toggle's size being 0 (height and width) when the toggle was hidden on creation/setup. --- js/bootstrap-toggle.js | 360 ++++++++++++++++++++++------------------- 1 file changed, 195 insertions(+), 165 deletions(-) diff --git a/js/bootstrap-toggle.js b/js/bootstrap-toggle.js index 533914e..04e216e 100644 --- a/js/bootstrap-toggle.js +++ b/js/bootstrap-toggle.js @@ -8,173 +8,203 @@ +function ($) { - 'use strict'; - - // TOGGLE PUBLIC CLASS DEFINITION - // ============================== - - var Toggle = function (element, options) { - this.$element = $(element) - this.options = $.extend({}, this.defaults(), options) - this.render() - } - - Toggle.VERSION = '2.2.0' - - Toggle.DEFAULTS = { - on: 'On', - off: 'Off', - onstyle: 'primary', - offstyle: 'default', - size: 'normal', - style: '', - width: null, - height: null - } - - Toggle.prototype.defaults = function() { - return { - on: this.$element.attr('data-on') || Toggle.DEFAULTS.on, - off: this.$element.attr('data-off') || Toggle.DEFAULTS.off, - onstyle: this.$element.attr('data-onstyle') || Toggle.DEFAULTS.onstyle, - offstyle: this.$element.attr('data-offstyle') || Toggle.DEFAULTS.offstyle, - size: this.$element.attr('data-size') || Toggle.DEFAULTS.size, - style: this.$element.attr('data-style') || Toggle.DEFAULTS.style, - width: this.$element.attr('data-width') || Toggle.DEFAULTS.width, - height: this.$element.attr('data-height') || Toggle.DEFAULTS.height - } - } - - Toggle.prototype.render = function () { - this._onstyle = 'btn-' + this.options.onstyle - this._offstyle = 'btn-' + this.options.offstyle - var size = this.options.size === 'large' ? 'btn-lg' - : this.options.size === 'small' ? 'btn-sm' - : this.options.size === 'mini' ? 'btn-xs' - : '' - var $toggleOn = $('