@@ -2,6 +2,19 @@ import jquery from 'jquery';
22
33const $ = jquery || window . jQuery || window . $ ;
44
5+ function getClasses ( options , id ) {
6+ const { state, size, disabled, readonly, indeterminate, inverse } = options ;
7+ return [
8+ state ? 'on' : 'off' ,
9+ size ,
10+ disabled ? 'disabled' : undefined ,
11+ readonly ? 'readonly' : undefined ,
12+ indeterminate ? 'indeterminate' : undefined ,
13+ inverse ? 'inverse' : undefined ,
14+ id ? `id-${ id } ` : undefined ,
15+ ] . filter ( v => v == null ) ;
16+ }
17+
518class BootstrapSwitch {
619 constructor ( element , options = { } ) {
720 this . $element = $ ( element ) ;
@@ -13,32 +26,10 @@ class BootstrapSwitch {
1326 ) ;
1427 this . prevOptions = { } ;
1528 this . $wrapper = $ ( '<div>' , {
16- class : ( ) => {
17- const classes = [ ] ;
18- classes . push ( this . options . state ? 'on' : 'off' ) ;
19- if ( this . options . size ) {
20- classes . push ( this . options . size ) ;
21- }
22- if ( this . options . disabled ) {
23- classes . push ( 'disabled' ) ;
24- }
25- if ( this . options . readonly ) {
26- classes . push ( 'readonly' ) ;
27- }
28- if ( this . options . indeterminate ) {
29- classes . push ( 'indeterminate' ) ;
30- }
31- if ( this . options . inverse ) {
32- classes . push ( 'inverse' ) ;
33- }
34- if ( this . $element . attr ( 'id' ) ) {
35- classes . push ( `id-${ this . $element . attr ( 'id' ) } ` ) ;
36- }
37- return classes
38- . map ( this . _getClass . bind ( this ) )
39- . concat ( [ this . options . baseClass ] , this . _getClasses ( this . options . wrapperClass ) )
40- . join ( ' ' ) ;
41- } ,
29+ class : ( ) => getClasses ( this . options , this . $element . attr ( 'id' ) )
30+ . map ( this . _getClass . bind ( this ) )
31+ . concat ( [ this . options . baseClass ] , this . _getClasses ( this . options . wrapperClass ) )
32+ . join ( ' ' ) ,
4233 } ) ;
4334 this . $container = $ ( '<div>' , { class : this . _getClass ( 'container' ) } ) ;
4435 this . $on = $ ( '<span>' , {
0 commit comments