1
0
mirror of synced 2024-11-25 22:36:03 +03:00

Cache objects in Utils.__cache instead of using $.data (#4346)

This commit is contained in:
alexweissman 2017-10-26 14:12:50 -04:00
parent 62c4f6332b
commit 1864a3d538
3 changed files with 24 additions and 25 deletions

View File

@ -13,6 +13,7 @@
- User-defined types not normalized properly when passed in as data (#4632)
- Perform deep merge for `Defaults.set()` (#4364)
- Fix "the results could not be loaded" displaying during AJAX request (#4356)
- Cache objects in `Utils.__cache` instead of using `$.data` (#4346)
- Removing the double event binding registration of `selection:update` (#4306)
#### Accessibility

View File

@ -6,7 +6,7 @@ define([
], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) {
if (Utils.GetData($element[0], 'select2') != null) {
Utils.GetData($element[0], 'select2').destroy();
Utils.GetData($element[0], 'select2').destroy();
}
this.$element = $element;
@ -573,7 +573,7 @@ define([
this._syncS = null;
this.$element.off('.select2');
this.$element.attr('tabindex',
this.$element.attr('tabindex',
Utils.GetData(this.$element[0], 'old-tabindex'));
this.$element.removeClass('select2-hidden-accessible');

View File

@ -74,10 +74,10 @@ define([
DecoratedClass.prototype = new ctr();
for (var m = 0; m < superMethods.length; m++) {
var superMethod = superMethods[m];
var superMethod = superMethods[m];
DecoratedClass.prototype[superMethod] =
SuperClass.prototype[superMethod];
DecoratedClass.prototype[superMethod] =
SuperClass.prototype[superMethod];
}
var calledMethod = function (methodName) {
@ -272,10 +272,9 @@ define([
$element.append($nodes);
};
// Cache objects in Utils.__cache instead of $.data
// Cache objects in Utils.__cache instead of $.data (see #4346)
Utils.__cache = {};
var id = 0;
Utils.GetUniqueElementId = function (element) {
// Get a unique element Id. If element has no id,
@ -285,14 +284,14 @@ define([
var select2Id = element.getAttribute('data-select2-id');
if (select2Id == null) {
// If element has id, use it.
if (element.id) {
select2Id = element.id;
element.setAttribute('data-select2-id', select2Id);
} else {
element.setAttribute('data-select2-id', ++id);
select2Id = id.toString();
}
// If element has id, use it.
if (element.id) {
select2Id = element.id;
element.setAttribute('data-select2-id', select2Id);
} else {
element.setAttribute('data-select2-id', ++id);
select2Id = id.toString();
}
}
return select2Id;
};
@ -302,13 +301,12 @@ define([
// name is the cache key.
var id = Utils.GetUniqueElementId(element);
if (!Utils.__cache[id]) {
Utils.__cache[id] = {};
Utils.__cache[id] = {};
}
Utils.__cache[id][name] = value;
};
Utils.GetData = function (element, name) {
// Retrieves a value from the cache by its key (name)
// name is optional. If no name specified, return
@ -316,14 +314,14 @@ define([
// and for a specified element.
var id = Utils.GetUniqueElementId(element);
if (name) {
if (Utils.__cache[id]) {
return Utils.__cache[id][name] != null ?
Utils.__cache[id][name]:
$(element).data(name); // Fallback to HTML5 data attribs.
}
return $(element).data(name); // Fallback to HTML5 data attribs.
if (Utils.__cache[id]) {
return Utils.__cache[id][name] != null ?
Utils.__cache[id][name]:
$(element).data(name); // Fallback to HTML5 data attribs.
}
return $(element).data(name); // Fallback to HTML5 data attribs.
} else {
return Utils.__cache[id];
return Utils.__cache[id];
}
};
@ -331,7 +329,7 @@ define([
// Removes all cached items for a specified element.
var id = Utils.GetUniqueElementId(element);
if (Utils.__cache[id] != null) {
delete Utils.__cache[id];
delete Utils.__cache[id];
}
};