Skip to content

Commit

Permalink
Applied new perfectionist rules
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Nov 25, 2024
1 parent 3ca5ba0 commit af17840
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 51 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import js from "@eslint/js";
import eslintComments from "@eslint-community/eslint-plugin-eslint-comments";
import commentsConfig from "@eslint-community/eslint-plugin-eslint-comments/configs";
import js from "@eslint/js";
import compat from "eslint-plugin-compat";
import perfectionist from "eslint-plugin-perfectionist";
import playwright from "eslint-plugin-playwright";
Expand Down
2 changes: 0 additions & 2 deletions src/lib/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,9 @@ export function State(
function transitionInNewImage(): void {
currentImageView?.transitionIn(
removeActivityIndicatorFromDOM,
/* eslint-disable @typescript-eslint/no-use-before-define -- Cyclical dependencies */
previous,
next,
close,
/* eslint-enable */
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function darkenOverlay(): void {
container.classList.add("ilb-overlay");
}

export function transitionOutContainer(): void {
container.style.opacity = "0";
export function getContainer(): HTMLDivElement {
return container;
}

export function removeContainerFromDOM(): void {
Expand All @@ -45,6 +45,6 @@ export function removeContainerFromDOM(): void {
document.body.classList.remove("ilb-body");
}

export function getContainer(): HTMLDivElement {
return container;
export function transitionOutContainer(): void {
container.style.opacity = "0";
}
70 changes: 35 additions & 35 deletions src/lib/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,6 @@ interface HistoryState {
imageLightboxSet?: string;
}

export function pushQuitToHistory(): void {
let newQuery = removeQueryField(
document.location.search,
"imageLightboxIndex",
);
newQuery = removeQueryField(newQuery, "imageLightboxSet");
window.history.pushState({}, "", document.location.pathname + newQuery);
}

export function pushToHistory(
index: number,
set: string | undefined,
images: Array<HTMLAnchorElement>,
): void {
const newIndex = images[index].dataset["ilb2Id"] ?? index.toString();
let newQuery = addQueryField(
document.location.search,
"imageLightboxIndex",
newIndex,
);
const newHistoryState: HistoryState = {
imageLightboxIndex: newIndex,
imageLightboxSet: "",
};
if (set !== undefined) {
newHistoryState.imageLightboxSet = set;
newQuery = addQueryField(newQuery, "imageLightboxSet", set);
}
window.history.pushState(
newHistoryState,
"",
document.location.pathname + newQuery,
);
}

export function openHistory(
set: string | undefined,
images: Array<HTMLAnchorElement>,
Expand Down Expand Up @@ -109,3 +74,38 @@ export function popHistory(
true,
);
}

export function pushQuitToHistory(): void {
let newQuery = removeQueryField(
document.location.search,
"imageLightboxIndex",
);
newQuery = removeQueryField(newQuery, "imageLightboxSet");
window.history.pushState({}, "", document.location.pathname + newQuery);
}

export function pushToHistory(
index: number,
set: string | undefined,
images: Array<HTMLAnchorElement>,
): void {
const newIndex = images[index].dataset["ilb2Id"] ?? index.toString();
let newQuery = addQueryField(
document.location.search,
"imageLightboxIndex",
newIndex,
);
const newHistoryState: HistoryState = {
imageLightboxIndex: newIndex,
imageLightboxSet: "",
};
if (set !== undefined) {
newHistoryState.imageLightboxSet = set;
newQuery = addQueryField(newQuery, "imageLightboxSet", set);
}
window.history.pushState(
newHistoryState,
"",
document.location.pathname + newQuery,
);
}
18 changes: 9 additions & 9 deletions src/lib/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ export function addNavigationItems(
}
}

export function changeNavigationCurrent(currentIndex: number): void {
for (let i = 0; i < navigation.children.length; i++) {
navigation.children.item(i)?.classList.remove("ilb-navigation-active");
}
navigation.children
.item(currentIndex)
?.classList.add("ilb-navigation-active");
}

export function addNavigationToDOM(
images: Array<HTMLAnchorElement>,
currentIndexFn: () => number | null,
Expand All @@ -70,3 +61,12 @@ export function addNavigationToDOM(
e.stopPropagation();
});
}

export function changeNavigationCurrent(currentIndex: number): void {
for (let i = 0; i < navigation.children.length; i++) {
navigation.children.item(i)?.classList.remove("ilb-navigation-active");
}
navigation.children
.item(currentIndex)
?.classList.add("ilb-navigation-active");
}

0 comments on commit af17840

Please sign in to comment.