@@ -1124,6 +1124,86 @@ <h2>Possibilities</h2>
11241124 } ) ;
11251125 } ) ( ) ;
11261126 </ script >
1127+
1128+ <!--
1129+ =========================================================================
1130+ Generic Video Play Overlay Script
1131+ =========================================================================
1132+ Automatically initializes play overlays for all <video data-play-overlay>
1133+ elements. The script:
1134+ 1. Wraps each video in a .video-overlay-container
1135+ 2. Injects a .video-play-overlay button with a CSS play icon
1136+ 3. Handles click, Enter, and Space to play the video
1137+ 4. Shows native controls after playback starts
1138+ 5. Re-shows the overlay when the video ends (for replay)
1139+
1140+ To opt-in a new video, simply add the data-play-overlay attribute:
1141+ <video data-play-overlay poster="thumb.png" ...>
1142+ <source src="video.mp4" type="video/mp4">
1143+ </video>
1144+ =========================================================================
1145+ -->
1146+ < script >
1147+ ( function initVideoPlayOverlays ( ) {
1148+ // Prevent double-initialization
1149+ if ( window . __videoPlayOverlaysInitialized ) return ;
1150+ window . __videoPlayOverlaysInitialized = true ;
1151+
1152+ const videos = document . querySelectorAll ( 'video[data-play-overlay]' ) ;
1153+ if ( ! videos . length ) return ;
1154+
1155+ videos . forEach ( function ( video ) {
1156+ // Remove autoplay to ensure video doesn't start on page load
1157+ video . removeAttribute ( 'autoplay' ) ;
1158+
1159+ // Create container wrapper
1160+ const container = document . createElement ( 'div' ) ;
1161+ container . className = 'video-overlay-container' ;
1162+
1163+ // Insert container before video, then move video inside
1164+ video . parentNode . insertBefore ( container , video ) ;
1165+ container . appendChild ( video ) ;
1166+
1167+ // Create overlay button
1168+ const overlay = document . createElement ( 'div' ) ;
1169+ overlay . className = 'video-play-overlay' ;
1170+ overlay . setAttribute ( 'tabindex' , '0' ) ;
1171+ overlay . setAttribute ( 'role' , 'button' ) ;
1172+ overlay . setAttribute ( 'aria-label' , 'Play video' ) ;
1173+
1174+ // Create play icon (CSS-styled circle + triangle)
1175+ const playIcon = document . createElement ( 'div' ) ;
1176+ playIcon . className = 'play-icon' ;
1177+ overlay . appendChild ( playIcon ) ;
1178+
1179+ // Insert overlay into container
1180+ container . appendChild ( overlay ) ;
1181+
1182+ // Activation handler: play video, hide overlay, show controls
1183+ function activateVideo ( ) {
1184+ video . play ( ) ;
1185+ overlay . classList . add ( 'hidden' ) ;
1186+ video . controls = true ;
1187+ }
1188+
1189+ // Click handler
1190+ overlay . addEventListener ( 'click' , activateVideo ) ;
1191+
1192+ // Keyboard handler (Enter or Space)
1193+ overlay . addEventListener ( 'keydown' , function ( e ) {
1194+ if ( e . key === 'Enter' || e . key === ' ' ) {
1195+ e . preventDefault ( ) ;
1196+ activateVideo ( ) ;
1197+ }
1198+ } ) ;
1199+
1200+ // When video ends, show overlay again for replay
1201+ video . addEventListener ( 'ended' , function ( ) {
1202+ overlay . classList . remove ( 'hidden' ) ;
1203+ } ) ;
1204+ } ) ;
1205+ } ) ( ) ;
1206+ </ script >
11271207</ body >
11281208</ html >
11291209
0 commit comments