File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed
website/content/public/js Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change 16
16
}
17
17
18
18
const initializeCarousel = ( ) => {
19
+
20
+ // Get all the carousel items from the document.
19
21
let container = document . getElementById ( 'carousel-item-container' ) ;
20
- let items = container . getElementsByClassName ( 'carousel-item' ) ;
21
- const order = Array . from ( { length : items . length } , ( value , index ) => index ) ;
22
- shuffle ( order ) ;
23
- for ( let i = 0 ; i < order . length ; i ++ ) {
24
- container . appendChild ( items [ order [ i ] ] ) ;
25
- }
26
- container . children [ 0 ] . className += ' active' ;
22
+ let items = Array . from ( container . getElementsByClassName ( 'carousel-item' ) ) ;
23
+
24
+ // Remove them before we add them back shuffled.
25
+ for ( let i = 0 ; i < items . length ; i ++ )
26
+ container . removeChild ( items [ i ] ) ;
27
+
28
+ // Since we made a copy we can shuffle it directly.
29
+ shuffle ( items ) ;
30
+
31
+ // Add the items back in the new order.
32
+ for ( let i = 0 ; i < items . length ; i ++ )
33
+ container . appendChild ( items [ i ] ) ;
27
34
35
+ // Make the first one visible.
36
+ container . children [ 0 ] . className += ' active' ;
28
37
}
29
38
30
39
initializeCarousel ( ) ;
You can’t perform that action at this time.
0 commit comments