@@ -275,17 +275,13 @@ window.ComponentDot = class {
275
275
delete : 'delete'
276
276
} ;
277
277
278
- constructor ( selector , select , selected , limit = 0 ) {
279
- if ( ! Array . isArray ( selected ) ) {
280
- console . error ( 'Dot param selected must be array!' ) ;
281
- return ;
282
- }
278
+ constructor ( selector , select ) {
283
279
if ( Array . isArray ( select ) || typeof select !== 'object' ) {
284
280
console . error ( 'Dot param select must be object such as {key:val,key2:val2,...} !' ) ;
285
281
return ;
286
282
}
287
283
this . select = select ;
288
- this . limit = limit ;
284
+ this . limit = 0 ;
289
285
if ( selector instanceof HTMLElement ) {
290
286
this . DOM = selector ;
291
287
} else {
@@ -295,24 +291,19 @@ window.ComponentDot = class {
295
291
e . preventDefault ( ) ;
296
292
} ) ;
297
293
298
- selected = selected . map ( function ( elem ) {
299
- return elem . toString ( ) ;
300
- } ) ;
301
- selected = selected . filter ( d => {
302
- if ( select [ d ] === undefined ) return false ;
303
- return true ;
304
- } ) ;
305
- this . selected_data = selected ;
294
+ this . selected_data = [ ] ;
306
295
this . select_data = [ ] ;
307
296
this . insert_data = [ ] ;
308
297
this . delete_data = [ ] ;
309
298
this . _modSettings = { mode : false } ;
310
299
this . _useSearchMod = false ;
311
- this . _triggerEvent = null ;
300
+ this . _triggerEvent = { func : null , enable : false } ;
312
301
313
302
this . _tagSelect = function ( element ) {
314
303
if ( this . limit > 0 && this . select_data . length >= this . limit && this . SELECTED_DOM . firstChild instanceof HTMLElement ) {
304
+ this . _triggerEvent . enable = false ;
315
305
this . SELECTED_DOM . firstChild . click ( ) ;
306
+ this . _triggerEvent . enable = true ;
316
307
}
317
308
let clone = element . cloneNode ( true ) ;
318
309
clone . addEventListener ( 'click' , ( ) => this . _tagCancel ( clone ) , false ) ;
@@ -361,7 +352,8 @@ window.ComponentDot = class {
361
352
if ( this . insertInputDOM instanceof HTMLElement ) this . insertInputDOM . value = JSON . stringify ( this . insert_data ) ;
362
353
}
363
354
}
364
- if ( typeof this . _triggerEvent == 'function' ) this . _triggerEvent ( this . select_data , this . insert_data , this . delete_data ) ;
355
+ if ( typeof this . _triggerEvent . func == 'function' && this . _triggerEvent . enable === true )
356
+ this . _triggerEvent . func ( this . select_data , this . insert_data , this . delete_data ) ;
365
357
} ;
366
358
367
359
this . _search = function ( search ) {
@@ -433,14 +425,14 @@ window.ComponentDot = class {
433
425
434
426
this . _bind = function ( ) {
435
427
setTimeout ( ( ) => {
436
- let queue = [ ] ;
437
428
this . CONTENT_DOM . childNodes . forEach ( ( D ) => {
438
429
let id = D . getAttribute ( 'data-id' ) ;
439
430
if ( this . selected_data . indexOf ( id ) !== - 1 ) {
440
- queue . push ( D ) ;
431
+ this . _triggerEvent . enable = false ;
432
+ D . click ( ) ;
433
+ this . _triggerEvent . enable = true ;
441
434
}
442
435
} ) ;
443
- queue . forEach ( ( D ) => D . click ( ) ) ;
444
436
if ( this . _modSettings . mode === true ) this . DOM . querySelector ( '.menu-list' ) . style . display = 'none' ;
445
437
} ) ;
446
438
if ( this . _useSearchMod === false ) return ;
@@ -486,7 +478,9 @@ window.ComponentDot = class {
486
478
return ;
487
479
}
488
480
if ( this . limit > 0 && this . select_data . length >= this . limit ) {
481
+ this . _triggerEvent . enable = false ;
489
482
list . childNodes [ this . id_line_hash [ this . select_data [ 0 ] . toString ( ) ] ] . click ( ) ;
483
+ this . _triggerEvent . enable = true ;
490
484
}
491
485
option . classList . add ( 'option-active' ) ;
492
486
this . _tagCal ( id , this . MODE . insert ) ;
@@ -533,6 +527,27 @@ window.ComponentDot = class {
533
527
return this ;
534
528
}
535
529
530
+ selected ( selected ) {
531
+ if ( ! Array . isArray ( selected ) ) {
532
+ console . error ( 'Dot param selected must be array [key1,key2...]!' ) ;
533
+ return this ;
534
+ }
535
+ selected = selected . map ( function ( elem ) {
536
+ return elem . toString ( ) ;
537
+ } ) ;
538
+ selected = selected . filter ( d => {
539
+ if ( this . select [ d ] === undefined ) return false ;
540
+ return true ;
541
+ } ) ;
542
+ this . selected_data = selected ;
543
+ return this ;
544
+ }
545
+
546
+ limitNum ( num ) {
547
+ this . limit = num ;
548
+ return this ;
549
+ }
550
+
536
551
mod ( settings = { mode : false , placeholder : '未选择' , height : '150px' , direction :'down' } ) {
537
552
this . _modSettings = Object . assign ( {
538
553
mode : false ,
@@ -550,7 +565,7 @@ window.ComponentDot = class {
550
565
551
566
trigger ( f = function ( ) {
552
567
} ) {
553
- this . _triggerEvent = f ;
568
+ this . _triggerEvent = { func : f , enable : true } ;
554
569
return this ;
555
570
}
556
571
@@ -594,11 +609,7 @@ window.ComponentCascadeDot = class {
594
609
delete : 'delete'
595
610
} ;
596
611
597
- constructor ( selector , select , selected , limit = 0 ) {
598
- if ( ! Array . isArray ( selected ) ) {
599
- console . error ( 'CascadeDot param selected must be array!' ) ;
600
- return ;
601
- }
612
+ constructor ( selector , select ) {
602
613
if ( ! Array . isArray ( select ) || typeof select [ 0 ] !== 'object' ) {
603
614
console . error ( 'CascadeDot param select must be object such as [{"key":1,"val":"root-node","nodes":[]},...] !' ) ;
604
615
return ;
@@ -609,9 +620,9 @@ window.ComponentCascadeDot = class {
609
620
} else {
610
621
this . DOM = document . querySelector ( selector ) ;
611
622
}
612
- this . limit = limit ;
623
+ this . limit = 0 ;
613
624
this . select = select ;
614
- this . selected_data = selected ;
625
+ this . selected_data = [ ] ;
615
626
this . select_data = [ ] ;
616
627
this . insert_data = [ ] ;
617
628
this . delete_data = [ ] ;
@@ -960,6 +971,20 @@ window.ComponentCascadeDot = class {
960
971
return this ;
961
972
}
962
973
974
+ selected ( selected ) {
975
+ if ( ! Array . isArray ( selected ) ) {
976
+ console . error ( 'CascadeDot param selected must be array!' ) ;
977
+ return this ;
978
+ }
979
+ this . selected_data = selected ;
980
+ return this ;
981
+ }
982
+
983
+ limitNum ( num ) {
984
+ this . limit = num ;
985
+ return this ;
986
+ }
987
+
963
988
useHiddenInput ( name ) {
964
989
this . DOM . insertAdjacentHTML ( 'beforeend' , `<input name="${ name } [select]" value="[]" type="hidden" /><input name="${ name } [insert]" value="[]" type="hidden" /><input name="${ name } [delete]" value="[]" type="hidden" />` ) ;
965
990
this . selectInputDOM = this . DOM . querySelector ( `input[name='${ name } [select]']` ) ;
0 commit comments