Skip to content

Commit

Permalink
Updated docs to reflect default options changes
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Oct 6, 2024
1 parent 7f43264 commit e6b9195
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 282 deletions.
9 changes: 9 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ header h2 {
margin-bottom: 0.625em;
}

#main_content h2:first-child {
border-top: none;
}

p {
margin-bottom: 20px;
}
Expand All @@ -240,6 +244,11 @@ ul li {
margin: 0.625em;
}

#main_content section {
border-top: 1px solid #999;
padding-bottom: 20px;
}

footer {
padding-bottom: 30px;
background: transparent url("../images/hr.png") 0 0 no-repeat;
Expand Down
343 changes: 138 additions & 205 deletions src/index.html

Large diffs are not rendered by default.

116 changes: 50 additions & 66 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,77 @@ import { ImageLightbox } from "./lib/imagelightbox";
declare const TEST: boolean | undefined;
const isTest: boolean = typeof TEST !== "undefined" ? TEST : false;

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="a"]'), {
activity: true,
new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="basic"]'), {
...(isTest && { animationSpeed: 0 }),
});

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="video"]'), {
...(isTest && { animationSpeed: 0 }),
});

new ImageLightbox(
document.querySelectorAll('a[data-imagelightbox="allowedtypes"]'),
document.querySelectorAll('a[data-imagelightbox="minimal"]'),
{
allowedTypes: "gif",
activity: false,
arrows: false,
button: false,
fullscreen: false,
overlay: false,
quitOnDocClick: false,
...(isTest && { animationSpeed: 0 }),
},
);

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="b"]'), {
overlay: true,
...(isTest && { animationSpeed: 0 }),
});

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="c"]'), {
button: true,
quitOnDocClick: false,
...(isTest && { animationSpeed: 0 }),
});

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="d"]'), {
caption: true,
...(isTest && { animationSpeed: 0 }),
});

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="e"]'), {
navigation: true,
...(isTest && { animationSpeed: 0 }),
});
new ImageLightbox(
document.querySelectorAll('a[data-imagelightbox="caption"]'),
{
caption: true,
...(isTest && { animationSpeed: 0 }),
},
);

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="f"]'), {
arrows: true,
...(isTest && { animationSpeed: 0 }),
});
new ImageLightbox(
document.querySelectorAll('a[data-imagelightbox="navigation"]'),
{
navigation: true,
...(isTest && { animationSpeed: 0 }),
},
);

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="quit"]'), {
quitOnEnd: true,
quitOnDocClick: false,
quitOnEnd: false,
quitOnImgClick: true,
...(isTest && { animationSpeed: 0 }),
});

new ImageLightbox(
document.querySelectorAll('a[data-imagelightbox="fullscreen"]'),
document.querySelectorAll('a[data-imagelightbox="history"]'),
{
fullscreen: true,
history: true,
...(isTest && { animationSpeed: 0 }),
},
);

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="g"]'), {
activity: true,
arrows: true,
button: true,
caption: true,
navigation: true,
overlay: true,
quitOnDocClick: false,
...(isTest && { animationSpeed: 0 }),
});
new ImageLightbox(
document.querySelectorAll('a[data-imagelightbox="history-ids"]'),
{
history: true,
...(isTest && { animationSpeed: 0 }),
},
);

new ImageLightbox(
document.querySelectorAll('a[data-imagelightbox="allowedtypes"]'),
{
allowedTypes: "gif",
...(isTest && { animationSpeed: 0 }),
},
);

const manualOpenGallery = new ImageLightbox(
document.querySelectorAll('a[data-imagelightbox="h"]'),
document.querySelectorAll('a[data-imagelightbox="trigger"]'),
{
arrows: true,
...(isTest && { animationSpeed: 0 }),
},
);
Expand All @@ -81,9 +85,8 @@ document
});

const dynamicAddingGallery = new ImageLightbox(
document.querySelectorAll('a[data-imagelightbox="i"]'),
document.querySelectorAll('a[data-imagelightbox="dynamic"]'),
{
arrows: true,
...(isTest && { animationSpeed: 0 }),
},
);
Expand All @@ -98,7 +101,7 @@ document
linkContainer?.appendChild(newLi);

const newAnchor = document.createElement("a");
newAnchor.dataset["imagelightbox"] = "i";
newAnchor.dataset["imagelightbox"] = "dynamic";
newAnchor.href = "images/demo4.jpg";
newLi.appendChild(newAnchor);

Expand All @@ -107,29 +110,10 @@ document
newAnchor.appendChild(newImg);

dynamicAddingGallery.addImages(
document.querySelectorAll('a[data-imagelightbox="i"]'),
document.querySelectorAll('a[data-imagelightbox="dynamic"]'),
);
});

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="j"]'), {
arrows: true,
history: true,
...(isTest && { animationSpeed: 0 }),
});

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="k"]'), {
arrows: true,
history: true,
...(isTest && { animationSpeed: 0 }),
});

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="video"]'), {
activity: true,
arrows: true,
overlay: true,
...(isTest && { animationSpeed: 0 }),
});

new ImageLightbox(document.querySelectorAll('a[data-imagelightbox="events"]'), {
...(isTest && { animationSpeed: 0 }),
});
Expand Down
6 changes: 3 additions & 3 deletions tests/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test("has correct title", async ({ page }) => {

test("opens and closes the lightbox", async ({ page }) => {
await page.goto("/");
await page.getByTestId("activity").getByRole("link").first().click();
await page.getByTestId("basic").getByRole("link").first().click();
await expect(page.locator("#ilb-activity-indicator")).toBeVisible();
await expect(page.locator("#ilb-image")).toBeVisible();
await expect(page.locator("#ilb-activity-indicator")).toBeHidden();
Expand Down Expand Up @@ -53,7 +53,7 @@ test("can add images dynamically", async ({ page }) => {

test("quits on end", async ({ page }) => {
await page.goto("/");
await page.getByTestId("quit").getByRole("link").first().click();
await page.getByTestId("basic").getByRole("link").first().click();
await expect(page.locator("#ilb-image")).toBeVisible();
await expect(page.locator("#ilb-image")).toHaveAttribute(
"src",
Expand All @@ -75,7 +75,7 @@ test("quits on end", async ({ page }) => {
);
await page.keyboard.press("ArrowRight");
await expect(page.locator("#ilb-image")).toBeHidden();
await page.getByTestId("quit").getByRole("link").first().click();
await page.getByTestId("basic").getByRole("link").first().click();
await expect(page.locator("#ilb-image")).toBeVisible();
await expect(page.locator("#ilb-image")).toHaveAttribute(
"src",
Expand Down
4 changes: 2 additions & 2 deletions tests/decorations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test.beforeEach(async ({ page }) => {

test("shows the overlay", async ({ page }) => {
await page.goto("/");
await page.getByTestId("overlay").getByRole("link").first().click();
await page.getByTestId("basic").getByRole("link").first().click();
await expect(page.locator("#ilb-image")).toBeVisible();
await expect(page.locator("#ilb-image")).toHaveAttribute(
"src",
Expand All @@ -22,7 +22,7 @@ test("shows the overlay", async ({ page }) => {

test("can be closed with the close button", async ({ page }) => {
await page.goto("/");
await page.getByTestId("close-button").getByRole("link").first().click();
await page.getByTestId("basic").getByRole("link").first().click();
await expect(page.locator("#ilb-image")).toBeVisible();
await expect(page.locator("#ilb-image")).toHaveAttribute(
"src",
Expand Down
6 changes: 3 additions & 3 deletions tests/history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test("has a working history", async ({ page }) => {
});

test("can open history links", async ({ page }) => {
await page.goto("/?imageLightboxIndex=2&imageLightboxSet=j");
await page.goto("/?imageLightboxIndex=2&imageLightboxSet=history");
await expect(page.locator("#ilb-image")).toBeVisible();
await expect(page.locator("#ilb-image")).toHaveAttribute(
"src",
Expand All @@ -51,7 +51,7 @@ test("can open history links", async ({ page }) => {

test.describe("doesn't break on invalid history links", () => {
test("invalid index", async ({ page }) => {
await page.goto("/?imageLightboxIndex=42&imageLightboxSet=j");
await page.goto("/?imageLightboxIndex=42&imageLightboxSet=history");
await expect(page.locator("#ilb-image")).toBeHidden();
});
test("no index", async ({ page }) => {
Expand Down Expand Up @@ -99,7 +99,7 @@ test("has a working history with IDs", async ({ page }) => {
});

test("can open history links with IDs", async ({ page }) => {
await page.goto("/?imageLightboxIndex=2&imageLightboxSet=k");
await page.goto("/?imageLightboxIndex=2&imageLightboxSet=history-ids");
await expect(page.locator("#ilb-image")).toBeVisible();
await expect(page.locator("#ilb-image")).toHaveAttribute(
"src",
Expand Down
6 changes: 3 additions & 3 deletions tests/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test.beforeEach(async ({ page }) => {

test("can be controlled with image clicks", async ({ page }) => {
await page.goto("/");
await page.getByTestId("overlay").getByRole("link").first().click();
await page.getByTestId("basic").getByRole("link").first().click();
await expect(page.locator("#ilb-image")).toBeVisible();
await expect(page.locator("#ilb-image")).toHaveAttribute(
"src",
Expand Down Expand Up @@ -49,7 +49,7 @@ test("can be controlled with image clicks", async ({ page }) => {

test("can be controlled with keyboard", async ({ page }) => {
await page.goto("/");
await page.getByTestId("fullscreen").getByRole("link").first().click();
await page.getByTestId("basic").getByRole("link").first().click();
await expect(page.locator("#ilb-image")).toBeVisible();
await expect(page.locator("#ilb-image")).toHaveAttribute(
"src",
Expand Down Expand Up @@ -88,7 +88,7 @@ test("can be controlled with keyboard", async ({ page }) => {

test("can be controlled with arrows", async ({ page }) => {
await page.goto("/");
await page.getByTestId("arrows").getByRole("link").first().click();
await page.getByTestId("quit").getByRole("link").first().click();
await expect(page.locator("#ilb-image")).toBeVisible();
await expect(page.locator("#ilb-image")).toHaveAttribute(
"src",
Expand Down

0 comments on commit e6b9195

Please sign in to comment.