@@ -357,7 +357,7 @@ window.ComponentDot = class {
357
357
} ;
358
358
359
359
this . _search = function ( search ) {
360
- if ( this . _modSettings . mode ) {
360
+ if ( this . _modSettings . mode === 'menu' ) {
361
361
if ( search . value === '' ) {
362
362
for ( let node of this . CONTENT_DOM . childNodes ) {
363
363
node . style . display = 'flex' ;
@@ -424,17 +424,16 @@ window.ComponentDot = class {
424
424
} ;
425
425
426
426
this . _bind = function ( ) {
427
- setTimeout ( ( ) => {
428
- this . CONTENT_DOM . childNodes . forEach ( ( D ) => {
429
- let id = D . getAttribute ( 'data-id' ) ;
430
- if ( this . selected_data . indexOf ( id ) !== - 1 ) {
431
- this . _triggerEvent . enable = false ;
432
- D . click ( ) ;
433
- this . _triggerEvent . enable = true ;
434
- }
435
- } ) ;
436
- if ( this . _modSettings . mode === true ) this . DOM . querySelector ( '.menu-list' ) . style . display = 'none' ;
427
+ this . CONTENT_DOM . childNodes . forEach ( ( D ) => {
428
+ let id = D . getAttribute ( 'data-id' ) ;
429
+ if ( this . selected_data . indexOf ( id ) !== - 1 ) {
430
+ this . _triggerEvent . enable = false ;
431
+ D . click ( ) ;
432
+ this . _triggerEvent . enable = true ;
433
+ }
437
434
} ) ;
435
+ if ( this . _modSettings . mode === 'menu' ) this . DOM . querySelector ( '.menu-list' ) . style . display = 'none' ;
436
+
438
437
if ( this . _useSearchMod === false ) return ;
439
438
let search = this . DOM . querySelector ( `.dot-search` ) ;
440
439
search . addEventListener ( 'input' , ( ) => {
@@ -524,6 +523,43 @@ window.ComponentDot = class {
524
523
this . CONTENT_DOM = this . DOM . querySelector ( `.list` ) ;
525
524
} ;
526
525
526
+ this . _switchMaker = function ( ) {
527
+ let select = this . select ;
528
+ let menu = document . createElement ( 'div' ) ;
529
+ menu . className = 'dlp-dot-switch' ;
530
+ this . id_line_hash = [ ] ;
531
+ let line = 0 ;
532
+ for ( let id in select ) {
533
+ if ( ! select . hasOwnProperty ( id ) ) continue ;
534
+ this . id_line_hash [ id ] = line ;
535
+ line ++ ;
536
+ let option = document . createElement ( 'button' ) ;
537
+ option . setAttribute ( 'data-id' , id ) ;
538
+ option . className = `dlp-button${ this . _modSettings . color } ` ;
539
+ option . textContent = select [ id ] ;
540
+ option . addEventListener ( 'click' , ( ) => {
541
+ if ( this . select_data . indexOf ( id ) !== - 1 ) {
542
+ /*cancel*/
543
+ this . _tagCal ( id , this . MODE . delete ) ;
544
+ option . classList . remove ( `dlp-button${ this . _modSettings . color } -active` ) ;
545
+ option . classList . add ( `dlp-button${ this . _modSettings . color } ` ) ;
546
+ return ;
547
+ }
548
+ if ( this . limit > 0 && this . select_data . length >= this . limit ) {
549
+ this . _triggerEvent . enable = false ;
550
+ menu . childNodes [ this . id_line_hash [ this . select_data [ 0 ] . toString ( ) ] ] . click ( ) ;
551
+ this . _triggerEvent . enable = true ;
552
+ }
553
+ option . classList . remove ( `dlp-button${ this . _modSettings . color } ` ) ;
554
+ option . classList . add ( `dlp-button${ this . _modSettings . color } -active` ) ;
555
+ this . _tagCal ( id , this . MODE . insert ) ;
556
+ } , false ) ;
557
+ menu . append ( option ) ;
558
+ }
559
+ this . DOM . append ( menu ) ;
560
+ this . CONTENT_DOM = menu ;
561
+ } ;
562
+
527
563
return this ;
528
564
}
529
565
@@ -548,16 +584,37 @@ window.ComponentDot = class {
548
584
return this ;
549
585
}
550
586
551
- mod ( settings = { mode : false , placeholder : '未选择' , height : '150px' , direction : 'down' } ) {
587
+ menuMod ( settings = { placeholder : '未选择' , height : '150px' , direction : 'down' } ) {
552
588
this . _modSettings = Object . assign ( {
553
- mode : false ,
554
589
placeholder : '未选择' ,
555
590
height : '150px' ,
556
591
direction : 'down'
557
592
} , settings ) ;
593
+ this . _modSettings . mode = 'menu' ;
594
+ return this ;
595
+ }
596
+
597
+ switchMod ( settings = { cols :0 , color :'' } ) {
598
+ this . _modSettings = Object . assign ( {
599
+ cols : 0 ,
600
+ color :'' ,
601
+ } , settings ) ;
602
+ this . _modSettings . mode = 'switch' ;
603
+ switch ( this . _modSettings . color ) {
604
+ case "red" :
605
+ case "blue" :
606
+ case "green" :
607
+ case "yellow" :
608
+ this . _modSettings . color = '-' + this . _modSettings . color ;
609
+ break ;
610
+ default :
611
+ this . _modSettings . color = '' ;
612
+ break ;
613
+ }
558
614
return this ;
559
615
}
560
616
617
+
561
618
useSearch ( ) {
562
619
this . _useSearchMod = true ;
563
620
return this ;
@@ -578,8 +635,11 @@ window.ComponentDot = class {
578
635
}
579
636
580
637
make ( ) {
581
- if ( this . _modSettings . mode === true ) {
638
+ if ( this . _modSettings . mode === 'menu' ) {
582
639
this . _menuMaker ( ) ;
640
+ } else if ( this . _modSettings . mode === 'switch' ) {
641
+ this . _switchMaker ( ) ;
642
+ this . _useSearchMod = false ;
583
643
} else {
584
644
let select = this . select ;
585
645
let select_dom = '' ;
@@ -1203,7 +1263,7 @@ window.ComponentLine = class {
1203
1263
td . append ( menu ) ;
1204
1264
let modSettings = Object . assign ( {
1205
1265
placeholder : '未选择' ,
1206
- height : '120px ' ,
1266
+ height : '150px ' ,
1207
1267
limit : 1 ,
1208
1268
useSearch : false
1209
1269
} , column . options ) ;
@@ -1214,8 +1274,7 @@ window.ComponentLine = class {
1214
1274
value = [ parseInt ( value ) ] ;
1215
1275
}
1216
1276
}
1217
- let dot = new ComponentDot ( menu , column . select ) . selected ( value ) . limitNum ( modSettings . limit ) . mod ( {
1218
- mode : true ,
1277
+ let dot = new ComponentDot ( menu , column . select ) . selected ( value ) . limitNum ( modSettings . limit ) . menuMod ( {
1219
1278
placeholder : modSettings . placeholder ,
1220
1279
height : modSettings . height
1221
1280
} ) ;
0 commit comments