From 3fee8fc7e63ee394b90da813a5a80362ab2b27b5 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Wed, 11 Jun 2014 20:06:41 -0400 Subject: [PATCH] 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 --- select2.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/select2.js b/select2.js index 1803259a..2c308ccc 100644 --- a/select2.js +++ b/select2.js @@ -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(" ")); }