I am trying to have this work in the code to remove duplication.
Working Code Example: https://jsfiddle.net/w3ctbv1s/1/
In the code below, I was trying to remove at least one player, then I could figure out how to do the others.
I am trying to have this part work in the code:
Code I am working on: https://jsfiddle.net/hxm1y47b/9/
I am thinking it should be able to work in this code.
This is the part from the working code that is responsible for removing the player.
const manageUI = (function makeManageUI() {
function addExitHandlers(callback) {
const resetVideo = document.querySelectorAll(".exitA");
resetVideo.forEach(function resetVideoHandler(video) {
video.addEventListener("click", callback);
});
}
return {
addExitHandlers
};
}());
function removePlayer(wrapper) {
wrapper.player.destroy();
delete wrapper.player;
console.log("removePlayer");
}
function removePlayerHandler(evt) {
const el = evt.target;
const container = el.closest(".containerA"); // Changed ".container" to ".containerA"
const wrapper = container.querySelector(".wrap");
if (wrapper.player) {
return removePlayer(wrapper);
}
}
const loadPlayer = (function uiLoadPlayer() {
function addPlayer(playerSelector, playerOptions) {
const parent = document.querySelector(playerSelector).parentElement;
const callback = managePlayer.adder(parent, playerOptions);
callback();
}
manageUI.addExitHandlers(managePlayer.removePlayerHandler);
return {
add: addPlayer
};
}());