Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small refactor that makes the file %26 smaller #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/animations.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 28 additions & 20 deletions scripts/animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@
* genesis/scripts/animations.js
*/

const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
if (entry.target.classList.contains("anim-slide-right-appear")) {
entry.target.classList.add("slide-right-appear");
} else if (entry.target.classList.contains("anim-slide-up-appear")) {
entry.target.classList.add("slide-up-appear");
} else if (entry.target.classList.contains("anim-appear")) {
entry.target.classList.add("appear");
} else if (entry.target.classList.contains("anim-slide-down-appear")) {
entry.target.classList.add("slide-down-appear");
} else if (entry.target.classList.contains("anim-slide-in-place-right")) {
entry.target.classList.add("slide-in-place-right");
} else if(entry.target.classList.contains("anim-gallery-staggered-appear")) {
applyCssToChildren(entry, "staggered-appear");
} else if (entry.target.classList.contains("anim-slide-left-appear")) {
entry.target.classList.add("slide-left-appear");
}
}
const animationCN = [
"anim-slide-right-appear",
"anim-slide-up-appear",
"anim-appear",
"anim-slide-down-appear",
"anim-slide-in-place-right",
"anim-gallery-staggered-appear",
"anim-slide-left-appear"
];

function buildQuery() {
let query = "";
animationCN.forEach((an) => {
query += `.${an},`;
});
return query;
}

function addMatchingFunction(e) {
if (e.isIntersecting)
animationCN.forEach((an) => {
if (e.target.classList.contains(an))
e.target.classList.add(an.replace("anim-", ""));
});
}

const observer = new IntersectionObserver(entries => {
entries.forEach(entry => addMatchingFunction(entry));
});

function applyDelayToChildren(parent, multiplier) {
Expand Down Expand Up @@ -54,7 +62,7 @@ function preprocessTargets() {

var genesis = typeof genesis !== 'undefined' ? genesis : (genesis = 313, console.log("Close the world, .txen eht nepO :: genesis by arbeit studio"), genesis);
preprocessTargets();
const query = ".anim-slide-down-appear,.anim-slide-right-appear,.anim-slide-up-appear,.anim-appear,.anim-slide-in-place-right,.anim-gallery-staggered-appear,.anim-slide-left-appear";
const query = buildQuery();
let targets = document.querySelectorAll(query);
targets.forEach(target => {
observer.observe(target);
Expand Down