@@ -3,46 +3,45 @@ customElements.define('summary-display',
3
3
constructor ( ) {
4
4
super ( ) ;
5
5
6
- let template = document . getElementById ( 'summary-display-template' ) ;
7
- let templateContent = template . content ;
6
+ const template = document . getElementById ( 'summary-display-template' ) ;
7
+ const templateContent = template . content ;
8
8
9
- let shadowRoot = this . attachShadow ( { mode : 'open' } ) ;
9
+ const shadowRoot = this . attachShadow ( { mode : 'open' } ) ;
10
10
shadowRoot . appendChild ( templateContent . cloneNode ( true ) ) ;
11
11
12
- let items = this . querySelectorAll ( 'li' ) ;
13
- let descriptions = this . querySelectorAll ( 'p' ) ;
12
+ const items = Array . from ( this . querySelectorAll ( 'li' ) ) ;
13
+ const descriptions = Array . from ( this . querySelectorAll ( 'p' ) ) ;
14
14
15
- for ( let i = 0 ; i < items . length ; i ++ ) {
16
- handleClick ( items [ i ] ) ;
17
- }
15
+ items . forEach ( item => {
16
+ handleClick ( item ) ;
17
+ } ) ;
18
18
19
19
function handleClick ( item ) {
20
20
item . addEventListener ( 'click' , function ( ) {
21
- for ( let i = 0 ; i < items . length ; i ++ ) {
22
- items [ i ] . style . backgroundColor = 'white' ;
23
- }
21
+ items . forEach ( item => {
22
+ item . style . backgroundColor = 'white' ;
23
+ } ) ;
24
24
25
- for ( let j = 0 ; j < descriptions . length ; j ++ ) {
26
- updateDisplay ( descriptions [ j ] , item ) ;
27
- }
25
+ descriptions . forEach ( description => {
26
+ updateDisplay ( description , item ) ;
27
+ } ) ;
28
28
} ) ;
29
29
}
30
30
31
31
function updateDisplay ( description , item ) {
32
32
description . removeAttribute ( 'slot' ) ;
33
33
34
34
if ( description . getAttribute ( 'data-name' ) === item . textContent ) {
35
- description . setAttribute ( 'slot' , 'choice' ) ;
35
+ description . setAttribute ( 'slot' , 'choice' ) ;
36
36
item . style . backgroundColor = '#bad0e4' ;
37
- } else {
38
-
39
37
}
40
38
}
41
39
42
- let slots = this . shadowRoot . querySelectorAll ( 'slot' ) ;
40
+ const slots = this . shadowRoot . querySelectorAll ( 'slot' ) ;
43
41
slots [ 1 ] . addEventListener ( 'slotchange' , function ( e ) {
44
- let nodes = slots [ 1 ] . assignedNodes ( ) ;
45
- console . log ( ' Element in Slot "' + slots [ 1 ] . name + ' " changed to "' + nodes [ 0 ] . outerHTML + '".' ) ;
42
+ const nodes = slots [ 1 ] . assignedNodes ( ) ;
43
+ console . log ( ` Element in Slot "${ slots [ 1 ] . name } " changed to "${ nodes [ 0 ] . outerHTML } ".` ) ;
46
44
} ) ;
45
+ }
47
46
}
48
- } ) ;
47
+ ) ;
0 commit comments