Skip to content

Commit

Permalink
Merge pull request #790 from d-i-t-a/develop
Browse files Browse the repository at this point in the history
2.4.6
  • Loading branch information
aferditamuriqi authored Feb 20, 2024
2 parents 7dbe313 + 20d6eb4 commit 4752b89
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 234 deletions.
424 changes: 212 additions & 212 deletions package-lock.json

Large diffs are not rendered by default.

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.5",
"version": "2.4.6",
"description": "A viewer application for EPUB files.",
"repository": "https://github.com/d-i-t-a/R2D2BC",
"license": "Apache-2.0",
Expand Down
38 changes: 24 additions & 14 deletions src/modules/search/Popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,21 @@ export class Popup {
return;
}
let self = this;
win.onclick = function (ev) {
if (event.target !== ev.target) {
if (d2popover.parentElement) {
self.hidePopover();
if (win) {
win.onclick = null;
win.addEventListener(
"click",
function (ev) {
if (event.target !== ev.target) {
if (d2popover.parentElement) {
self.hidePopover();
ev.stopImmediatePropagation();
}
}
},
{
once: true,
capture: true,
}
};
);
}
} else if (src) {
let absolute = getAbsoluteHref(src);
Expand Down Expand Up @@ -207,16 +212,21 @@ export class Popup {
return;
}
let self = this;
win.onclick = function (ev) {
if (event.target !== ev.target) {
if (d2popover.parentElement) {
self.hidePopover();
if (win) {
win.onclick = null;
win.addEventListener(
"click",
function (ev) {
if (event.target !== ev.target) {
if (d2popover.parentElement) {
self.hidePopover();
ev.stopImmediatePropagation();
}
}
},
{
once: true,
capture: true,
}
};
);
}
}
}
Expand Down
26 changes: 23 additions & 3 deletions src/navigator/IFrameNavigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import {
ConsumptionModule,
ConsumptionModuleConfig,
} from "../modules/consumption/ConsumptionModule";
import KeyDownEvent = JQuery.KeyDownEvent;

export type GetContent = (href: string) => Promise<string>;
export type GetContentBytesLength = (
Expand All @@ -117,6 +118,8 @@ export interface NavigatorAPI {
resourceAtEnd: any;
resourceFitsScreen: any;
updateCurrentLocation: any;
keydownFallthrough: any;
clickThrough: any;
direction: any;
onError?: (e: Error) => void;
}
Expand Down Expand Up @@ -999,11 +1002,16 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
this.nextChapterBottomAnchorElement.style.display = "none";
if (this.previousChapterTopAnchorElement)
this.previousChapterTopAnchorElement.style.display = "none";
if (this.eventHandler) {
this.eventHandler.onClickThrough = this.handleClickThrough.bind(this);
}
if (this.keyboardEventHandler) {
this.keyboardEventHandler.onBackwardSwipe =
this.handlePreviousChapterClick.bind(this);
this.keyboardEventHandler.onForwardSwipe =
this.handleNextChapterClick.bind(this);
this.keyboardEventHandler.onKeydown =
this.handleKeydownFallthrough.bind(this);
}
if (this.touchEventHandler) {
this.touchEventHandler.onBackwardSwipe =
Expand Down Expand Up @@ -1048,6 +1056,8 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
this.handlePreviousPageClick.bind(this);
this.keyboardEventHandler.onForwardSwipe =
this.handleNextPageClick.bind(this);
this.keyboardEventHandler.onKeydown =
this.handleKeydownFallthrough.bind(this);
}
} else {
if (this.infoBottom) this.infoBottom.style.display = "none";
Expand Down Expand Up @@ -1168,6 +1178,8 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
this.handlePreviousPageClick.bind(this);
this.keyboardEventHandler.onForwardSwipe =
this.handleNextPageClick.bind(this);
this.keyboardEventHandler.onKeydown =
this.handleKeydownFallthrough.bind(this);
}
}
});
Expand Down Expand Up @@ -1696,8 +1708,8 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
e instanceof Error
? e
: typeof e === "string"
? new Error(e)
: new Error("An unknown error occurred in the IFrameNavigator.");
? new Error(e)
: new Error("An unknown error occurred in the IFrameNavigator.");
this.api.onError(trueError);
} else {
// otherwise just display the standard error UI
Expand Down Expand Up @@ -2483,7 +2495,10 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
}
}

private handleClickThrough(_event: MouseEvent | TouchEvent) {}
private handleClickThrough(event: MouseEvent | TouchEvent) {
if (this.api?.clickThrough) this.api?.clickThrough(event);
this.emit("click", event);
}

private handleInternalLink(event: MouseEvent | TouchEvent) {
const element = event.target;
Expand Down Expand Up @@ -2815,6 +2830,11 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
}
}

private handleKeydownFallthrough(event: KeyDownEvent | undefined): void {
if (this.api?.keydownFallthrough) this.api?.keydownFallthrough(event);
this.emit("keydown", event);
}

private hideView(): void {
if (this.view?.layout !== "fixed") {
if (this.view?.isScrollMode()) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/EventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class EventHandler {
// Most click handling is done in the touchend and mouseup event handlers,
// but if there's a click on an external link we need to cancel the click
// event to prevent it from opening in the iframe.
element.addEventListener("click", this.handleLinks.bind(this));
element.addEventListener("click", this.handleLinks.bind(this), true);
} else {
throw "cannot setup events for null";
}
Expand Down
9 changes: 6 additions & 3 deletions src/utils/KeyboardEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class KeyboardEventHandler {

public onBackwardSwipe: (event: UIEvent) => void = () => {};
public onForwardSwipe: (event: UIEvent) => void = () => {};
public onKeydown: (event: UIEvent) => void = () => {};

public setupEvents = (element: HTMLElement | Document | null): void => {
if (element) {
Expand Down Expand Up @@ -93,20 +94,22 @@ export default class KeyboardEventHandler {
switch (key) {
case "ArrowRight":
self.rtl ? self.onBackwardSwipe(event) : self.onForwardSwipe(event);
break;
return;
case "ArrowLeft":
self.rtl ? self.onForwardSwipe(event) : self.onBackwardSwipe(event);
break;
return;
}
switch (event.code) {
case "Space":
if (event.ctrlKey) {
self.onBackwardSwipe(event);
return;
} else {
self.onForwardSwipe(event);
return;
}
break;
}
self.onKeydown(event);
})
);
}
Expand Down
12 changes: 12 additions & 0 deletions viewer/index_dita.html
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,12 @@
);
});
},
keydownFallthrough: function(event) {
console.log("api.keydownFallthrough:" + event.key);
},
clickThrough: function(event) {
console.log("api.clickThrough");
},
onError: function(error) {
console.log(error);
},
Expand Down Expand Up @@ -1449,6 +1455,12 @@
instance.addEventListener("resource.ready", () => {
console.log("listener ready");
});
instance.addEventListener("keydown", (event) => {
console.log("keydown: " + event.key);
});
instance.addEventListener("click", (event) => {
console.log("click through: " + event.detail);
});

}).catch(error => {
console.error(error);
Expand Down

0 comments on commit 4752b89

Please sign in to comment.