@@ -11,25 +11,6 @@ export function init(id, options) {
11
11
const tree = { el, invoke, isVirtualize } ;
12
12
Data . set ( id , tree )
13
13
14
- EventHandler . on ( el , 'mouseenter' , '.tree-content' , e => {
15
- const ele = e . delegateTarget . parentNode
16
- ele . classList . add ( 'hover' )
17
- } )
18
-
19
- EventHandler . on ( el , 'mouseleave' , '.tree-content' , e => {
20
- const ele = e . delegateTarget . parentNode
21
- ele . classList . remove ( 'hover' )
22
- } )
23
-
24
- EventHandler . on ( el , 'click' , '.tree-node' , e => {
25
- const node = e . delegateTarget
26
- const prev = node . previousElementSibling ;
27
- const radio = prev . querySelector ( '[type="radio"]' )
28
- if ( radio && radio . getAttribute ( 'disabled' ) !== 'disabled' ) {
29
- radio . click ( ) ;
30
- }
31
- } )
32
-
33
14
EventHandler . on ( el , 'keydown' , '.tree-root' , e => {
34
15
if ( e . key === 'ArrowDown' || e . key === 'ArrowUp' || e . key === 'ArrowLeft' || e . key === 'ArrowRight' ) {
35
16
const v = el . getAttribute ( 'data-bb-keyboard' ) ;
@@ -41,33 +22,14 @@ export function init(id, options) {
41
22
else if ( e . keyCode === 32 ) {
42
23
const v = el . getAttribute ( 'data-bb-keyboard' ) ;
43
24
if ( v === "true" ) {
44
- const checkbox = el . querySelector ( ".active > .tree-content > .form-check > .form-check-input" ) ;
25
+ const checkbox = el . querySelector ( ".active .form-check-input" ) ;
45
26
if ( checkbox ) {
46
27
e . preventDefault ( ) ;
47
28
checkbox . click ( ) ;
48
29
}
49
30
}
50
31
}
51
32
} ) ;
52
-
53
- if ( isVirtualize ) {
54
- EventHandler . on ( el , 'click' , '.form-check-input' , async e => {
55
- const checkbox = e . delegateTarget ;
56
- const state = checkbox . getAttribute ( 'data-bb-state' ) ;
57
- if ( state ) {
58
- const row = checkbox . closest ( '.tree-content' ) ;
59
- const index = row . getAttribute ( 'data-bb-tree-view-index' ) ;
60
-
61
- const v = state === '1' ? 0 : 1 ;
62
- await setChildrenState ( id , parseInt ( index ) , v ) ;
63
- await setParentState ( id , parseInt ( index ) , v ) ;
64
- const handler = setTimeout ( ( ) => {
65
- checkbox . checked = v === 1 ;
66
- clearTimeout ( handler ) ;
67
- } , 0 ) ;
68
- }
69
- } ) ;
70
- }
71
33
}
72
34
73
35
export function scroll ( id , options ) {
@@ -114,13 +76,7 @@ export function setChildrenState(id, index, state) {
114
76
if ( checkbox ) {
115
77
checkbox . indeterminate = false ;
116
78
checkbox . checked = state === 1 ;
117
- checkbox . setAttribute ( 'data-bb-state' , state ) ;
118
- if ( state === 1 ) {
119
- checkbox . parentElement . classList . add ( 'is-checked' ) ;
120
- }
121
- else {
122
- checkbox . parentElement . classList . remove ( 'is-checked' ) ;
123
- }
79
+ EventHandler . trigger ( checkbox , "statechange.bb.checkbox" , { state } ) ;
124
80
}
125
81
next = next . nextElementSibling ;
126
82
}
@@ -151,7 +107,6 @@ export async function setParentState(id, index, state) {
151
107
for ( let index = 0 ; index < parents . length ; index ++ ) {
152
108
const checkbox = parents [ index ] . querySelector ( '.form-check-input' ) ;
153
109
const result = results [ index ] ;
154
- checkbox . setAttribute ( 'data-bb-state' , result ) ;
155
110
checkbox . indeterminate = false ;
156
111
if ( result === 0 ) {
157
112
checkbox . checked = false ;
@@ -162,6 +117,7 @@ export async function setParentState(id, index, state) {
162
117
else {
163
118
checkbox . indeterminate = true ;
164
119
}
120
+ EventHandler . trigger ( checkbox , "statechange.bb.checkbox" , { state : result } ) ;
165
121
}
166
122
}
167
123
}
@@ -173,14 +129,7 @@ export function dispose(id) {
173
129
Data . remove ( id ) ;
174
130
175
131
if ( tree ) {
176
- const { el, isVirtualize } = tree ;
177
- EventHandler . off ( el , 'mouseenter' ) ;
178
- EventHandler . off ( el , 'mouseleave' ) ;
179
- EventHandler . off ( el , 'click' , '.tree-node' ) ;
132
+ const { el } = tree ;
180
133
EventHandler . off ( el , 'keyup' , '.tree-root' ) ;
181
-
182
- if ( isVirtualize ) {
183
- EventHandler . off ( el , 'click' , '.form-check-input' ) ;
184
- } ;
185
134
}
186
135
}
0 commit comments