Explorar o código

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
Kevin Brown %!s(int64=11) %!d(string=hai) anos
pai
achega
3fee8fc7e6
Modificáronse 1 ficheiros con 11 adicións e 4 borrados
  1. 11 4
      select2.js

+ 11 - 4
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(" "));
     }