File tree Expand file tree Collapse file tree 2 files changed +42
-5
lines changed
Expand file tree Collapse file tree 2 files changed +42
-5
lines changed Original file line number Diff line number Diff line change 1- .custom-block {
2- padding : 1rem ;
3- background-color : # f0f0f0 ;
4- text-align : center;
5- border : 1px solid # ccc ;
1+ /* blocks/custom/custom.css */
2+
3+ .block .custom {
4+ position : relative;
5+ overflow : hidden;
6+ width : 100% ;
7+ max-width : 100% ;
8+ aspect-ratio : 16 / 9 ;
9+ }
10+
11+ .block .custom iframe {
12+ width : 100% ;
13+ height : 100% ;
14+ border : none;
15+ pointer-events : none;
16+ display : block;
617}
Original file line number Diff line number Diff line change 1+ // blocks/custom/custom.js
2+
3+ /**
4+ * Custom video block: expects a table with column "ID"
5+ * and values like "dQw4w9WgXcQ" (YouTube video ID)
6+ * It autoplays, loops, mutes and hides controls.
7+ */
8+
9+ export default function decorate ( block ) {
10+ const idCell = block . querySelector ( 'div > div' ) ;
11+ if ( ! idCell ) return ;
12+
13+ const videoId = idCell . textContent . trim ( ) ;
14+ if ( ! videoId ) return ;
15+
16+ const iframe = document . createElement ( 'iframe' ) ;
17+ iframe . src = `https://www.youtube.com/embed/${ videoId } ?autoplay=1&loop=1&playlist=${ videoId } &mute=1&controls=0&rel=0&playsinline=1&disablekb=1` ;
18+ iframe . title = 'YouTube Video' ;
19+ iframe . allow = 'autoplay; encrypted-media' ;
20+ iframe . allowFullscreen = false ;
21+ iframe . setAttribute ( 'tabindex' , '-1' ) ;
22+ iframe . style = 'border: 0; width: 100%; aspect-ratio: 16/9; pointer-events: none;' ;
23+
24+ block . innerHTML = '' ;
25+ block . appendChild ( iframe ) ;
26+ }
You can’t perform that action at this time.
0 commit comments