Browse Source

Added `.dataset` fallback for jQuery 1.x

As we have established already, jQuery 1.x does not correctly handle
`data-*` attributes where there are multiple dashes.  This makes it
so we can still handle nested options when working with jQuery 1.x
by using the `.dataset` option that is supported by all major
browsers as well as IE 11+.

Browser support tables for the `.dataset` attributes can be found at
http://caniuse.com/dataset

A notice was already added to the documentation about this in
https://github.com/select2/select2/commit/caeb0ec9b775baf1b91cad859a2954d720d3af20.

The related ticket in the jQuery repository about this issue is
https://github.com/jquery/jquery/issues/2070.

This closes https://github.com/select2/select2/issues/2969.
Kevin Brown 10 years ago
parent
commit
a9f6d64b72

+ 1 - 0
dist/js/i18n/hi.js

@@ -0,0 +1 @@
+(function(){if(window.define)var e=window.define;if(window.require)var t=window.require;if(window.jQuery&&jQuery.fn&&jQuery.fn.select2&&jQuery.fn.select2.amd)var e=jQuery.fn.select2.amd.define,t=jQuery.fn.select2.amd.require;e("select2/i18n/hi",[],function(){return{errorLoading:function(){return"परिणामों को लोड नहीं किया जा सका।"},inputTooLong:function(e){var t=e.input.length-e.maximum,n=t+" अक्षर को हटा दें";return t>1&&(n=t+" अक्षरों को हटा दें "),n},inputTooShort:function(e){var t=e.minimum-e.input.length,n="कृपया "+t+" या अधिक अक्षर दर्ज करें";return n},loadingMore:function(){return"अधिक परिणाम लोड हो रहे है..."},maximumSelected:function(e){var t="आप केवल "+e.maximum+" आइटम का चयन कर सकते हैं";return t},noResults:function(){return"कोई परिणाम नहीं मिला"},searching:function(){return"खोज रहा है..."}}}),t("jquery.select2"),jQuery.fn.select2.amd={define:e,require:t}})();

+ 3 - 1
dist/js/select2.amd.full.js

@@ -4116,7 +4116,9 @@ define('select2/options',[
       $e.data('ajax--url', $e.data('ajax-url'));
     }
 
-    var data = $e.data();
+    // Prefer the element's `dataset` attribute if it exists
+    // jQuery 1.x does not correctly handle data attributes with multiple dashes
+    var data = $.extend(true, {}, $e[0].dataset || $e.data());
 
     data = Utils._convertData(data);
 

+ 3 - 1
dist/js/select2.amd.js

@@ -4116,7 +4116,9 @@ define('select2/options',[
       $e.data('ajax--url', $e.data('ajax-url'));
     }
 
-    var data = $e.data();
+    // Prefer the element's `dataset` attribute if it exists
+    // jQuery 1.x does not correctly handle data attributes with multiple dashes
+    var data = $.extend(true, {}, $e[0].dataset || $e.data());
 
     data = Utils._convertData(data);
 

+ 3 - 1
dist/js/select2.full.js

@@ -4555,7 +4555,9 @@ define('select2/options',[
       $e.data('ajax--url', $e.data('ajax-url'));
     }
 
-    var data = $e.data();
+    // Prefer the element's `dataset` attribute if it exists
+    // jQuery 1.x does not correctly handle data attributes with multiple dashes
+    var data = $.extend(true, {}, $e[0].dataset || $e.data());
 
     data = Utils._convertData(data);
 

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


+ 3 - 1
dist/js/select2.js

@@ -4555,7 +4555,9 @@ define('select2/options',[
       $e.data('ajax--url', $e.data('ajax-url'));
     }
 
-    var data = $e.data();
+    // Prefer the element's `dataset` attribute if it exists
+    // jQuery 1.x does not correctly handle data attributes with multiple dashes
+    var data = $.extend(true, {}, $e[0].dataset || $e.data());
 
     data = Utils._convertData(data);
 

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


+ 3 - 1
src/js/select2/options.js

@@ -70,7 +70,9 @@ define([
       $e.data('ajax--url', $e.data('ajax-url'));
     }
 
-    var data = $e.data();
+    // Prefer the element's `dataset` attribute if it exists
+    // jQuery 1.x does not correctly handle data attributes with multiple dashes
+    var data = $.extend(true, {}, $e[0].dataset || $e.data());
 
     data = Utils._convertData(data);
 

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