Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TAS-2267] 🚸 Allow clicking 1/3 of the epub view to navigate #1824

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/pages/reader/epub.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@

<div
:class="[
'phoneLg:hidden',
'absolute',
'inset-0',

Expand Down Expand Up @@ -291,6 +292,12 @@ export default {
this.initRendition();
document.addEventListener('keydown', this.keyListener, false);
},
beforeDestroy() {
if (this.cleanUpClickListener) {
this.cleanUpClickListener();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need to set this.cleanUpClickListener to undefined here

this.cleanUpClickListener = undefined;
}
},
methods: {
async initRendition() {
try {
Expand Down Expand Up @@ -324,6 +331,37 @@ export default {
this.dirPath = pathArr.join('/');

this.isRightToLeft = view?.settings?.direction === 'rtl';

if (this.cleanUpClickListener) {
this.cleanUpClickListener();
}
this.cleanUpClickListener = view.window.addEventListener(
'click',
event => {
// Ignore clicks on links
const hasClickedLink = event
.composedPath()
.some(eventTarget => eventTarget.tagName === 'A');
if (hasClickedLink) {
return;
}

// Ignore when selecting text
const selection = view.window.getSelection();
if (selection?.toString()?.length) {
return;
}

const width = this.rendition?.manager?.container.clientWidth || 0;
const range = width * (1 / 3);
const x = event.clientX % width; // Normalize x to be within the window
if (x < range) {
this.goLeft();
} else if (width - x < range) {
this.goRight();
}
}
);
});

this.rendition.on('relocated', location => {
Expand Down
Loading