Browse Source

Added the `element` reference in the data

This also fixes `_normalizeItem` for cases where `text` doesn't
exist, so it doesn't clobber the item.
Kevin Brown 10 years ago
parent
commit
1e44ab7ee1

+ 6 - 6
dist/js/select2.amd.full.js

@@ -2239,6 +2239,7 @@ define('select2/data/select',[
     var $option = $(option);
     var $option = $(option);
 
 
     var normalizedData = this._normalizeItem(data);
     var normalizedData = this._normalizeItem(data);
+    normalizedData.element = option;
 
 
     // Override the option's data with the combined data
     // Override the option's data with the combined data
     $.data(option, 'data', normalizedData);
     $.data(option, 'data', normalizedData);
@@ -2283,6 +2284,7 @@ define('select2/data/select',[
     }
     }
 
 
     data = this._normalizeItem(data);
     data = this._normalizeItem(data);
+    data.element = $option[0];
 
 
     $.data($option[0], 'data', data);
     $.data($option[0], 'data', data);
 
 
@@ -2290,12 +2292,10 @@ define('select2/data/select',[
   };
   };
 
 
   SelectAdapter.prototype._normalizeItem = function (item) {
   SelectAdapter.prototype._normalizeItem = function (item) {
-    if (item.text == null) {
-      item = {
-        id: item,
-        text: item
-      };
-    }
+    $.extend(item, {
+      id: item,
+      text: item
+    });
 
 
     var defaults = {
     var defaults = {
       selected: false,
       selected: false,

+ 6 - 6
dist/js/select2.amd.js

@@ -2239,6 +2239,7 @@ define('select2/data/select',[
     var $option = $(option);
     var $option = $(option);
 
 
     var normalizedData = this._normalizeItem(data);
     var normalizedData = this._normalizeItem(data);
+    normalizedData.element = option;
 
 
     // Override the option's data with the combined data
     // Override the option's data with the combined data
     $.data(option, 'data', normalizedData);
     $.data(option, 'data', normalizedData);
@@ -2283,6 +2284,7 @@ define('select2/data/select',[
     }
     }
 
 
     data = this._normalizeItem(data);
     data = this._normalizeItem(data);
+    data.element = $option[0];
 
 
     $.data($option[0], 'data', data);
     $.data($option[0], 'data', data);
 
 
@@ -2290,12 +2292,10 @@ define('select2/data/select',[
   };
   };
 
 
   SelectAdapter.prototype._normalizeItem = function (item) {
   SelectAdapter.prototype._normalizeItem = function (item) {
-    if (item.text == null) {
-      item = {
-        id: item,
-        text: item
-      };
-    }
+    $.extend(item, {
+      id: item,
+      text: item
+    });
 
 
     var defaults = {
     var defaults = {
       selected: false,
       selected: false,

+ 6 - 6
dist/js/select2.full.js

@@ -11774,6 +11774,7 @@ define('select2/data/select',[
     var $option = $(option);
     var $option = $(option);
 
 
     var normalizedData = this._normalizeItem(data);
     var normalizedData = this._normalizeItem(data);
+    normalizedData.element = option;
 
 
     // Override the option's data with the combined data
     // Override the option's data with the combined data
     $.data(option, 'data', normalizedData);
     $.data(option, 'data', normalizedData);
@@ -11818,6 +11819,7 @@ define('select2/data/select',[
     }
     }
 
 
     data = this._normalizeItem(data);
     data = this._normalizeItem(data);
+    data.element = $option[0];
 
 
     $.data($option[0], 'data', data);
     $.data($option[0], 'data', data);
 
 
@@ -11825,12 +11827,10 @@ define('select2/data/select',[
   };
   };
 
 
   SelectAdapter.prototype._normalizeItem = function (item) {
   SelectAdapter.prototype._normalizeItem = function (item) {
-    if (item.text == null) {
-      item = {
-        id: item,
-        text: item
-      };
-    }
+    $.extend(item, {
+      id: item,
+      text: item
+    });
 
 
     var defaults = {
     var defaults = {
       selected: false,
       selected: false,

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


+ 6 - 6
dist/js/select2.js

@@ -2667,6 +2667,7 @@ define('select2/data/select',[
     var $option = $(option);
     var $option = $(option);
 
 
     var normalizedData = this._normalizeItem(data);
     var normalizedData = this._normalizeItem(data);
+    normalizedData.element = option;
 
 
     // Override the option's data with the combined data
     // Override the option's data with the combined data
     $.data(option, 'data', normalizedData);
     $.data(option, 'data', normalizedData);
@@ -2711,6 +2712,7 @@ define('select2/data/select',[
     }
     }
 
 
     data = this._normalizeItem(data);
     data = this._normalizeItem(data);
+    data.element = $option[0];
 
 
     $.data($option[0], 'data', data);
     $.data($option[0], 'data', data);
 
 
@@ -2718,12 +2720,10 @@ define('select2/data/select',[
   };
   };
 
 
   SelectAdapter.prototype._normalizeItem = function (item) {
   SelectAdapter.prototype._normalizeItem = function (item) {
-    if (item.text == null) {
-      item = {
-        id: item,
-        text: item
-      };
-    }
+    $.extend(item, {
+      id: item,
+      text: item
+    });
 
 
     var defaults = {
     var defaults = {
       selected: false,
       selected: false,

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


+ 6 - 6
src/js/select2/data/select.js

@@ -146,6 +146,7 @@ define([
     var $option = $(option);
     var $option = $(option);
 
 
     var normalizedData = this._normalizeItem(data);
     var normalizedData = this._normalizeItem(data);
+    normalizedData.element = option;
 
 
     // Override the option's data with the combined data
     // Override the option's data with the combined data
     $.data(option, 'data', normalizedData);
     $.data(option, 'data', normalizedData);
@@ -190,6 +191,7 @@ define([
     }
     }
 
 
     data = this._normalizeItem(data);
     data = this._normalizeItem(data);
+    data.element = $option[0];
 
 
     $.data($option[0], 'data', data);
     $.data($option[0], 'data', data);
 
 
@@ -197,12 +199,10 @@ define([
   };
   };
 
 
   SelectAdapter.prototype._normalizeItem = function (item) {
   SelectAdapter.prototype._normalizeItem = function (item) {
-    if (item.text == null) {
-      item = {
-        id: item,
-        text: item
-      };
-    }
+    $.extend(item, {
+      id: item,
+      text: item
+    });
 
 
     var defaults = {
     var defaults = {
       selected: false,
       selected: false,

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