Skip to content

Commit

Permalink
Merge pull request #815 from d-i-t-a/develop
Browse files Browse the repository at this point in the history
2.4.9
  • Loading branch information
aferditamuriqi authored Mar 5, 2024
2 parents a4f139a + b8c8b05 commit 3f9343b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 43 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@d-i-t-a/reader",
"version": "2.4.8",
"version": "2.4.9",
"description": "A viewer application for EPUB files.",
"repository": "https://github.com/d-i-t-a/R2D2BC",
"license": "Apache-2.0",
Expand Down
4 changes: 4 additions & 0 deletions src/modules/highlight/TextHighlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,24 +903,28 @@ export class TextHighlighter {

switch (mode) {
case "colors":
this.selectionMenuOpened();
if (toolboxColorsOptions) toolboxColorsOptions.style.display = "unset";
if (toolboxAddOptions) toolboxAddOptions.style.display = "none";
if (toolboxEditOptions) toolboxEditOptions.style.display = "none";
if (toolboxMarkOptions) toolboxMarkOptions.style.display = "none";
break;
case "edit":
this.selectionMenuOpened();
if (toolboxColorsOptions) toolboxColorsOptions.style.display = "none";
if (toolboxAddOptions) toolboxAddOptions.style.display = "none";
if (toolboxEditOptions) toolboxEditOptions.style.display = "unset";
if (toolboxMarkOptions) toolboxMarkOptions.style.display = "none";
break;
case "action":
this.selectionMenuOpened();
if (toolboxColorsOptions) toolboxColorsOptions.style.display = "none";
if (toolboxAddOptions) toolboxAddOptions.style.display = "none";
if (toolboxEditOptions) toolboxEditOptions.style.display = "none";
if (toolboxMarkOptions) toolboxMarkOptions.style.display = "unset";
break;
default:
this.selectionMenuOpened();
if (toolboxColorsOptions) toolboxColorsOptions.style.display = "none";
if (toolboxAddOptions) toolboxAddOptions.style.display = "unset";
if (toolboxEditOptions) toolboxEditOptions.style.display = "none";
Expand Down
101 changes: 61 additions & 40 deletions src/utils/EventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,58 +127,79 @@ export default class EventHandler {
return isEpubInternal;
};

clicks = 0;
clickTimer: any = 0;
dblClickTimeSpan = 300;

private handleLinks = async (
event: MouseEvent | TouchEvent
): Promise<void> => {
log.log("R2 Click Handler");
this.clicks++;
if (this.clicks === 1) {
this.clickTimer = setTimeout(async () => {
this.clicks = 0;

const link = this.checkForLink(event);
if (link) {
// Open external links in new tabs.
const isSameOrigin =
window.location.protocol === link.protocol &&
window.location.port === link.port &&
window.location.hostname === link.hostname;
const link = this.checkForLink(event);
if (link) {
// Open external links in new tabs.
const isSameOrigin =
window.location.protocol === link.protocol &&
window.location.port === link.port &&
window.location.hostname === link.hostname;

// If epub is hosted, rather than streamed, links to a resource inside the same epub should not be opened externally.
const isEpubInternal = this.isReadingOrderInternal(link);
// If epub is hosted, rather than streamed, links to a resource inside the same epub should not be opened externally.
const isEpubInternal = this.isReadingOrderInternal(link);

const isResourceInternal = this.isResourceInternal(link);
if (!isResourceInternal) {
await this.popup.hidePopover();
}
const isResourceInternal = this.isResourceInternal(link);
if (!isResourceInternal) {
await this.popup.hidePopover();
}

const isInternal = link.href.indexOf("#");
if (!isEpubInternal && !isResourceInternal) {
window.open(link.href, link.target ?? "_blank");
event.preventDefault();
event.stopPropagation();
} else {
(event.target as HTMLAnchorElement).href = link.href;
if ((isSameOrigin || isEpubInternal) && isInternal !== -1) {
const link = event.target as HTMLLIElement;
if (link) {
const attribute = link.getAttribute("epub:type") === "noteref";
if (attribute) {
await this.popup.handleFootnote(link, event);
} else if (isResourceInternal && !isEpubInternal) {
await this.popup.showPopover(link, event);
} else {
const isInternal = link.href.indexOf("#");
if (!isEpubInternal && !isResourceInternal) {
window.open(link.href, link.target ?? "_blank");
event.preventDefault();
event.stopPropagation();
} else {
(event.target as HTMLAnchorElement).href = link.href;
if ((isSameOrigin || isEpubInternal) && isInternal !== -1) {
const link = event.target as HTMLLIElement;
if (link) {
const attribute = link.getAttribute("epub:type") === "noteref";
if (attribute) {
await this.popup.handleFootnote(link, event);
} else if (isResourceInternal && !isEpubInternal) {
await this.popup.showPopover(link, event);
} else {
this.onInternalLink(event);
}
} else {
this.onInternalLink(event);
}
} else if ((isSameOrigin || isEpubInternal) && isInternal === -1) {
// TODO needs some more refactoring when handling other types of links or elements
// link.click();
this.onInternalLink(event);
}
} else {
this.onInternalLink(event);
}
} else if ((isSameOrigin || isEpubInternal) && isInternal === -1) {
// TODO needs some more refactoring when handling other types of links or elements
// link.click();
this.onInternalLink(event);
} else {
setTimeout(() => {
console.log("event.detail", event.detail);
if (
!this.navigator.highlighter?.isSelectionMenuOpen &&
event.detail === 1
) {
this.onClickThrough(event);
}
}, 100);
}
}
} else {
if (!this.navigator.highlighter?.isSelectionMenuOpen) {
this.onClickThrough(event);
}
}, this.dblClickTimeSpan);
}
if (this.clicks === 2) {
// it is the second click in double-click event
clearTimeout(this.clickTimer);
this.clicks = 0;
}
};
}

0 comments on commit 3f9343b

Please sign in to comment.