1
0
mirror of synced 2025-02-04 06:09:23 +03:00

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.
This commit is contained in:
Kevin Brown 2014-12-16 20:51:35 -05:00
parent 33809f1fef
commit 1e44ab7ee1
7 changed files with 32 additions and 32 deletions

View File

@ -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) { $.extend(item, {
item = { id: item,
id: item, text: item
text: item });
};
}
var defaults = { var defaults = {
selected: false, selected: false,

View File

@ -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) { $.extend(item, {
item = { id: item,
id: item, text: item
text: item });
};
}
var defaults = { var defaults = {
selected: false, selected: false,

View File

@ -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) { $.extend(item, {
item = { id: item,
id: item, text: item
text: item });
};
}
var defaults = { var defaults = {
selected: false, selected: false,

File diff suppressed because one or more lines are too long

12
dist/js/select2.js vendored
View File

@ -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) { $.extend(item, {
item = { id: item,
id: item, text: item
text: item });
};
}
var defaults = { var defaults = {
selected: false, selected: false,

File diff suppressed because one or more lines are too long

View File

@ -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) { $.extend(item, {
item = { id: item,
id: item, text: item
text: item });
};
}
var defaults = { var defaults = {
selected: false, selected: false,