1
0
mirror of synced 2025-02-03 21:59:24 +03:00

Detect classes separated by multiple spaces

This detects classes separated by multiple spaces and will trim
extra spaces surrounding the class attribute.

This closes the following issue: https://github.com/ivaynberg/select2/issues/2358
This commit is contained in:
Kevin Brown 2014-06-11 20:06:41 -04:00
parent 9e17f63013
commit 3fee8fc7e6

View File

@ -320,27 +320,34 @@ the specific language governing permissions and limitations under the Apache Lic
function syncCssClasses(dest, src, adapter) {
var classes, replacements = [], adapted;
classes = dest.attr("class");
classes = $.trim(dest.attr("class"));
if (classes) {
classes = '' + classes; // for IE which returns object
$(classes.split(" ")).each2(function() {
$(classes.split(/\s+/)).each2(function() {
if (this.indexOf("select2-") === 0) {
replacements.push(this);
}
});
}
classes = src.attr("class");
classes = $.trim(src.attr("class"));
if (classes) {
classes = '' + classes; // for IE which returns object
$(classes.split(" ")).each2(function() {
$(classes.split(/\s+/)).each2(function() {
if (this.indexOf("select2-") !== 0) {
adapted = adapter(this);
if (adapted) {
replacements.push(adapted);
}
}
});
}
dest.attr("class", replacements.join(" "));
}