浏览代码

flicker on initialisation fix

Emanuele Marchi 10 年之前
父节点
当前提交
2624eeae45
共有 4 个文件被更改,包括 67 次插入35 次删除
  1. 26 14
      dist/js/bootstrap-switch.js
  2. 0 0
      dist/js/bootstrap-switch.min.js
  3. 15 7
      src/coffee/bootstrap-switch.coffee
  4. 26 14
      test/bootstrap-switch.js

+ 26 - 14
dist/js/bootstrap-switch.js

@@ -27,7 +27,6 @@
     var BootstrapSwitch;
     var BootstrapSwitch;
     BootstrapSwitch = (function() {
     BootstrapSwitch = (function() {
       function BootstrapSwitch(element, options) {
       function BootstrapSwitch(element, options) {
-        var initInterval;
         if (options == null) {
         if (options == null) {
           options = {};
           options = {};
         }
         }
@@ -110,19 +109,7 @@
         if (this.options.indeterminate) {
         if (this.options.indeterminate) {
           this.$element.prop("indeterminate", true);
           this.$element.prop("indeterminate", true);
         }
         }
-        initInterval = window.setInterval((function(_this) {
-          return function() {
-            if (_this.$wrapper.is(":visible")) {
-              _this._width();
-              _this._containerPosition(null, function() {
-                if (_this.options.animate) {
-                  return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
-                }
-              });
-              return window.clearInterval(initInterval);
-            }
-          };
-        })(this), 50);
+        this._init();
         this._elementHandlers();
         this._elementHandlers();
         this._handleHandlers();
         this._handleHandlers();
         this._labelHandlers();
         this._labelHandlers();
@@ -475,6 +462,31 @@
         }, 50);
         }, 50);
       };
       };
 
 
+      BootstrapSwitch.prototype._init = function() {
+        var init, initInterval;
+        init = (function(_this) {
+          return function() {
+            _this._width();
+            return _this._containerPosition(null, function() {
+              if (_this.options.animate) {
+                return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
+              }
+            });
+          };
+        })(this);
+        if (this.$wrapper.is(":visible")) {
+          return init();
+        }
+        return initInterval = window.setInterval((function(_this) {
+          return function() {
+            if (_this.$wrapper.is(":visible")) {
+              init();
+              return window.clearInterval(initInterval);
+            }
+          };
+        })(this), 50);
+      };
+
       BootstrapSwitch.prototype._elementHandlers = function() {
       BootstrapSwitch.prototype._elementHandlers = function() {
         return this.$element.on({
         return this.$element.on({
           "change.bootstrapSwitch": (function(_this) {
           "change.bootstrapSwitch": (function(_this) {

文件差异内容过多而无法显示
+ 0 - 0
dist/js/bootstrap-switch.min.js


+ 15 - 7
src/coffee/bootstrap-switch.coffee

@@ -65,13 +65,7 @@ do ($ = window.jQuery, window) ->
       @$element.prop "indeterminate", true  if @options.indeterminate
       @$element.prop "indeterminate", true  if @options.indeterminate
 
 
       # normalize handles width and set container position
       # normalize handles width and set container position
-      initInterval = window.setInterval =>
-        if @$wrapper.is ":visible"
-          @_width()
-          @_containerPosition null, =>
-            @$wrapper.addClass "#{@options.baseClass}-animate"  if @options.animate
-          window.clearInterval initInterval
-      , 50
+      @_init()
 
 
       # initialise handlers
       # initialise handlers
       @_elementHandlers()
       @_elementHandlers()
@@ -348,6 +342,20 @@ do ($ = window.jQuery, window) ->
         callback()
         callback()
       , 50
       , 50
 
 
+    _init: ->
+      init = =>
+        @_width()
+        @_containerPosition null, =>
+          @$wrapper.addClass "#{@options.baseClass}-animate"  if @options.animate
+
+      return init()  if @$wrapper.is ":visible"
+
+      initInterval = window.setInterval =>
+        if @$wrapper.is ":visible"
+          init()
+          window.clearInterval initInterval
+      , 50
+
     _elementHandlers: ->
     _elementHandlers: ->
       @$element.on
       @$element.on
         "change.bootstrapSwitch": (e, skip) =>
         "change.bootstrapSwitch": (e, skip) =>

+ 26 - 14
test/bootstrap-switch.js

@@ -27,7 +27,6 @@
     var BootstrapSwitch;
     var BootstrapSwitch;
     BootstrapSwitch = (function() {
     BootstrapSwitch = (function() {
       function BootstrapSwitch(element, options) {
       function BootstrapSwitch(element, options) {
-        var initInterval;
         if (options == null) {
         if (options == null) {
           options = {};
           options = {};
         }
         }
@@ -110,19 +109,7 @@
         if (this.options.indeterminate) {
         if (this.options.indeterminate) {
           this.$element.prop("indeterminate", true);
           this.$element.prop("indeterminate", true);
         }
         }
-        initInterval = window.setInterval((function(_this) {
-          return function() {
-            if (_this.$wrapper.is(":visible")) {
-              _this._width();
-              _this._containerPosition(null, function() {
-                if (_this.options.animate) {
-                  return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
-                }
-              });
-              return window.clearInterval(initInterval);
-            }
-          };
-        })(this), 50);
+        this._init();
         this._elementHandlers();
         this._elementHandlers();
         this._handleHandlers();
         this._handleHandlers();
         this._labelHandlers();
         this._labelHandlers();
@@ -475,6 +462,31 @@
         }, 50);
         }, 50);
       };
       };
 
 
+      BootstrapSwitch.prototype._init = function() {
+        var init, initInterval;
+        init = (function(_this) {
+          return function() {
+            _this._width();
+            return _this._containerPosition(null, function() {
+              if (_this.options.animate) {
+                return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
+              }
+            });
+          };
+        })(this);
+        if (this.$wrapper.is(":visible")) {
+          return init();
+        }
+        return initInterval = window.setInterval((function(_this) {
+          return function() {
+            if (_this.$wrapper.is(":visible")) {
+              init();
+              return window.clearInterval(initInterval);
+            }
+          };
+        })(this), 50);
+      };
+
       BootstrapSwitch.prototype._elementHandlers = function() {
       BootstrapSwitch.prototype._elementHandlers = function() {
         return this.$element.on({
         return this.$element.on({
           "change.bootstrapSwitch": (function(_this) {
           "change.bootstrapSwitch": (function(_this) {

部分文件因为文件数量过多而无法显示