Which of these?
or would it be written a different way?
Code 1
https://jsfiddle.net/51aeuy9x/
const videoPlayer = (function makeVideoPlayer() {
let player = null;
function loadPlayer() {
const tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
const firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
function onPlayerReady(event) {
player = event.target;
player.setVolume(100);
}
function addPlayer(video) {
new YT.Player(video, {
width: 606,
height: 344,
videoId: video.dataset.id,
playerVars: {
autoplay: 0,
controls: 1,
showinfo: 1,
rel: 0,
iv_load_policy: 3,
cc_load_policy: 0,
fs: 0,
disablekb: 1
},
events: {
"onReady": onPlayerReady
}
});
}
function init() {
loadPlayer();
}
return {
addPlayer,
init
};
}());
function onYouTubeIframeAPIReady() {
const frameContainer = document.querySelector(".video");
videoPlayer.addPlayer(frameContainer);
}
(function iife() {
function coverClickHandler() {
videoPlayer.init();
}
const cover = document.querySelector(".playa");
cover.addEventListener("click", coverClickHandler);
}());
Code 2
https://jsfiddle.net/qzynsw4j/
const videoPlayer = (function makeVideoPlayer() {
let player = null;
function loadPlayer() {
const tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
const firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
window.onYouTubeIframeAPIReady = function() {
const frameContainer = document.querySelector(".video");
addPlayer(frameContainer);
}
function onPlayerReady(event) {
player = event.target;
player.setVolume(100);
}
function addPlayer(video) {
new YT.Player(video, {
width: 606,
height: 344,
videoId: video.dataset.id,
playerVars: {
autoplay: 0,
controls: 1,
showinfo: 1,
rel: 0,
iv_load_policy: 3,
cc_load_policy: 0,
fs: 0,
disablekb: 1
},
events: {
"onReady": onPlayerReady
}
});
}
function init() {
loadPlayer();
}
return {
addPlayer,
init
};
}());
(function iife() {
function coverClickHandler() {
videoPlayer.init();
}
const cover = document.querySelector(".playa");
cover.addEventListener("click", coverClickHandler);
}());
Code 3
https://jsfiddle.net/wpf3bgha/
const videoPlayer = (function makeVideoPlayer() {
let player = null;
function loadPlayer() {
const tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
const firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
function onPlayerReady(event) {
player = event.target;
player.setVolume(100);
}
window.onYouTubePlayerAPIReady = function() {
const video = document.querySelector(".video");
new YT.Player(video, {
width: 606,
height: 344,
videoId: video.dataset.id,
playerVars: {
autoplay: 0,
controls: 1,
showinfo: 1,
rel: 0,
iv_load_policy: 3,
cc_load_policy: 0,
fs: 0,
disablekb: 1
},
events: {
"onReady": onPlayerReady
}
});
};
function init() {
loadPlayer();
}
return {
init
};
}());
(function iife() {
function coverClickHandler(evt) {
videoPlayer.init();
}
const cover = document.querySelector(".playa");
cover.addEventListener("click", coverClickHandler);
}());