浏览代码

Added debug option

Now most of the warning messages will only be displayed if the
`debug` option is set when initializing Select2.

This closes https://github.com/select2/select2/issues/3100.
Kevin Brown 10 年之前
父节点
当前提交
78c301f4fb

+ 13 - 11
dist/js/select2.amd.full.js

@@ -1171,7 +1171,7 @@ define('select2/selection/allowClear',[
     decorated.call(this, container, $container);
 
     if (self.placeholder == null) {
-      if (window.console && console.error) {
+      if (self.options.get('debug') && window.console && console.error) {
         console.error(
           'Select2: The `allowClear` option should be used in combination ' +
           'with the `placeholder` option.'
@@ -2782,7 +2782,7 @@ define('select2/data/ajax',[
       var $request = options.transport(options, function (data) {
         var results = self.processResults(data, params);
 
-        if (window.console && console.error) {
+        if (self.options.get('debug') && window.console && console.error) {
           // Check to make sure that the response included a `results` key.
           if (!results || !results.results || !$.isArray(results.results)) {
             console.error(
@@ -3963,7 +3963,7 @@ define('select2/defaults',[
             // The translation could not be loaded at all. Sometimes this is
             // because of a configuration problem, other times this can be
             // because of how Select2 helps load all possible translation files.
-            if (window.console && console.warn) {
+            if (options.debug && window.console && console.warn) {
               console.warn(
                 'Select2: The language file for "' + name + '" could not be ' +
                 'automatically loaded. A fallback will be used instead.'
@@ -4044,6 +4044,7 @@ define('select2/defaults',[
       amdBase: 'select2/',
       amdLanguageBase: 'select2/i18n/',
       closeOnSelect: true,
+      debug: false,
       escapeMarkup: Utils.escapeMarkup,
       language: EnglishTranslation,
       matcher: matcher,
@@ -4139,7 +4140,7 @@ define('select2/options',[
     $e.prop('multiple', this.options.multiple);
 
     if ($e.data('select2Tags')) {
-      if (window.console && console.warn) {
+      if (this.options.debug && window.console && console.warn) {
         console.warn(
           'Select2: The `data-select2-tags` attribute has been changed to ' +
           'use the `data-data` and `data-tags="true"` attributes and will be ' +
@@ -4152,7 +4153,7 @@ define('select2/options',[
     }
 
     if ($e.data('ajaxUrl')) {
-      if (window.console && console.warn) {
+      if (this.options.debug && window.console && console.warn) {
         console.warn(
           'Select2: The `data-ajax-url` attribute has been changed to ' +
           '`data-ajax--url` and support for the old attribute will be removed' +
@@ -4617,7 +4618,7 @@ define('select2/core',[
   };
 
   Select2.prototype.enable = function (args) {
-    if (window.console && console.warn) {
+    if (this.options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `select2("enable")` method has been deprecated and will' +
         ' be removed in later Select2 versions. Use $element.prop("disabled")' +
@@ -4635,7 +4636,8 @@ define('select2/core',[
   };
 
   Select2.prototype.data = function () {
-    if (arguments.length > 0 && window.console && console.warn) {
+    if (this.options.get('debug') &&
+        arguments.length > 0 && window.console && console.warn) {
       console.warn(
         'Select2: Data can no longer be set using `select2("data")`. You ' +
         'should consider setting the value instead using `$element.val()`.'
@@ -4652,7 +4654,7 @@ define('select2/core',[
   };
 
   Select2.prototype.val = function (args) {
-    if (window.console && console.warn) {
+    if (this.options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `select2("val")` method has been deprecated and will be' +
         ' removed in later Select2 versions. Use $element.val() instead.'
@@ -4999,7 +5001,7 @@ define('select2/compat/initSelection',[
   'jquery'
 ], function ($) {
   function InitSelection (decorated, $element, options) {
-    if (window.console && console.warn) {
+    if (options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `initSelection` option has been deprecated in favor' +
         ' of a custom data adapter that overrides the `current` method. ' +
@@ -5046,7 +5048,7 @@ define('select2/compat/inputData',[
     this._valueSeparator = options.get('valueSeparator') || ',';
 
     if ($element.prop('type') === 'hidden') {
-      if (console && console.warn) {
+      if (options.get('debug') && console && console.warn) {
         console.warn(
           'Select2: Using a hidden input with Select2 is no longer ' +
           'supported and may stop working in the future. It is recommended ' +
@@ -5170,7 +5172,7 @@ define('select2/compat/query',[
 
 ], function () {
   function Query (decorated, $element, options) {
-    if (window.console && console.warn) {
+    if (options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `query` option has been deprecated in favor of a ' +
         'custom data adapter that overrides the `query` method. Support ' +

+ 10 - 8
dist/js/select2.amd.js

@@ -1171,7 +1171,7 @@ define('select2/selection/allowClear',[
     decorated.call(this, container, $container);
 
     if (self.placeholder == null) {
-      if (window.console && console.error) {
+      if (self.options.get('debug') && window.console && console.error) {
         console.error(
           'Select2: The `allowClear` option should be used in combination ' +
           'with the `placeholder` option.'
@@ -2782,7 +2782,7 @@ define('select2/data/ajax',[
       var $request = options.transport(options, function (data) {
         var results = self.processResults(data, params);
 
-        if (window.console && console.error) {
+        if (self.options.get('debug') && window.console && console.error) {
           // Check to make sure that the response included a `results` key.
           if (!results || !results.results || !$.isArray(results.results)) {
             console.error(
@@ -3963,7 +3963,7 @@ define('select2/defaults',[
             // The translation could not be loaded at all. Sometimes this is
             // because of a configuration problem, other times this can be
             // because of how Select2 helps load all possible translation files.
-            if (window.console && console.warn) {
+            if (options.debug && window.console && console.warn) {
               console.warn(
                 'Select2: The language file for "' + name + '" could not be ' +
                 'automatically loaded. A fallback will be used instead.'
@@ -4044,6 +4044,7 @@ define('select2/defaults',[
       amdBase: 'select2/',
       amdLanguageBase: 'select2/i18n/',
       closeOnSelect: true,
+      debug: false,
       escapeMarkup: Utils.escapeMarkup,
       language: EnglishTranslation,
       matcher: matcher,
@@ -4139,7 +4140,7 @@ define('select2/options',[
     $e.prop('multiple', this.options.multiple);
 
     if ($e.data('select2Tags')) {
-      if (window.console && console.warn) {
+      if (this.options.debug && window.console && console.warn) {
         console.warn(
           'Select2: The `data-select2-tags` attribute has been changed to ' +
           'use the `data-data` and `data-tags="true"` attributes and will be ' +
@@ -4152,7 +4153,7 @@ define('select2/options',[
     }
 
     if ($e.data('ajaxUrl')) {
-      if (window.console && console.warn) {
+      if (this.options.debug && window.console && console.warn) {
         console.warn(
           'Select2: The `data-ajax-url` attribute has been changed to ' +
           '`data-ajax--url` and support for the old attribute will be removed' +
@@ -4617,7 +4618,7 @@ define('select2/core',[
   };
 
   Select2.prototype.enable = function (args) {
-    if (window.console && console.warn) {
+    if (this.options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `select2("enable")` method has been deprecated and will' +
         ' be removed in later Select2 versions. Use $element.prop("disabled")' +
@@ -4635,7 +4636,8 @@ define('select2/core',[
   };
 
   Select2.prototype.data = function () {
-    if (arguments.length > 0 && window.console && console.warn) {
+    if (this.options.get('debug') &&
+        arguments.length > 0 && window.console && console.warn) {
       console.warn(
         'Select2: Data can no longer be set using `select2("data")`. You ' +
         'should consider setting the value instead using `$element.val()`.'
@@ -4652,7 +4654,7 @@ define('select2/core',[
   };
 
   Select2.prototype.val = function (args) {
-    if (window.console && console.warn) {
+    if (this.options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `select2("val")` method has been deprecated and will be' +
         ' removed in later Select2 versions. Use $element.val() instead.'

+ 14 - 12
dist/js/select2.full.js

@@ -1,5 +1,5 @@
 /*!
- * Select2 4.0.0-rc.1 - Thu, 12 Mar 2015 00:26:05 GMT
+ * Select2 4.0.0-rc.1 - Thu, 12 Mar 2015 00:39:48 GMT
  * https://select2.github.io
  *
  * Released under the MIT license
@@ -1617,7 +1617,7 @@ define('select2/selection/allowClear',[
     decorated.call(this, container, $container);
 
     if (self.placeholder == null) {
-      if (window.console && console.error) {
+      if (self.options.get('debug') && window.console && console.error) {
         console.error(
           'Select2: The `allowClear` option should be used in combination ' +
           'with the `placeholder` option.'
@@ -3228,7 +3228,7 @@ define('select2/data/ajax',[
       var $request = options.transport(options, function (data) {
         var results = self.processResults(data, params);
 
-        if (window.console && console.error) {
+        if (self.options.get('debug') && window.console && console.error) {
           // Check to make sure that the response included a `results` key.
           if (!results || !results.results || !$.isArray(results.results)) {
             console.error(
@@ -4409,7 +4409,7 @@ define('select2/defaults',[
             // The translation could not be loaded at all. Sometimes this is
             // because of a configuration problem, other times this can be
             // because of how Select2 helps load all possible translation files.
-            if (window.console && console.warn) {
+            if (options.debug && window.console && console.warn) {
               console.warn(
                 'Select2: The language file for "' + name + '" could not be ' +
                 'automatically loaded. A fallback will be used instead.'
@@ -4490,6 +4490,7 @@ define('select2/defaults',[
       amdBase: 'select2/',
       amdLanguageBase: 'select2/i18n/',
       closeOnSelect: true,
+      debug: false,
       escapeMarkup: Utils.escapeMarkup,
       language: EnglishTranslation,
       matcher: matcher,
@@ -4585,7 +4586,7 @@ define('select2/options',[
     $e.prop('multiple', this.options.multiple);
 
     if ($e.data('select2Tags')) {
-      if (window.console && console.warn) {
+      if (this.options.debug && window.console && console.warn) {
         console.warn(
           'Select2: The `data-select2-tags` attribute has been changed to ' +
           'use the `data-data` and `data-tags="true"` attributes and will be ' +
@@ -4598,7 +4599,7 @@ define('select2/options',[
     }
 
     if ($e.data('ajaxUrl')) {
-      if (window.console && console.warn) {
+      if (this.options.debug && window.console && console.warn) {
         console.warn(
           'Select2: The `data-ajax-url` attribute has been changed to ' +
           '`data-ajax--url` and support for the old attribute will be removed' +
@@ -5063,7 +5064,7 @@ define('select2/core',[
   };
 
   Select2.prototype.enable = function (args) {
-    if (window.console && console.warn) {
+    if (this.options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `select2("enable")` method has been deprecated and will' +
         ' be removed in later Select2 versions. Use $element.prop("disabled")' +
@@ -5081,7 +5082,8 @@ define('select2/core',[
   };
 
   Select2.prototype.data = function () {
-    if (arguments.length > 0 && window.console && console.warn) {
+    if (this.options.get('debug') &&
+        arguments.length > 0 && window.console && console.warn) {
       console.warn(
         'Select2: Data can no longer be set using `select2("data")`. You ' +
         'should consider setting the value instead using `$element.val()`.'
@@ -5098,7 +5100,7 @@ define('select2/core',[
   };
 
   Select2.prototype.val = function (args) {
-    if (window.console && console.warn) {
+    if (this.options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `select2("val")` method has been deprecated and will be' +
         ' removed in later Select2 versions. Use $element.val() instead.'
@@ -5445,7 +5447,7 @@ define('select2/compat/initSelection',[
   'jquery'
 ], function ($) {
   function InitSelection (decorated, $element, options) {
-    if (window.console && console.warn) {
+    if (options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `initSelection` option has been deprecated in favor' +
         ' of a custom data adapter that overrides the `current` method. ' +
@@ -5492,7 +5494,7 @@ define('select2/compat/inputData',[
     this._valueSeparator = options.get('valueSeparator') || ',';
 
     if ($element.prop('type') === 'hidden') {
-      if (console && console.warn) {
+      if (options.get('debug') && console && console.warn) {
         console.warn(
           'Select2: Using a hidden input with Select2 is no longer ' +
           'supported and may stop working in the future. It is recommended ' +
@@ -5616,7 +5618,7 @@ define('select2/compat/query',[
 
 ], function () {
   function Query (decorated, $element, options) {
-    if (window.console && console.warn) {
+    if (options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `query` option has been deprecated in favor of a ' +
         'custom data adapter that overrides the `query` method. Support ' +

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


+ 11 - 9
dist/js/select2.js

@@ -1,5 +1,5 @@
 /*!
- * Select2 4.0.0-rc.1 - Thu, 12 Mar 2015 00:26:05 GMT
+ * Select2 4.0.0-rc.1 - Thu, 12 Mar 2015 00:39:48 GMT
  * https://select2.github.io
  *
  * Released under the MIT license
@@ -1617,7 +1617,7 @@ define('select2/selection/allowClear',[
     decorated.call(this, container, $container);
 
     if (self.placeholder == null) {
-      if (window.console && console.error) {
+      if (self.options.get('debug') && window.console && console.error) {
         console.error(
           'Select2: The `allowClear` option should be used in combination ' +
           'with the `placeholder` option.'
@@ -3228,7 +3228,7 @@ define('select2/data/ajax',[
       var $request = options.transport(options, function (data) {
         var results = self.processResults(data, params);
 
-        if (window.console && console.error) {
+        if (self.options.get('debug') && window.console && console.error) {
           // Check to make sure that the response included a `results` key.
           if (!results || !results.results || !$.isArray(results.results)) {
             console.error(
@@ -4409,7 +4409,7 @@ define('select2/defaults',[
             // The translation could not be loaded at all. Sometimes this is
             // because of a configuration problem, other times this can be
             // because of how Select2 helps load all possible translation files.
-            if (window.console && console.warn) {
+            if (options.debug && window.console && console.warn) {
               console.warn(
                 'Select2: The language file for "' + name + '" could not be ' +
                 'automatically loaded. A fallback will be used instead.'
@@ -4490,6 +4490,7 @@ define('select2/defaults',[
       amdBase: 'select2/',
       amdLanguageBase: 'select2/i18n/',
       closeOnSelect: true,
+      debug: false,
       escapeMarkup: Utils.escapeMarkup,
       language: EnglishTranslation,
       matcher: matcher,
@@ -4585,7 +4586,7 @@ define('select2/options',[
     $e.prop('multiple', this.options.multiple);
 
     if ($e.data('select2Tags')) {
-      if (window.console && console.warn) {
+      if (this.options.debug && window.console && console.warn) {
         console.warn(
           'Select2: The `data-select2-tags` attribute has been changed to ' +
           'use the `data-data` and `data-tags="true"` attributes and will be ' +
@@ -4598,7 +4599,7 @@ define('select2/options',[
     }
 
     if ($e.data('ajaxUrl')) {
-      if (window.console && console.warn) {
+      if (this.options.debug && window.console && console.warn) {
         console.warn(
           'Select2: The `data-ajax-url` attribute has been changed to ' +
           '`data-ajax--url` and support for the old attribute will be removed' +
@@ -5063,7 +5064,7 @@ define('select2/core',[
   };
 
   Select2.prototype.enable = function (args) {
-    if (window.console && console.warn) {
+    if (this.options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `select2("enable")` method has been deprecated and will' +
         ' be removed in later Select2 versions. Use $element.prop("disabled")' +
@@ -5081,7 +5082,8 @@ define('select2/core',[
   };
 
   Select2.prototype.data = function () {
-    if (arguments.length > 0 && window.console && console.warn) {
+    if (this.options.get('debug') &&
+        arguments.length > 0 && window.console && console.warn) {
       console.warn(
         'Select2: Data can no longer be set using `select2("data")`. You ' +
         'should consider setting the value instead using `$element.val()`.'
@@ -5098,7 +5100,7 @@ define('select2/core',[
   };
 
   Select2.prototype.val = function (args) {
-    if (window.console && console.warn) {
+    if (this.options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `select2("val")` method has been deprecated and will be' +
         ' removed in later Select2 versions. Use $element.val() instead.'

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


+ 1 - 1
src/js/select2/compat/initSelection.js

@@ -2,7 +2,7 @@ define([
   'jquery'
 ], function ($) {
   function InitSelection (decorated, $element, options) {
-    if (window.console && console.warn) {
+    if (options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `initSelection` option has been deprecated in favor' +
         ' of a custom data adapter that overrides the `current` method. ' +

+ 1 - 1
src/js/select2/compat/inputData.js

@@ -6,7 +6,7 @@ define([
     this._valueSeparator = options.get('valueSeparator') || ',';
 
     if ($element.prop('type') === 'hidden') {
-      if (console && console.warn) {
+      if (options.get('debug') && console && console.warn) {
         console.warn(
           'Select2: Using a hidden input with Select2 is no longer ' +
           'supported and may stop working in the future. It is recommended ' +

+ 1 - 1
src/js/select2/compat/query.js

@@ -2,7 +2,7 @@ define([
 
 ], function () {
   function Query (decorated, $element, options) {
-    if (window.console && console.warn) {
+    if (options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `query` option has been deprecated in favor of a ' +
         'custom data adapter that overrides the `query` method. Support ' +

+ 4 - 3
src/js/select2/core.js

@@ -411,7 +411,7 @@ define([
   };
 
   Select2.prototype.enable = function (args) {
-    if (window.console && console.warn) {
+    if (this.options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `select2("enable")` method has been deprecated and will' +
         ' be removed in later Select2 versions. Use $element.prop("disabled")' +
@@ -429,7 +429,8 @@ define([
   };
 
   Select2.prototype.data = function () {
-    if (arguments.length > 0 && window.console && console.warn) {
+    if (this.options.get('debug') &&
+        arguments.length > 0 && window.console && console.warn) {
       console.warn(
         'Select2: Data can no longer be set using `select2("data")`. You ' +
         'should consider setting the value instead using `$element.val()`.'
@@ -446,7 +447,7 @@ define([
   };
 
   Select2.prototype.val = function (args) {
-    if (window.console && console.warn) {
+    if (this.options.get('debug') && window.console && console.warn) {
       console.warn(
         'Select2: The `select2("val")` method has been deprecated and will be' +
         ' removed in later Select2 versions. Use $element.val() instead.'

+ 1 - 1
src/js/select2/data/ajax.js

@@ -64,7 +64,7 @@ define([
       var $request = options.transport(options, function (data) {
         var results = self.processResults(data, params);
 
-        if (window.console && console.error) {
+        if (self.options.get('debug') && window.console && console.error) {
           // Check to make sure that the response included a `results` key.
           if (!results || !results.results || !$.isArray(results.results)) {
             console.error(

+ 2 - 1
src/js/select2/defaults.js

@@ -237,7 +237,7 @@ define([
             // The translation could not be loaded at all. Sometimes this is
             // because of a configuration problem, other times this can be
             // because of how Select2 helps load all possible translation files.
-            if (window.console && console.warn) {
+            if (options.debug && window.console && console.warn) {
               console.warn(
                 'Select2: The language file for "' + name + '" could not be ' +
                 'automatically loaded. A fallback will be used instead.'
@@ -318,6 +318,7 @@ define([
       amdBase: 'select2/',
       amdLanguageBase: 'select2/i18n/',
       closeOnSelect: true,
+      debug: false,
       escapeMarkup: Utils.escapeMarkup,
       language: EnglishTranslation,
       matcher: matcher,

+ 2 - 2
src/js/select2/options.js

@@ -55,7 +55,7 @@ define([
     $e.prop('multiple', this.options.multiple);
 
     if ($e.data('select2Tags')) {
-      if (window.console && console.warn) {
+      if (this.options.debug && window.console && console.warn) {
         console.warn(
           'Select2: The `data-select2-tags` attribute has been changed to ' +
           'use the `data-data` and `data-tags="true"` attributes and will be ' +
@@ -68,7 +68,7 @@ define([
     }
 
     if ($e.data('ajaxUrl')) {
-      if (window.console && console.warn) {
+      if (this.options.debug && window.console && console.warn) {
         console.warn(
           'Select2: The `data-ajax-url` attribute has been changed to ' +
           '`data-ajax--url` and support for the old attribute will be removed' +

+ 1 - 1
src/js/select2/selection/allowClear.js

@@ -9,7 +9,7 @@ define([
     decorated.call(this, container, $container);
 
     if (self.placeholder == null) {
-      if (window.console && console.error) {
+      if (self.options.get('debug') && window.console && console.error) {
         console.error(
           'Select2: The `allowClear` option should be used in combination ' +
           'with the `placeholder` option.'

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