Skip to content

Commit

Permalink
Merge pull request #480 from d-i-t-a/develop
Browse files Browse the repository at this point in the history
2.3.12
  • Loading branch information
aferditamuriqi authored Aug 12, 2023
2 parents 0ac10a0 + 7a26058 commit f498bd7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 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.3.11",
"version": "2.3.12",
"description": "A viewer application for EPUB files.",
"repository": "https://github.com/d-i-t-a/R2D2BC",
"license": "Apache-2.0",
Expand Down
36 changes: 30 additions & 6 deletions src/modules/highlight/TextHighlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ let NODE_TYPE = {
TEXT_NODE: 3,
};

export enum MenuPosition {
INLINE = "inline",
TOP = "top",
BOTTOM = "bottom",
}

export const _blacklistIdClassForCssSelectors = [
HighlightContainer.R2_ID_HIGHLIGHTS_CONTAINER,
HighlightContainer.R2_ID_PAGEBREAK_CONTAINER,
Expand All @@ -131,6 +137,7 @@ let lastMouseDownY = -1;

export interface TextHighlighterProperties {
selectionMenuItems?: Array<SelectionMenuItem>;
menuPosition?: MenuPosition;
}

export interface TextHighlighterConfig extends TextHighlighterProperties {
Expand Down Expand Up @@ -168,6 +175,9 @@ export class TextHighlighter {
) {
this.layerSettings = layerSettings;
this.properties = properties;
if (this.properties.menuPosition == undefined) {
this.properties.menuPosition = MenuPosition.INLINE;
}
this.api = api;
this.hasEventListener = hasEventListener;
this.options = this.defaults(options, {
Expand Down Expand Up @@ -1107,14 +1117,28 @@ export class TextHighlighter {
let toolbox = document.getElementById("highlight-toolbox");

if (toolbox) {
const paginated = this.navigator.view?.isPaginated();
if (paginated) {
toolbox.style.top =
rect.top + (this.navigator.attributes?.navHeight ?? 0) + "px";
if (this.properties?.menuPosition === MenuPosition.TOP) {
toolbox.style.left = "0px";
toolbox.style.transform = "revert";
toolbox.style.width = "100%";
toolbox.style.textAlign = "center";
} else if (this.properties?.menuPosition === MenuPosition.BOTTOM) {
toolbox.style.bottom = "0px";
toolbox.style.left = "0px";
toolbox.style.transform = "revert";
toolbox.style.width = "100%";
toolbox.style.textAlign = "center";
toolbox.style.position = "absolute";
} else {
toolbox.style.top = rect.top + "px";
const paginated = this.navigator.view?.isPaginated();
if (paginated) {
toolbox.style.top =
rect.top + (this.navigator.attributes?.navHeight ?? 0) + "px";
} else {
toolbox.style.top = rect.top + "px";
}
toolbox.style.left = (rect.right - rect.left) / 2 + rect.left + "px";
}
toolbox.style.left = (rect.right - rect.left) / 2 + rect.left + "px";
}
}

Expand Down
1 change: 1 addition & 0 deletions viewer/index_dita.html
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@
],
},
highlighter: {
menuPosition: "inline", // top, bottom, inline (inline is default)
selectionMenuItems: selectionMenuItems,
api: {
selectionMenuOpen: function() {
Expand Down

0 comments on commit f498bd7

Please sign in to comment.