Commit 8966384 1 parent 6144260 commit 8966384 Copy full SHA for 8966384
File tree 1 file changed +35
-5
lines changed
1 file changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -11,17 +11,47 @@ const ClassName = {
11
11
} ;
12
12
13
13
function toggleCut ( element : HTMLElement ) {
14
- const cutEl = element . parentNode as HTMLElement ;
15
- cutEl . classList . toggle ( ClassName . OPEN ) ;
14
+ const cutNode = element . parentNode ;
15
+
16
+ if ( ! ( cutNode instanceof HTMLElement ) ) {
17
+ return ;
18
+ }
19
+
20
+ cutNode . classList . toggle ( ClassName . OPEN ) ;
21
+ }
22
+
23
+ function matchTitle ( target : EventTarget | null ) {
24
+ if ( ! ( target instanceof HTMLElement ) ) {
25
+ return false ;
26
+ }
27
+
28
+ return target ?. matches ?.( Selector . TITLE ) ;
29
+ }
30
+
31
+ function findTitleInPath ( event : MouseEvent ) : HTMLElement | undefined {
32
+ const target = getEventTarget ( event ) ;
33
+
34
+ if ( matchTitle ( target ) ) {
35
+ return target as HTMLElement ;
36
+ }
37
+
38
+ const path = event . composedPath ?.( ) ;
39
+
40
+ return path ?. find ( matchTitle ) as HTMLElement | undefined ;
16
41
}
17
42
18
43
if ( typeof document !== 'undefined' ) {
19
44
document . addEventListener ( 'click' , ( event ) => {
20
- const target = getEventTarget ( event ) as HTMLElement ;
21
- if ( isCustom ( event ) || ! target . matches ( Selector . TITLE ) ) {
45
+ if ( isCustom ( event ) ) {
46
+ return ;
47
+ }
48
+
49
+ const title = findTitleInPath ( event ) ;
50
+
51
+ if ( ! title ) {
22
52
return ;
23
53
}
24
54
25
- toggleCut ( target ) ;
55
+ toggleCut ( title ) ;
26
56
} ) ;
27
57
}
You can’t perform that action at this time.
0 commit comments