Enhance EPUB reader navigation by adding tap zones for easier page control (#2092)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
+105
-105
@@ -19,101 +19,101 @@
|
|||||||
<div class="progress-info">
|
<div class="progress-info">
|
||||||
<span class="progress-percentage"><span class="progress-label">Progress: </span>{{ progressPercentage }}%</span>
|
<span class="progress-percentage"><span class="progress-label">Progress: </span>{{ progressPercentage }}%</span>
|
||||||
</div>
|
</div>
|
||||||
<p-drawer [(visible)]="isDrawerVisible" [modal]="false" [position]="'left'" [style]="{ width: '320px' }" (click)="$event.stopPropagation()">
|
<p-drawer [(visible)]="isDrawerVisible" [modal]="false" [position]="'left'" [style]="{ width: '320px' }" (click)="$event.stopPropagation()">
|
||||||
<ng-template pTemplate="header">
|
<ng-template pTemplate="header">
|
||||||
<div class="drawer-header">
|
<div class="drawer-header">
|
||||||
<span class="drawer-title">Table of Contents</span>
|
<span class="drawer-title">Table of Contents</span>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<p-tabs value="0">
|
<p-tabs value="0">
|
||||||
<p-tablist>
|
<p-tablist>
|
||||||
<p-tab value="0">
|
<p-tab value="0">
|
||||||
<div class="tab-header">
|
<div class="tab-header">
|
||||||
<i class="pi pi-book"></i>
|
<i class="pi pi-book"></i>
|
||||||
<span>Chapters</span>
|
<span>Chapters</span>
|
||||||
</div>
|
|
||||||
</p-tab>
|
|
||||||
<p-tab value="1">
|
|
||||||
<div class="tab-header">
|
|
||||||
<i class="pi pi-bookmark"></i>
|
|
||||||
<span>Bookmarks</span>
|
|
||||||
</div>
|
|
||||||
</p-tab>
|
|
||||||
</p-tablist>
|
|
||||||
<p-tabpanels>
|
|
||||||
<p-tabpanel value="0">
|
|
||||||
<div class="tab-content">
|
|
||||||
<ul class="chapter-list">
|
|
||||||
@for (chapter of chapters; track chapter) {
|
|
||||||
<li (click)="navigateToChapter(chapter); $event.stopPropagation()"
|
|
||||||
class="chapter-item"
|
|
||||||
[class.current-chapter]="chapter.href === currentChapterHref"
|
|
||||||
[style.padding-left.rem]="chapter.level * 1.5 + 0.75">
|
|
||||||
<i class="pi pi-chevron-right chapter-icon"></i>
|
|
||||||
<span class="chapter-label">{{ chapter.label }}</span>
|
|
||||||
</li>
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</p-tabpanel>
|
|
||||||
<p-tabpanel value="1">
|
|
||||||
<div class="tab-content">
|
|
||||||
<div class="p-2 mb-2">
|
|
||||||
<p-iconfield class="w-full">
|
|
||||||
<p-inputicon class="pi pi-search"/>
|
|
||||||
<input
|
|
||||||
pInputText
|
|
||||||
type="text"
|
|
||||||
[(ngModel)]="filterText"
|
|
||||||
placeholder="Search bookmarks..."
|
|
||||||
class="w-full p-inputtext-sm"
|
|
||||||
(click)="$event.stopPropagation()">
|
|
||||||
</p-iconfield>
|
|
||||||
</div>
|
|
||||||
@if (filteredBookmarks.length === 0) {
|
|
||||||
<div class="empty-state">
|
|
||||||
<i class="pi pi-bookmark"></i>
|
|
||||||
<p>No bookmarks found</p>
|
|
||||||
<span>{{ filterText ? 'Try a different search term' : 'Tap the bookmark icon to save your place' }}</span>
|
|
||||||
</div>
|
|
||||||
} @else {
|
|
||||||
<ul class="bookmark-list">
|
|
||||||
@for (bookmark of filteredBookmarks; track bookmark.id) {
|
|
||||||
<li class="bookmark-item" (click)="navigateToBookmark(bookmark); $event.stopPropagation()">
|
|
||||||
<i class="pi pi-bookmark-fill bookmark-icon" [style.color]="bookmark.color || 'var(--primary-color)'"></i>
|
|
||||||
<span class="bookmark-label">{{ bookmark.title }}</span>
|
|
||||||
<div class="bookmark-actions">
|
|
||||||
<button
|
|
||||||
class="bookmark-action-btn"
|
|
||||||
(click)="openViewDialog(bookmark); $event.stopPropagation()"
|
|
||||||
pTooltip="View Details"
|
|
||||||
tooltipPosition="bottom">
|
|
||||||
<i class="pi pi-info-circle"></i>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
class="bookmark-action-btn"
|
|
||||||
(click)="openEditBookmarkDialog(bookmark); $event.stopPropagation()"
|
|
||||||
pTooltip="Edit"
|
|
||||||
tooltipPosition="bottom">
|
|
||||||
<i class="pi pi-pencil"></i>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
class="bookmark-action-btn delete"
|
|
||||||
(click)="deleteBookmark(bookmark.id); $event.stopPropagation()"
|
|
||||||
pTooltip="Delete"
|
|
||||||
tooltipPosition="bottom">
|
|
||||||
<i class="pi pi-trash"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</p-tab>
|
||||||
}
|
<p-tab value="1">
|
||||||
</ul>
|
<div class="tab-header">
|
||||||
}
|
<i class="pi pi-bookmark"></i>
|
||||||
</div>
|
<span>Bookmarks</span>
|
||||||
</p-tabpanel>
|
</div>
|
||||||
</p-tabpanels>
|
</p-tab>
|
||||||
</p-tabs>
|
</p-tablist>
|
||||||
</p-drawer>
|
<p-tabpanels>
|
||||||
|
<p-tabpanel value="0">
|
||||||
|
<div class="tab-content">
|
||||||
|
<ul class="chapter-list">
|
||||||
|
@for (chapter of chapters; track chapter) {
|
||||||
|
<li (click)="navigateToChapter(chapter); $event.stopPropagation()"
|
||||||
|
class="chapter-item"
|
||||||
|
[class.current-chapter]="chapter.href === currentChapterHref"
|
||||||
|
[style.padding-left.rem]="chapter.level * 1.5 + 0.75">
|
||||||
|
<i class="pi pi-chevron-right chapter-icon"></i>
|
||||||
|
<span class="chapter-label">{{ chapter.label }}</span>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</p-tabpanel>
|
||||||
|
<p-tabpanel value="1">
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="p-2 mb-2">
|
||||||
|
<p-iconfield class="w-full">
|
||||||
|
<p-inputicon class="pi pi-search"/>
|
||||||
|
<input
|
||||||
|
pInputText
|
||||||
|
type="text"
|
||||||
|
[(ngModel)]="filterText"
|
||||||
|
placeholder="Search bookmarks..."
|
||||||
|
class="w-full p-inputtext-sm"
|
||||||
|
(click)="$event.stopPropagation()">
|
||||||
|
</p-iconfield>
|
||||||
|
</div>
|
||||||
|
@if (filteredBookmarks.length === 0) {
|
||||||
|
<div class="empty-state">
|
||||||
|
<i class="pi pi-bookmark"></i>
|
||||||
|
<p>No bookmarks found</p>
|
||||||
|
<span>{{ filterText ? 'Try a different search term' : 'Tap the bookmark icon to save your place' }}</span>
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<ul class="bookmark-list">
|
||||||
|
@for (bookmark of filteredBookmarks; track bookmark.id) {
|
||||||
|
<li class="bookmark-item" (click)="navigateToBookmark(bookmark); $event.stopPropagation()">
|
||||||
|
<i class="pi pi-bookmark-fill bookmark-icon" [style.color]="bookmark.color || 'var(--primary-color)'"></i>
|
||||||
|
<span class="bookmark-label">{{ bookmark.title }}</span>
|
||||||
|
<div class="bookmark-actions">
|
||||||
|
<button
|
||||||
|
class="bookmark-action-btn"
|
||||||
|
(click)="openViewDialog(bookmark); $event.stopPropagation()"
|
||||||
|
pTooltip="View Details"
|
||||||
|
tooltipPosition="bottom">
|
||||||
|
<i class="pi pi-info-circle"></i>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="bookmark-action-btn"
|
||||||
|
(click)="openEditBookmarkDialog(bookmark); $event.stopPropagation()"
|
||||||
|
pTooltip="Edit"
|
||||||
|
tooltipPosition="bottom">
|
||||||
|
<i class="pi pi-pencil"></i>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="bookmark-action-btn delete"
|
||||||
|
(click)="deleteBookmark(bookmark.id); $event.stopPropagation()"
|
||||||
|
pTooltip="Delete"
|
||||||
|
tooltipPosition="bottom">
|
||||||
|
<i class="pi pi-trash"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</p-tabpanel>
|
||||||
|
</p-tabpanels>
|
||||||
|
</p-tabs>
|
||||||
|
</p-drawer>
|
||||||
</div>
|
</div>
|
||||||
<div class="header-center">
|
<div class="header-center">
|
||||||
<p class="text font-medium">{{ currentChapter }}</p>
|
<p class="text font-medium">{{ currentChapter }}</p>
|
||||||
@@ -305,14 +305,14 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<app-bookmark-edit-dialog
|
<app-bookmark-edit-dialog
|
||||||
[(visible)]="showEditBookmarkDialog"
|
[(visible)]="showEditBookmarkDialog"
|
||||||
[bookmark]="editingBookmark"
|
[bookmark]="editingBookmark"
|
||||||
[isSaving]="isEditingBookmark"
|
[isSaving]="isEditingBookmark"
|
||||||
(save)="onBookmarkSave($event)"
|
(save)="onBookmarkSave($event)"
|
||||||
(cancelEdit)="onBookmarkCancel()">
|
(cancelEdit)="onBookmarkCancel()">
|
||||||
</app-bookmark-edit-dialog>
|
</app-bookmark-edit-dialog>
|
||||||
<app-bookmark-view-dialog
|
<app-bookmark-view-dialog
|
||||||
[(visible)]="viewDialogVisible"
|
[(visible)]="viewDialogVisible"
|
||||||
[bookmark]="selectedBookmark">
|
[bookmark]="selectedBookmark">
|
||||||
</app-bookmark-view-dialog>
|
</app-bookmark-view-dialog>
|
||||||
|
|||||||
+226
-81
@@ -65,6 +65,9 @@ export class EpubReaderComponent implements OnInit, OnDestroy {
|
|||||||
private hideHeaderTimeout?: number;
|
private hideHeaderTimeout?: number;
|
||||||
private isMouseInTopRegion = false;
|
private isMouseInTopRegion = false;
|
||||||
private headerShownByMobileTouch = false;
|
private headerShownByMobileTouch = false;
|
||||||
|
private currentIframe: HTMLIFrameElement | null = null;
|
||||||
|
private iframeTouchHandler: ((event: TouchEvent) => void) | null = null;
|
||||||
|
private iframeClickHandler: ((event: MouseEvent) => void) | null = null;
|
||||||
|
|
||||||
editingBookmark: BookMark | null = null;
|
editingBookmark: BookMark | null = null;
|
||||||
showEditBookmarkDialog = false;
|
showEditBookmarkDialog = false;
|
||||||
@@ -388,65 +391,183 @@ export class EpubReaderComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setupTouchListener(): void {
|
private setupTouchListener(): void {
|
||||||
if (!this.isMobileDevice() || !this.rendition) return;
|
if (!this.isMobileDevice()) return;
|
||||||
|
|
||||||
|
const container = this.epubContainer.nativeElement;
|
||||||
|
|
||||||
|
container.addEventListener('touchend', (event: TouchEvent) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
this.ngZone.run(() => {
|
||||||
|
this.handleTouchEnd(event);
|
||||||
|
});
|
||||||
|
}, { passive: false });
|
||||||
|
|
||||||
|
container.addEventListener('click', (event: MouseEvent) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
this.ngZone.run(() => {
|
||||||
|
this.handleClickAsTap(event);
|
||||||
|
});
|
||||||
|
}, { capture: true });
|
||||||
|
|
||||||
this.rendition.on('rendered', () => {
|
this.rendition.on('rendered', () => {
|
||||||
const iframe = this.epubContainer.nativeElement.querySelector('iframe');
|
const iframe = this.epubContainer.nativeElement.querySelector('iframe');
|
||||||
if (iframe && iframe.contentDocument) {
|
|
||||||
iframe.contentDocument.addEventListener('touchstart', () => {
|
if (iframe && iframe !== this.currentIframe) {
|
||||||
this.ngZone.run(() => {
|
if (this.currentIframe && this.currentIframe.contentDocument) {
|
||||||
this.onBookTouch();
|
if (this.iframeTouchHandler) {
|
||||||
});
|
this.currentIframe.contentDocument.removeEventListener('touchend', this.iframeTouchHandler, true);
|
||||||
});
|
}
|
||||||
|
if (this.iframeClickHandler) {
|
||||||
|
this.currentIframe.contentDocument.removeEventListener('click', this.iframeClickHandler, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentIframe = iframe;
|
||||||
|
|
||||||
|
if (iframe.contentDocument) {
|
||||||
|
this.iframeTouchHandler = (event: TouchEvent) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
this.ngZone.run(() => {
|
||||||
|
this.handleTouchEnd(event);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.iframeClickHandler = (event: MouseEvent) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
this.ngZone.run(() => {
|
||||||
|
this.handleClickAsTap(event);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
iframe.contentDocument.addEventListener('touchend', this.iframeTouchHandler, { passive: false, capture: true });
|
||||||
|
iframe.contentDocument.addEventListener('click', this.iframeClickHandler, { capture: true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public isMobileDevice(): boolean {
|
public handleTouchEnd(event: TouchEvent): void {
|
||||||
return window.innerWidth <= 768;
|
if (!this.isMobileDevice()) return;
|
||||||
}
|
|
||||||
|
|
||||||
prevPage(): void {
|
const touch = event.changedTouches[0];
|
||||||
if (this.rendition) {
|
let touchX = touch.clientX;
|
||||||
this.rendition.prev().then(() => {
|
let touchY = touch.clientY;
|
||||||
const location = this.rendition.currentLocation();
|
|
||||||
this.readingSessionService.updateProgress(
|
if (event.target && (event.target as HTMLElement).ownerDocument !== document) {
|
||||||
location?.start?.cfi,
|
const iframe = this.currentIframe;
|
||||||
this.progressPercentage
|
if (iframe) {
|
||||||
);
|
const iframeRect = iframe.getBoundingClientRect();
|
||||||
});
|
touchX = touch.clientX + iframeRect.left;
|
||||||
|
touchY = touch.clientY + iframeRect.top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const screenWidth = window.innerWidth;
|
||||||
|
const screenHeight = window.innerHeight;
|
||||||
|
|
||||||
|
const isTopTouch = touchY < screenHeight * 0.2;
|
||||||
|
const isInTapZoneVertically = touchY >= screenHeight * 0.2;
|
||||||
|
|
||||||
|
if (isTopTouch) {
|
||||||
|
if (!this.showHeader) {
|
||||||
|
this.showHeader = true;
|
||||||
|
this.headerShownByMobileTouch = true;
|
||||||
|
this.clearHeaderTimeout();
|
||||||
|
this.startHeaderAutoHide();
|
||||||
|
} else if (this.headerShownByMobileTouch) {
|
||||||
|
this.showHeader = false;
|
||||||
|
this.headerShownByMobileTouch = false;
|
||||||
|
this.clearHeaderTimeout();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isInTapZoneVertically) {
|
||||||
|
const leftZoneEnd = screenWidth / 3;
|
||||||
|
const rightZoneStart = screenWidth * (2 / 3);
|
||||||
|
|
||||||
|
if (touchX < leftZoneEnd) {
|
||||||
|
this.prevPage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (touchX > rightZoneStart) {
|
||||||
|
this.nextPage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.showControlsTemporarily();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nextPage(): void {
|
private handleClickAsTap(event: MouseEvent): void {
|
||||||
if (this.rendition) {
|
if (!this.isMobileDevice()) return;
|
||||||
this.rendition.next().then(() => {
|
|
||||||
const location = this.rendition.currentLocation();
|
let clickX = event.clientX;
|
||||||
this.readingSessionService.updateProgress(
|
let clickY = event.clientY;
|
||||||
location?.start?.cfi,
|
|
||||||
this.progressPercentage
|
if (event.target && (event.target as HTMLElement).ownerDocument !== document) {
|
||||||
);
|
const iframe = this.currentIframe;
|
||||||
});
|
if (iframe) {
|
||||||
|
const iframeRect = iframe.getBoundingClientRect();
|
||||||
|
clickX = event.clientX + iframeRect.left;
|
||||||
|
clickY = event.clientY + iframeRect.top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const screenWidth = window.innerWidth;
|
||||||
|
const screenHeight = window.innerHeight;
|
||||||
|
|
||||||
|
const isTopClick = clickY < screenHeight * 0.2;
|
||||||
|
const isInTapZoneVertically = clickY >= screenHeight * 0.2;
|
||||||
|
|
||||||
|
if (isTopClick) {
|
||||||
|
if (!this.showHeader) {
|
||||||
|
this.showHeader = true;
|
||||||
|
this.headerShownByMobileTouch = true;
|
||||||
|
this.clearHeaderTimeout();
|
||||||
|
this.startHeaderAutoHide();
|
||||||
|
} else if (this.headerShownByMobileTouch) {
|
||||||
|
this.showHeader = false;
|
||||||
|
this.headerShownByMobileTouch = false;
|
||||||
|
this.clearHeaderTimeout();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isInTapZoneVertically) {
|
||||||
|
const leftZoneEnd = screenWidth / 3;
|
||||||
|
const rightZoneStart = screenWidth * (2 / 3);
|
||||||
|
|
||||||
|
if (clickX < leftZoneEnd) {
|
||||||
|
this.prevPage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clickX > rightZoneStart) {
|
||||||
|
this.nextPage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.showControlsTemporarily();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
navigateToChapter(chapter: { label: string; href: string; level: number }): void {
|
closeReader(): void {
|
||||||
if (this.book && chapter.href) {
|
if (this.readingSessionService.isSessionActive()) {
|
||||||
this.book.rendition.display(chapter.href).then(() => {
|
this.readingSessionService.endSession(
|
||||||
const location = this.rendition.currentLocation();
|
this.currentCfi || undefined,
|
||||||
this.readingSessionService.updateProgress(
|
this.progressPercentage
|
||||||
location?.start?.cfi,
|
);
|
||||||
this.progressPercentage
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
this.location.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleDrawer(): void {
|
toggleDrawer(): void {
|
||||||
this.isDrawerVisible = !this.isDrawerVisible;
|
this.isDrawerVisible = !this.isDrawerVisible;
|
||||||
if (this.isDrawerVisible) {
|
if (this.isDrawerVisible) {
|
||||||
this.showHeader = true;
|
|
||||||
this.headerShownByMobileTouch = false;
|
|
||||||
this.clearHeaderTimeout();
|
this.clearHeaderTimeout();
|
||||||
} else {
|
} else {
|
||||||
this.startHeaderAutoHide();
|
this.startHeaderAutoHide();
|
||||||
@@ -456,14 +577,40 @@ export class EpubReaderComponent implements OnInit, OnDestroy {
|
|||||||
toggleSettingsDrawer(): void {
|
toggleSettingsDrawer(): void {
|
||||||
this.isSettingsDrawerVisible = !this.isSettingsDrawerVisible;
|
this.isSettingsDrawerVisible = !this.isSettingsDrawerVisible;
|
||||||
if (this.isSettingsDrawerVisible) {
|
if (this.isSettingsDrawerVisible) {
|
||||||
this.showHeader = true;
|
|
||||||
this.headerShownByMobileTouch = false;
|
|
||||||
this.clearHeaderTimeout();
|
this.clearHeaderTimeout();
|
||||||
} else {
|
} else {
|
||||||
this.startHeaderAutoHide();
|
this.startHeaderAutoHide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
navigateToChapter(chapter: { label: string; href: string; level: number }): void {
|
||||||
|
if (this.rendition) {
|
||||||
|
this.rendition.display(chapter.href).then(() => {
|
||||||
|
const location = this.rendition.currentLocation();
|
||||||
|
this.readingSessionService.updateProgress(
|
||||||
|
location?.start?.cfi,
|
||||||
|
this.progressPercentage
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prevPage(): void {
|
||||||
|
if (this.rendition) {
|
||||||
|
this.rendition.prev();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nextPage(): void {
|
||||||
|
if (this.rendition) {
|
||||||
|
this.rendition.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isMobileDevice(): boolean {
|
||||||
|
return window.innerWidth <= 768;
|
||||||
|
}
|
||||||
|
|
||||||
private trackProgress(): void {
|
private trackProgress(): void {
|
||||||
if (!this.book || !this.rendition) return;
|
if (!this.book || !this.rendition) return;
|
||||||
this.rendition.on('relocated', (location: any) => {
|
this.rendition.on('relocated', (location: any) => {
|
||||||
@@ -528,6 +675,15 @@ export class EpubReaderComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.routeSubscription?.unsubscribe();
|
this.routeSubscription?.unsubscribe();
|
||||||
|
|
||||||
|
if (this.currentIframe && this.currentIframe.contentDocument) {
|
||||||
|
if (this.iframeTouchHandler) {
|
||||||
|
this.currentIframe.contentDocument.removeEventListener('touchend', this.iframeTouchHandler, true);
|
||||||
|
}
|
||||||
|
if (this.iframeClickHandler) {
|
||||||
|
this.currentIframe.contentDocument.removeEventListener('click', this.iframeClickHandler, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.rendition) {
|
if (this.rendition) {
|
||||||
this.rendition.off('keyup', this.keyListener);
|
this.rendition.off('keyup', this.keyListener);
|
||||||
}
|
}
|
||||||
@@ -550,23 +706,14 @@ export class EpubReaderComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onBookClick(event: MouseEvent): void {
|
onBookClick(event: MouseEvent): void {
|
||||||
|
|
||||||
|
const clickX = event.clientX;
|
||||||
const clickY = event.clientY;
|
const clickY = event.clientY;
|
||||||
|
const screenWidth = window.innerWidth;
|
||||||
const screenHeight = window.innerHeight;
|
const screenHeight = window.innerHeight;
|
||||||
|
|
||||||
if (this.isMobileDevice()) {
|
if (this.isMobileDevice()) {
|
||||||
const isTopClick = clickY < screenHeight * 0.2;
|
this.handleClickAsTap(event);
|
||||||
const isBottomClick = clickY > screenHeight * 0.2;
|
|
||||||
|
|
||||||
if (isTopClick && !this.showHeader) {
|
|
||||||
this.showHeader = true;
|
|
||||||
this.headerShownByMobileTouch = true;
|
|
||||||
this.clearHeaderTimeout();
|
|
||||||
this.startHeaderAutoHide();
|
|
||||||
} else if (isBottomClick && this.showHeader && this.headerShownByMobileTouch) {
|
|
||||||
this.showHeader = false;
|
|
||||||
this.headerShownByMobileTouch = false;
|
|
||||||
this.clearHeaderTimeout();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const isTopClick = clickY < screenHeight * 0.1;
|
const isTopClick = clickY < screenHeight * 0.1;
|
||||||
if (isTopClick) {
|
if (isTopClick) {
|
||||||
@@ -615,28 +762,36 @@ export class EpubReaderComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onBookTouch(): void {
|
onBookTouch(event?: TouchEvent): void {
|
||||||
if (this.isMobileDevice()) {
|
if (this.isMobileDevice()) {
|
||||||
this.showControls = true;
|
if (event) {
|
||||||
this.showHeader = true;
|
this.handleTouchEnd(event);
|
||||||
this.headerShownByMobileTouch = false;
|
} else {
|
||||||
this.clearHeaderTimeout();
|
this.showControlsTemporarily();
|
||||||
|
|
||||||
if (this.hideControlsTimeout) {
|
|
||||||
window.clearTimeout(this.hideControlsTimeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hideControlsTimeout = window.setTimeout(() => {
|
|
||||||
this.ngZone.run(() => {
|
|
||||||
this.showControls = false;
|
|
||||||
if (!this.isDrawerVisible && !this.isSettingsDrawerVisible) {
|
|
||||||
this.showHeader = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 2000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private showControlsTemporarily(): void {
|
||||||
|
this.showControls = true;
|
||||||
|
this.showHeader = true;
|
||||||
|
this.headerShownByMobileTouch = false;
|
||||||
|
this.clearHeaderTimeout();
|
||||||
|
|
||||||
|
if (this.hideControlsTimeout) {
|
||||||
|
window.clearTimeout(this.hideControlsTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.hideControlsTimeout = window.setTimeout(() => {
|
||||||
|
this.ngZone.run(() => {
|
||||||
|
this.showControls = false;
|
||||||
|
if (!this.isDrawerVisible && !this.isSettingsDrawerVisible) {
|
||||||
|
this.showHeader = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
startHeaderAutoHide(): void {
|
startHeaderAutoHide(): void {
|
||||||
this.clearHeaderTimeout();
|
this.clearHeaderTimeout();
|
||||||
|
|
||||||
@@ -834,14 +989,4 @@ export class EpubReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.showEditBookmarkDialog = false;
|
this.showEditBookmarkDialog = false;
|
||||||
this.editingBookmark = null;
|
this.editingBookmark = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeReader(): void {
|
|
||||||
if (this.readingSessionService.isSessionActive()) {
|
|
||||||
this.readingSessionService.endSession(
|
|
||||||
this.currentCfi || undefined,
|
|
||||||
this.progressPercentage
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.location.back();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user