Skip to content

Commit 9eec1cc

Browse files
auto play for youtube as default
1 parent b381d8e commit 9eec1cc

File tree

1 file changed

+22
-2
lines changed
  • packages/builder-web-core/widgets-native/html-iframe-youtube

1 file changed

+22
-2
lines changed

packages/builder-web-core/widgets-native/html-iframe-youtube/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff 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("&");

0 commit comments

Comments
 (0)