{
// Other internal links won't work and are disabled; external ones are forced to
// open a new tab as the results of trying to display a web page in the bloom-player
// iframe or webview can be confusing.
- // private fixInternalHyperlinks(div: HTMLDivElement | null): void {
- // if (!div) {
- // return;
- // }
- // const anchors = Array.from(div.getElementsByTagName("a") ?? []);
- // anchors.forEach((a) => {
- // const href = a.getAttribute("href"); // not a.href, which has the full page address prepended.
- // if (href?.startsWith("#")) {
- // const pageId = href.substring(1);
- // const pageNum = this.state.pageIdToIndexMap[pageId];
- // if (pageNum !== undefined) {
- // a.href = ""; // may not be needed, on its own was unsuccessful in stopping attempted default navigation
- // a.onclick = (ev) => {
- // ev.preventDefault(); // don't try to follow the link, other than by the slideTo below
- // ev.stopPropagation(); // don't allow parent listeners, particularly the one that toggles the nav bar
- // this.swiperInstance.slideTo(pageNum);
- // };
- // } else {
- // // no other kind of internal link makes sense, so let them be ignored.
- // a.onclick = (ev) => {
- // ev.preventDefault();
- // ev.stopPropagation();
- // };
- // }
- // } else {
- // // an external link. It will likely confuse things to follow it inside whatever iframe or webview
- // // bloom player may be running in, so encourage opening a new tab or similar action.
- // a.setAttribute("target", "blank");
- // }
- // });
- // }
// What we need to do when the page narration is completed (if autoadvance, go to next page).
public handlePageNarrationComplete = (page: HTMLElement | undefined) => {
diff --git a/src/navigation.test.ts b/src/navigation.test.ts
index c996e2a..64cf2bc 100644
--- a/src/navigation.test.ts
+++ b/src/navigation.test.ts
@@ -132,6 +132,16 @@ describe("Navigation functions", () => {
const thirdBack = goBackInHistoryIfPossible("book1");
expect(thirdBack).toBeUndefined();
});
+
+ test("doesn't die if an href is empty", () => {
+ const event = createClickEvent("");
+ const result = checkClickForBookOrPageJump(
+ event,
+ "doesn't matter",
+ () => "doesn't matter",
+ );
+ expect(result).toEqual(undefined);
+ });
});
});
diff --git a/src/navigation.ts b/src/navigation.ts
index 37f2318..78aaa29 100644
--- a/src/navigation.ts
+++ b/src/navigation.ts
@@ -5,15 +5,15 @@ type ILocation = { bookUrl?: string; pageId?: string };
export function canGoBack() {
return jumpHistory.length > 0;
}
-export function goBackInHistoryIfPossible(
+export function tryPopPlayerHistory(
currentBookId: string,
): ILocation | undefined {
const previousLocation = jumpHistory.pop();
if (previousLocation) {
- console.log(
- "Going Back. Current History is: ",
- JSON.stringify(jumpHistory, null, 2),
- );
+ // console.log(
+ // "Going Back. Current History is: ",
+ // JSON.stringify(jumpHistory, null, 2),
+ // );
return {
bookUrl:
currentBookId === previousLocation.bookId
@@ -24,15 +24,12 @@ export function goBackInHistoryIfPossible(
}
return undefined;
}
-function urlFromBookId(bookId: string) {
- return `/book/${bookId}/index.htm`;
-}
export function checkClickForBookOrPageJump(
event: any,
currentBookInstanceId: string,
- getCurentPageId: () => string,
-): ILocation {
+ getCurrentPageId: () => string,
+): ILocation | undefined {
const linkElement = (event.target as HTMLElement).closest(
"[href], [data-href]",
);
@@ -41,10 +38,9 @@ export function checkClickForBookOrPageJump(
event.stopPropagation();
const href: string =
- (linkElement.attributes["href"] &&
- linkElement.attributes["href"].nodeValue) ||
- (linkElement.attributes["data-href"] &&
- linkElement.attributes["data-href"].nodeValue);
+ (linkElement.getAttribute("href") ||
+ linkElement.getAttribute("data-href")) ??
+ "";
if (href.startsWith("http://") || href.startsWith("https://")) {
// This is a generic external link. We open it in a new window or tab.
@@ -66,7 +62,7 @@ export function checkClickForBookOrPageJump(
: urlFromBookId(previousLocation.bookId!),
pageId: previousLocation.pageId,
};
- }
+ } else return undefined;
} else if (href.startsWith("/book/")) {
const target = parseTargetBookUrl(href);
targetBookId = target.bookId;
@@ -93,16 +89,21 @@ export function checkClickForBookOrPageJump(
return { pageId: targetPageId };
}
- return {}; // nothing to do as far as navigation goes
+ return undefined; // nothing to do as far as navigation goes
}
function pushLocation(bookId: string, pageId: string, comment: string) {
jumpHistory.push({ bookId, pageId });
- console.log(
- comment + " Current History is: ",
- JSON.stringify(jumpHistory, null, 2),
- );
+ // console.log(
+ // comment + " Current History is: ",
+ // JSON.stringify(jumpHistory, null, 2)
+ // );
}
+
+function urlFromBookId(bookId: string) {
+ return `/book/${bookId}/index.htm`;
+}
+
function parseTargetBookUrl(url: string) {
// the format is "/book/BOOKID#PAGEID" where the page id is optional
const bloomUrl = new URL(url, window.location.origin);
diff --git a/src/stories/BloomPlayerIframe.tsx b/src/stories/BloomPlayerIframe.tsx
index c85c487..5342d0f 100644
--- a/src/stories/BloomPlayerIframe.tsx
+++ b/src/stories/BloomPlayerIframe.tsx
@@ -6,7 +6,7 @@ export function BloomPlayerIframe({ bookUrl, bookPageIndex, showBackButton }) {
if (!useBuildIsReady()) {
return (
- Waiting for Bloom Player to build. See "yarn buildForStorybook"
+ Waiting for Bloom Player to build. See "yarn watchForStorybook"
);
}
diff --git a/src/stories/multiBook.stories.tsx b/src/stories/multiBook.stories.tsx
index d3135aa..17c44a0 100644
--- a/src/stories/multiBook.stories.tsx
+++ b/src/stories/multiBook.stories.tsx
@@ -3,7 +3,7 @@ import type { Meta, StoryObj } from "@storybook/react";
import { BloomPlayerIframe } from "./BloomPlayerIframe";
/* This uses an iframe, so normal dev server compilation is not effective.
-Therefore, when developing with this, use `yarn buildForStorybook` to update non-storybook code.
+Therefore, when developing with this, use `yarn watchForStorybook` to update non-storybook code.
The point of this story is really just to host a book that has links to a second book. What makes
that possible is the proxy defined in .storybook/main.ts, not here.
diff --git a/src/stories/navigation.stories.tsx b/src/stories/navigation.stories.tsx
index 841ba6c..ca5fd1c 100644
--- a/src/stories/navigation.stories.tsx
+++ b/src/stories/navigation.stories.tsx
@@ -3,7 +3,7 @@ import { BloomPlayerIframe } from "./BloomPlayerIframe";
import { BloomPlayerTester } from "./BloomPlayerTester";
/* This uses an iframe, so normal dev server compilation is not effective.
-Therefore, when developing with this, use `yarn buildForStorybook` to update non-storybook code.
+Therefore, when developing with this, use `yarn watchForStorybook` to update non-storybook code.
The point of this story is really just to host a book that has links to a second book. What makes
that possible is the proxy defined in .storybook/main.ts, not here.