Skip to content

Commit 2624eea

Browse files
author
Emanuele Marchi
committed
flicker on initialisation fix
1 parent d2dd44a commit 2624eea

File tree

4 files changed

+68
-36
lines changed

4 files changed

+68
-36
lines changed

dist/js/bootstrap-switch.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
var BootstrapSwitch;
2828
BootstrapSwitch = (function() {
2929
function BootstrapSwitch(element, options) {
30-
var initInterval;
3130
if (options == null) {
3231
options = {};
3332
}
@@ -110,19 +109,7 @@
110109
if (this.options.indeterminate) {
111110
this.$element.prop("indeterminate", true);
112111
}
113-
initInterval = window.setInterval((function(_this) {
114-
return function() {
115-
if (_this.$wrapper.is(":visible")) {
116-
_this._width();
117-
_this._containerPosition(null, function() {
118-
if (_this.options.animate) {
119-
return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
120-
}
121-
});
122-
return window.clearInterval(initInterval);
123-
}
124-
};
125-
})(this), 50);
112+
this._init();
126113
this._elementHandlers();
127114
this._handleHandlers();
128115
this._labelHandlers();
@@ -475,6 +462,31 @@
475462
}, 50);
476463
};
477464

465+
BootstrapSwitch.prototype._init = function() {
466+
var init, initInterval;
467+
init = (function(_this) {
468+
return function() {
469+
_this._width();
470+
return _this._containerPosition(null, function() {
471+
if (_this.options.animate) {
472+
return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
473+
}
474+
});
475+
};
476+
})(this);
477+
if (this.$wrapper.is(":visible")) {
478+
return init();
479+
}
480+
return initInterval = window.setInterval((function(_this) {
481+
return function() {
482+
if (_this.$wrapper.is(":visible")) {
483+
init();
484+
return window.clearInterval(initInterval);
485+
}
486+
};
487+
})(this), 50);
488+
};
489+
478490
BootstrapSwitch.prototype._elementHandlers = function() {
479491
return this.$element.on({
480492
"change.bootstrapSwitch": (function(_this) {

0 commit comments

Comments
 (0)