Skip to content
Open
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
10 changes: 10 additions & 0 deletions src/plugins/translate/plugin.translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export class TranslatePlugin extends BookReaderPlugin {
}
/** @type {HTMLElement} textLayerElement */
const textLayerElement = page.querySelector('.BRtextLayer');
if (!textLayerElement) {
console.warn("Translate unavailable: no text layer (preview mode?)");
return;
}
// Should use native DOM element.style method instead of $().css method, specific issue with rendering / style calculation in Chrome
$(pageTranslationLayer).css({
"width": textLayerElement.style.width,
Expand Down Expand Up @@ -307,6 +311,12 @@ export class TranslatePlugin extends BookReaderPlugin {
}

handleToggleTranslation = async () => {
const hasTextLayer = document.querySelector('.BRtextLayer');
if (!hasTextLayer) {
alert("Please borrow the book to use translation.");
return;
}

this.userToggleTranslate = !this.userToggleTranslate;
this.translationManager.active = this.userToggleTranslate;

Expand Down