Explorar el Código

Fixed unit tests and updated source code to handle HTML5 attribs.

Nadim Afana hace 9 años
padre
commit
a1dc7f23d1
Se han modificado 3 ficheros con 10 adiciones y 6 borrados
  1. 2 1
      src/js/select2/options.js
  2. 5 3
      src/js/select2/utils.js
  3. 3 2
      tests/data/array-tests.js

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

@@ -78,7 +78,8 @@ define([
       }
 
       $e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
-      Utils.StoreData($e[0], 'ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
+      Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl'));
+	  
     }
 
     var dataset = {};

+ 5 - 3
src/js/select2/utils.js

@@ -303,11 +303,13 @@ define([
     var id = Utils.GetUniqueElementId(element);
     if (name) {
         if (Utils.__cache[id]) {
-            return Utils.__cache[id][name];
+            return Utils.__cache[id][name] != null ? 
+			       Utils.__cache[id][name]:
+				   $(element).data(name); // Fallback to HTML5 data attribs.
         }
-        return null;
+        return $(element).data(name); // Fallback to HTML5 data attribs.
     } else {
-        return Utils.__cache[id];
+        return Utils.__cache[id];			   
     }
   };
 

+ 3 - 2
tests/data/array-tests.js

@@ -3,6 +3,7 @@ module('Data adapters - Array');
 var ArrayData = require('select2/data/array');
 var $ = require('jquery');
 var Options = require('select2/options');
+var Utils = require('select2/utils');
 
 var arrayOptions = new Options({
   data: [
@@ -237,7 +238,7 @@ test('option tags can receive new data', function(assert) {
   });
 
   assert.ok(
-    $select.find(':selected').data('data').extra,
+     Utils.GetData($select.find(':selected')[0], 'data').extra,
     '<option> default should have new data'
   );
 
@@ -246,7 +247,7 @@ test('option tags can receive new data', function(assert) {
   });
 
   assert.ok(
-    $select.find(':selected').data('data').extra,
+     Utils.GetData($select.find(':selected')[0], 'data').extra,
     '<option> One should have new data'
   );
 });