I do not think having everything lumped together like this is a good idea, and should be avoided.
https://jsfiddle.net/6uyahwbg/
function userAgent() {
const theBody = document.querySelector("body");
theBody.classList.remove("bg1");
const theActive = document.querySelector(".with-curtain.active");
theActive.classList.remove("active");
const theHides = document.querySelectorAll(".hide");
theHides.forEach(function needsAName(removeHide) {
removeHide.classList.remove("hide");
});
}
So, I separated them into separate functions here:
Is the flow of how these functions are organized with separation good?
Is there anything I should change or adjust?
https://jsfiddle.net/e7a304df/
Does that look right?
or should those be in a different order?
1st function showHidden() {
2nd function showBody() {
3rd function showActive() {
Should showActive be under showHidden instead?
I’m a little confused on what the order of those should be.
That would look like this then:
https://jsfiddle.net/gjuybfed/
function showHidden() {
const theHides = document.querySelectorAll(".hide");
theHides.forEach(function needsAName(removeHide) {
removeHide.classList.remove("hide");
});
}
function showActive() {
const theActive = document.querySelector(".with-curtain.active");
theActive.classList.remove("active");
}
function showBody() {
const theBody = document.querySelector("body");
theBody.classList.remove("bg1");
showHidden();
showActive();
}
function homeClickHandler() {
showBody();
}
I was thinking about doing it this way:
Would this way be better?
https://jsfiddle.net/1zeh93ko/
function showHidden() {
const theHides = document.querySelectorAll(".hide");
theHides.forEach(function needsAName(removeHide) {
removeHide.classList.remove("hide");
});
}
function showBody() {
const theBody = document.querySelector("body");
theBody.classList.remove("bg1");
const theActive = document.querySelector(".with-curtain.active");
theActive.classList.remove("active");
showHidden();
}
function homeClickHandler() {
showBody();
}
I also don’t know what to call this function: It needs a name.
theHides.forEach(function needsAName(removeHide) {
With this one
I changed this:
function showCovers(playButton) {
const cover = playButton.parentElement;
cover.classList.add("active");
show(cover);
const theBody = document.querySelector("body");
theBody.classList.add("bg1");
}
To this:
const manageCover = (function makeManageCover() {
function showBody() {
const theBody = document.querySelector("body");
theBody.classList.add("bg1");
}
function showCovers(playButton) {
const cover = playButton.parentElement;
cover.classList.add("active");
show(cover);
showBody();
}
function coverClickHandler(evt) {
hideAll(config.containers);
const cover = evt.currentTarget;
showCovers(cover);
}
Though, I probably could have left it as this:
function showCovers(playButton) {
const cover = playButton.parentElement;
cover.classList.add("active");
show(cover);
const theBody = document.querySelector("body");
theBody.classList.add("bg1");
}
What do you think?