Sfoglia il codice sorgente

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 11 anni fa
parent
commit
3fee8fc7e6
1 ha cambiato i file con 11 aggiunte e 4 eliminazioni
  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(" "));
     }