Browse Source

made html inline options overridable by javascript init options #319

LostCrew 11 years ago
parent
commit
c5681c4871

+ 3 - 3
dist/js/bootstrap-switch.js

@@ -31,7 +31,7 @@
           options = {};
         }
         this.$element = $(element);
-        this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, options, {
+        this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, {
           state: this.$element.is(":checked"),
           size: this.$element.data("size"),
           animate: this.$element.data("animate"),
@@ -45,7 +45,7 @@
           labelText: this.$element.data("label-text"),
           baseClass: this.$element.data("base-class"),
           wrapperClass: this.$element.data("wrapper-class")
-        });
+        }, options);
         this.$wrapper = $("<div>", {
           "class": (function(_this) {
             return function() {
@@ -429,10 +429,10 @@
               if (_this.isLabelDragged) {
                 _this.isLabelDragged = false;
                 _this.state(parseInt(_this.$container.css("margin-left"), 10) > -(_this.$container.width() / 6));
-                _this.$container.css("margin-left", "");
                 if (_this.options.animate) {
                   _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
                 }
+                _this.$container.css("margin-left", "");
               } else {
                 _this.state(!_this.options.state);
               }

File diff suppressed because it is too large
+ 0 - 0
dist/js/bootstrap-switch.min.js


+ 3 - 2
src/coffee/bootstrap-switch.coffee

@@ -4,7 +4,7 @@ do ($ = window.jQuery, window) ->
   class BootstrapSwitch
     constructor: (element, options = {}) ->
       @$element = $ element
-      @options = $.extend {}, $.fn.bootstrapSwitch.defaults, options,
+      @options = $.extend {}, $.fn.bootstrapSwitch.defaults,
         state: @$element.is ":checked"
         size: @$element.data "size"
         animate: @$element.data "animate"
@@ -18,6 +18,7 @@ do ($ = window.jQuery, window) ->
         labelText: @$element.data "label-text"
         baseClass: @$element.data "base-class"
         wrapperClass: @$element.data "wrapper-class"
+      , options
       @$wrapper = $ "<div>",
         class: do =>
           classes = ["#{@options.baseClass}"].concat @_getClasses @options.wrapperClass
@@ -320,8 +321,8 @@ do ($ = window.jQuery, window) ->
           if @isLabelDragged
             @isLabelDragged = false
             @state parseInt(@$container.css("margin-left"), 10) > -(@$container.width() / 6)
-            @$container.css "margin-left", ""
             @$wrapper.addClass "#{@options.baseClass}-animate" if @options.animate
+            @$container.css "margin-left", ""
           else
             @state not @options.state
           @isLabelDragging = false

Some files were not shown because too many files changed in this diff