فهرست منبع

made plugin defaults publicly overridable

Emanuele Marchi 11 سال پیش
والد
کامیت
b6415f3abc
3فایلهای تغییر یافته به همراه47 افزوده شده و 51 حذف شده
  1. 31 34
      build/js/bootstrap-switch.js
  2. 0 0
      build/js/bootstrap-switch.min.js
  3. 16 17
      src/coffee/bootstrap-switch.coffee

+ 31 - 34
build/js/bootstrap-switch.js

@@ -26,19 +26,6 @@
     "use strict";
     var BootstrapSwitch;
     BootstrapSwitch = (function() {
-      BootstrapSwitch.prototype.defaults = {
-        state: true,
-        size: null,
-        animate: true,
-        disabled: false,
-        readonly: false,
-        onColor: "primary",
-        offColor: "default",
-        onText: "ON",
-        offText: "OFF",
-        labelText: " "
-      };
-
       BootstrapSwitch.prototype.name = "bootstrap-switch";
 
       function BootstrapSwitch(element, options) {
@@ -46,7 +33,7 @@
           options = {};
         }
         this.$element = $(element);
-        this.options = $.extend({}, this.defaults, options, {
+        this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, options, {
           state: this.$element.is(":checked"),
           size: this.$element.data("size"),
           animate: this.$element.data("animate"),
@@ -413,26 +400,36 @@
       return BootstrapSwitch;
 
     })();
-    $.fn.extend({
-      bootstrapSwitch: function() {
-        var args, option, ret;
-        option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
-        ret = this;
-        this.each(function() {
-          var $this, data;
-          $this = $(this);
-          data = $this.data("bootstrap-switch");
-          if (!data) {
-            $this.data("bootstrap-switch", data = new BootstrapSwitch(this, option));
-          }
-          if (typeof option === "string") {
-            return ret = data[option].apply(data, args);
-          }
-        });
-        return ret;
-      }
-    });
-    return $.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
+    $.fn.bootstrapSwitch = function() {
+      var args, option, ret;
+      option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+      ret = this;
+      this.each(function() {
+        var $this, data;
+        $this = $(this);
+        data = $this.data("bootstrap-switch");
+        if (!data) {
+          $this.data("bootstrap-switch", data = new BootstrapSwitch(this, option));
+        }
+        if (typeof option === "string") {
+          return ret = data[option].apply(data, args);
+        }
+      });
+      return ret;
+    };
+    $.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
+    return $.fn.bootstrapSwitch.defaults = {
+      state: true,
+      size: null,
+      animate: true,
+      disabled: false,
+      readonly: false,
+      onColor: "primary",
+      offColor: "default",
+      onText: "ON",
+      offText: "OFF",
+      labelText: "&nbsp;"
+    };
   })(window.jQuery, window);
 
 }).call(this);

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
build/js/bootstrap-switch.min.js


+ 16 - 17
src/coffee/bootstrap-switch.coffee

@@ -1,23 +1,12 @@
-(($, window) ->
+do ($ = window.jQuery, window) ->
   "use strict"
 
   class BootstrapSwitch
-    defaults:
-      state: true
-      size: null
-      animate: true
-      disabled: false
-      readonly: false
-      onColor: "primary"
-      offColor: "default"
-      onText: "ON"
-      offText: "OFF"
-      labelText: "&nbsp;"
     name: "bootstrap-switch"
 
     constructor: (element, options = {}) ->
       @$element = $ element
-      @options = $.extend {}, @defaults, options,
+      @options = $.extend {}, $.fn.bootstrapSwitch.defaults, options,
         state: @$element.is ":checked"
         size: @$element.data "size"
         animate: @$element.data "animate"
@@ -38,7 +27,7 @@
         for: @$element.attr "id"
         html: @options.labelText
       @$wrapper = $ "<div>",
-        class: =>
+        "class": =>
           classes = ["#{@name}"]
 
           classes.push if @options.state then "#{@name}-on" else "#{@name}-off"
@@ -300,10 +289,10 @@
         , 1
       .data "bootstrap-switch", true
 
-  $.fn.extend bootstrapSwitch: (option, args...) ->
+  $.fn.bootstrapSwitch = (option, args...) ->
     ret = @
     @each ->
-      $this = $(@)
+      $this = $ @
       data = $this.data "bootstrap-switch"
 
       $this.data "bootstrap-switch", data = new BootstrapSwitch @, option if not data
@@ -311,4 +300,14 @@
     ret
 
   $.fn.bootstrapSwitch.Constructor = BootstrapSwitch
-) window.jQuery, window
+  $.fn.bootstrapSwitch.defaults =
+    state: true
+    size: null
+    animate: true
+    disabled: false
+    readonly: false
+    onColor: "primary"
+    offColor: "default"
+    onText: "ON"
+    offText: "OFF"
+    labelText: "&nbsp;"

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است