@@ -271,6 +271,32 @@ the specific language governing permissions and limitations under the Apache Lic
271271 return sizer . width ( ) ;
272272 }
273273
274+ function syncCssClasses ( dest , src , adapter ) {
275+ var classes , replacements = [ ] , adapted ;
276+
277+ classes = dest . attr ( "class" ) ;
278+ if ( typeof classes === "string" ) {
279+ $ ( classes . split ( " " ) ) . each2 ( function ( ) {
280+ if ( this . indexOf ( "select2-" ) === 0 ) {
281+ replacements . push ( this ) ;
282+ }
283+ } ) ;
284+ }
285+ classes = src . attr ( "class" ) ;
286+ if ( typeof classes === "string" ) {
287+ $ ( classes . split ( " " ) ) . each2 ( function ( ) {
288+ if ( this . indexOf ( "select2-" ) !== 0 ) {
289+ adapted = adapter ( this ) ;
290+ if ( typeof adapted === "string" && adapted . length > 0 ) {
291+ replacements . push ( this ) ;
292+ }
293+ }
294+ } ) ;
295+ }
296+ dest . attr ( "class" , replacements . join ( " " ) ) ;
297+ }
298+
299+
274300 function markMatch ( text , term , markup , escapeMarkup ) {
275301 var match = text . toUpperCase ( ) . indexOf ( term . toUpperCase ( ) ) ,
276302 tl = term . length ;
@@ -582,10 +608,8 @@ the specific language governing permissions and limitations under the Apache Lic
582608 } ) ;
583609 }
584610
585- if ( opts . element . attr ( "class" ) !== undefined ) {
586- this . container . addClass ( opts . element . attr ( "class" ) ) ;
587- }
588-
611+ syncCssClasses ( this . container , this . opts . element , this . opts . adaptContainerCssClass ) ;
612+
589613 this . container . css ( evaluate ( opts . containerCss ) ) ;
590614 this . container . addClass ( evaluate ( opts . containerCssClass ) ) ;
591615
@@ -881,32 +905,11 @@ the specific language governing permissions and limitations under the Apache Lic
881905 }
882906 }
883907
884- function syncCssClasses ( dest , accept ) {
885- var classes , replacements = [ ] ;
886-
887- classes = dest . attr ( "class" ) ;
888- if ( typeof classes === "string" ) {
889- $ ( classes . split ( " " ) ) . each2 ( function ( ) {
890- if ( this . indexOf ( "select2-" ) === 0 ) {
891- replacements . push ( this ) ;
892- }
893- } ) ;
894- }
895- classes = self . opts . element . attr ( "class" ) ;
896- if ( typeof classes === "string" ) {
897- $ ( classes . split ( " " ) ) . each2 ( function ( ) {
898- if ( this . indexOf ( "select2-" ) !== 0 && accept ( this ) ) {
899- replacements . push ( this ) ;
900- }
901- } ) ;
902- }
903- dest . attr ( "class" , replacements . join ( " " ) ) ;
904- }
905908
906- syncCssClasses ( this . container , this . opts . acceptContainerCssClass ) ;
909+ syncCssClasses ( this . container , this . opts . element , this . opts . adaptContainerCssClass ) ;
907910 this . container . addClass ( evaluate ( this . opts . containerCssClass ) ) ;
908911
909- syncCssClasses ( this . dropdown , this . opts . acceptDropdownCssClass ) ;
912+ syncCssClasses ( this . dropdown , this . opts . element , this . opts . adaptDropdownCssClass ) ;
910913 this . dropdown . addClass ( evaluate ( this . opts . dropdownCssClass ) ) ;
911914
912915 } ) ;
@@ -2615,8 +2618,8 @@ the specific language governing permissions and limitations under the Apache Lic
26152618 } ,
26162619 blurOnChange : false ,
26172620 selectOnBlur : false ,
2618- acceptContainerCssClass : function ( c ) { return true ; } ,
2619- acceptDropdownCssClass : function ( c ) { return true ; }
2621+ adaptContainerCssClass : function ( c ) { return c ; } ,
2622+ adaptDropdownCssClass : function ( c ) { return null ; }
26202623 } ;
26212624
26222625 // exports
0 commit comments