File tree Expand file tree Collapse file tree 1 file changed +37
-9
lines changed
Expand file tree Collapse file tree 1 file changed +37
-9
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,21 @@ function setupPlayer(video) {
22 const container = document . createElement ( 'div' ) ;
33 const icon = document . createElement ( 'div' ) ;
44
5+ const play = ( ) => {
6+ const promise = video . play ( ) ;
7+
8+ container . classList . remove ( 'paused' ) ;
9+
10+ promise ?. catch ( ( ) => {
11+ container . classList . add ( 'paused' ) ;
12+ } ) ;
13+ } ;
14+
15+ const pause = ( ) => {
16+ video . pause ( ) ;
17+ container . classList . add ( 'paused' ) ;
18+ } ;
19+
520 video . parentNode . insertBefore ( container , video ) ;
621
722 icon . classList . add ( 'video-player-icon' ) ;
@@ -10,15 +25,28 @@ function setupPlayer(video) {
1025 container . appendChild ( video ) ;
1126 container . appendChild ( icon ) ;
1227
13- container . addEventListener ( 'click' , ( ) => {
14- if ( video . paused ) {
15- video . play ( ) ;
16- container . classList . remove ( 'paused' ) ;
17- } else {
18- video . pause ( ) ;
19- container . classList . add ( 'paused' ) ;
20- }
21- } ) ;
28+ const feature = video . closest ( '.feature-grid li' ) ;
29+
30+ if ( feature != null ) {
31+ video . removeAttribute ( 'loop' ) ;
32+ video . loop = false ;
33+
34+ feature . addEventListener ( 'mouseenter' , ( ) => {
35+ video . loop = true ;
36+
37+ play ( ) ;
38+ } ) ;
39+
40+ feature . addEventListener ( 'mouseleave' , pause ) ;
41+ } else {
42+ container . addEventListener ( 'click' , ( ) => {
43+ if ( video . paused ) {
44+ play ( ) ;
45+ } else {
46+ pause ( ) ;
47+ }
48+ } ) ;
49+ }
2250
2351 container . style . borderRadius = window . getComputedStyle ( video ) . borderRadius ;
2452
You can’t perform that action at this time.
0 commit comments