The curtainsConfig is pretty easy - just move the delayOpen part to the top of the code.
const config = {
curtains: {
delayOpen: 3000
}
};
const load = (function () {
...
and in the init function, we refer to that config.curtains object:
const curtainsConfig = {
whenOpened: function () {
addVideo(opts.video);
},
delayOpen: config.curtains.delayOpen
};
That’s the cover config all dealt with. https://jsfiddle.net/xag9m8st/
More difficult is the following player config:
function addVideo(video) {
const playlist = "M7lc1UVf-VE";
new YT.Player(video, {
width: 640,
height: 360,
host: "https://www.youtube-nocookie.com",
playerVars: {
autoplay: 0,
controls: 1,
loop: 1,
rel: 0,
iv_load_policy: 3,
cc_load_policy: 0,
fs: 0,
disablekb: 1,
playlist
},
events: {
"onReady": onPlayerReady,
"onStateChange": onPlayerStateChange
}
});
First, the playlist is moved into playerVars.
// const playlist = "M7lc1UVf-VE";
playerVars: {
playlist: "M7lc1UVf-VE",
autoplay: 0,
...
disablekb: 1
// disablekb: 1,
// playlist
},
We can now extract the player config out to a separate playerConfig object:
const playerConfig = {
width: 640,
...
};
new YT.Player(video, config);
We don’t want all of that playerConfig up at the top of the page. The events part should remain where it is. How we deal with that is to add a player section to the config, and copy the player config information there.
const config = {
curtains: {
...
},
player: {
width: 640,
height: 360,
host: "https://www.youtube-nocookie.com",
playerVars: {
playlist: "M7lc1UVf-VE",
autoplay: 0,
controls: 1,
loop: 1,
rel: 0,
iv_load_policy: 3,
cc_load_policy: 0,
fs: 0,
disablekb: 1
}
}
};
Further down the code in the addVideo function, we refer to parts of that config.player object:
const playerConfig = {
width: config.player.width,
height: config.player.height,
host: config.player.host,
playerVars: config.player.playerVars,
events: {
"onReady": onPlayerReady,
"onStateChange": onPlayerStateChange
}
};
And that’s the player config all dealt with. https://jsfiddle.net/xag9m8st/1/
The configurable information is now all at the top of the code, making it easier to access.