Skip to content

Commit

Permalink
Merge pull request #337 from StephenMcConnel/BL-13882-LinksToOtherBooks
Browse files Browse the repository at this point in the history
feat: Send bloomnav links to the host window to handle (BL-13882) (#337)
  • Loading branch information
andrew-polk authored Nov 14, 2024
2 parents 7486250 + f635e88 commit 09f3509
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/bloom-player-core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ export class BloomPlayerCore extends React.Component<IProps, IState> {
}

handleDocumentLevelClick(e: any) {
const hrefValue = (e.target as HTMLElement)?.attributes["href"]
?.value as string;
if (hrefValue) {
if (hrefValue.startsWith("bloomnav://")) {
// This is a link to a page in another book. We need to send a message to the host.
this.handleBloomNavLink(hrefValue, e);
}
return;
}
const targetElement = (e.target as HTMLElement).closest(
"[data-href]"
) as HTMLElement;
Expand All @@ -397,9 +406,7 @@ export class BloomPlayerCore extends React.Component<IProps, IState> {
e.stopPropagation();
} else if (href.startsWith("bloomnav://")) {
// This is a link to a page in another book. We need to send a message to the host.
sendMessageToHost({ messageType: "bloomnav", href: href });
e.preventDefault();
e.stopPropagation();
this.handleBloomNavLink(href, e);
} else if (
href.startsWith("http://") ||
href.startsWith("https://")
Expand All @@ -414,6 +421,19 @@ export class BloomPlayerCore extends React.Component<IProps, IState> {
}
}

private handleBloomNavLink(href: string, e: any) {
const page = (e.target as HTMLElement).closest(".bloom-page");
sendMessageToHost({
messageType: "bloomnav",
href: href,
// used for backreference to the page that initiated the navigation
sourceUrl: this.sourceUrl,
sourcePageNumber: page?.getAttribute("data-page-number")
});
e.preventDefault();
e.stopPropagation();
}

private handleWindowFocus() {
const readDuration = localStorage.getItem(kLocalStorageDurationKey);
const savedBookUrl = localStorage.getItem(kLocalStorageBookUrlKey);
Expand Down

0 comments on commit 09f3509

Please sign in to comment.