File tree Expand file tree Collapse file tree
packages/builder-web-core/widgets-native/html-iframe-youtube Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,11 +22,31 @@ export class HtmlIframeYoutube extends HtmlIframe {
2222 loading,
2323 sandbox,
2424 referrerpolicy,
25- src : yturl ( video ) ,
25+ src : yturl ( video , { autoplay : true } ) ,
2626 } ) ;
2727 }
2828}
2929
30- function yturl ( video : string ) : string {
30+ function yturl (
31+ video : string ,
32+ opt ?: {
33+ autoplay ?: boolean ;
34+ }
35+ ) : string {
36+ const q = { } ;
37+
38+ if ( opt ?. autoplay ) {
39+ q [ "autoplay" ] = "1" ;
40+ }
41+
42+ if ( Object . keys ( q ) . length > 0 ) {
43+ return `https://www.youtube.com/embed/${ video } ?${ buildq ( q ) } ` ;
44+ }
45+
3146 return `https://www.youtube.com/embed/${ video } ` ;
3247}
48+
49+ const buildq = ( q : object ) : string =>
50+ Object . keys ( q )
51+ . map ( ( k ) => `${ encodeURIComponent ( k ) } =${ encodeURIComponent ( q [ k ] ) } ` )
52+ . join ( "&" ) ;
You can’t perform that action at this time.
0 commit comments