vendor/select2/src/js/select2/utils.js in card-mod-bootstrap-0.14.2 vs vendor/select2/src/js/select2/utils.js in card-mod-bootstrap-0.15.0
- old
+ new
@@ -253,85 +253,98 @@
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
return replaceMap[match];
});
};
- // Append an array of jQuery nodes to a given element.
- Utils.appendMany = function ($element, $nodes) {
- // jQuery 1.7.x does not support $.fn.append() with an array
- // Fall back to a jQuery object collection using $.fn.add()
- if ($.fn.jquery.substr(0, 3) === '1.7') {
- var $jqNodes = $();
-
- $.map($nodes, function (node) {
- $jqNodes = $jqNodes.add(node);
- });
-
- $nodes = $jqNodes;
- }
-
- $element.append($nodes);
- };
-
// 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,
- // creates a new unique number, stores it in the id
- // attribute and returns the new id.
- // If an id already exists, it simply returns it.
+ // Get a unique element Id. If element has no id,
+ // creates a new unique number, stores it in the id
+ // attribute and returns the new id with a prefix.
+ // If an id already exists, it simply returns it with a prefix.
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 (select2Id != null) {
+ return select2Id;
}
+
+ // If element has id, use it.
+ if (element.id) {
+ select2Id = 'select2-data-' + element.id;
+ } else {
+ select2Id = 'select2-data-' + (++id).toString() +
+ '-' + Utils.generateChars(4);
+ }
+
+ element.setAttribute('data-select2-id', select2Id);
+
return select2Id;
};
Utils.StoreData = function (element, name, value) {
// Stores an item in the cache for a specified element.
- // name is the cache key.
+ // name is the cache key.
var id = Utils.GetUniqueElementId(element);
if (!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
+ // name is optional. If no name specified, return
// all cache items for the specified element.
// 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.
+ if (Utils.__cache[id][name] != null) {
+ return Utils.__cache[id][name];
+ }
+ return $(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];
}
};
Utils.RemoveData = function (element) {
// Removes all cached items for a specified element.
var id = Utils.GetUniqueElementId(element);
if (Utils.__cache[id] != null) {
delete Utils.__cache[id];
}
+
+ element.removeAttribute('data-select2-id');
+ };
+
+ Utils.copyNonInternalCssClasses = function (dest, src) {
+ var classes;
+
+ var destinationClasses = dest.getAttribute('class').trim().split(/\s+/);
+
+ destinationClasses = destinationClasses.filter(function (clazz) {
+ // Save all Select2 classes
+ return clazz.indexOf('select2-') === 0;
+ });
+
+ var sourceClasses = src.getAttribute('class').trim().split(/\s+/);
+
+ sourceClasses = sourceClasses.filter(function (clazz) {
+ // Only copy non-Select2 classes
+ return clazz.indexOf('select2-') !== 0;
+ });
+
+ var replacements = destinationClasses.concat(sourceClasses);
+
+ dest.setAttribute('class', replacements.join(' '));
};
return Utils;
});