Use one noContextMenu
function in both the src/- and web/-folders
Currently we duplicate this event handler function in multiple places, which seems unnecessary.
This commit is contained in:
parent
a09b7228fb
commit
1df31c0284
@ -789,6 +789,13 @@ function isValidFetchUrl(url, baseUrl) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler to suppress context menu.
|
||||
*/
|
||||
function noContextMenu(e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} src
|
||||
* @param {boolean} [removeScriptElement]
|
||||
@ -1020,6 +1027,7 @@ export {
|
||||
isPdfFile,
|
||||
isValidFetchUrl,
|
||||
loadScript,
|
||||
noContextMenu,
|
||||
PageViewport,
|
||||
PDFDateString,
|
||||
PixelsPerInch,
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
import { bindEvents, ColorManager } from "./tools.js";
|
||||
import { FeatureTest, shadow, unreachable } from "../../shared/util.js";
|
||||
import { noContextMenu } from "../display_utils.js";
|
||||
|
||||
/**
|
||||
* @typedef {Object} AnnotationEditorParameters
|
||||
@ -589,10 +590,6 @@ class AnnotationEditor {
|
||||
return [0, 0];
|
||||
}
|
||||
|
||||
static #noContextMenu(e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
#createResizers() {
|
||||
if (this.#resizersDiv) {
|
||||
return;
|
||||
@ -611,7 +608,7 @@ class AnnotationEditor {
|
||||
"pointerdown",
|
||||
this.#resizerPointerdown.bind(this, name)
|
||||
);
|
||||
div.addEventListener("contextmenu", AnnotationEditor.#noContextMenu);
|
||||
div.addEventListener("contextmenu", noContextMenu);
|
||||
}
|
||||
this.div.prepend(this.#resizersDiv);
|
||||
}
|
||||
@ -834,7 +831,7 @@ class AnnotationEditor {
|
||||
altText.textContent = msg;
|
||||
altText.setAttribute("aria-label", msg);
|
||||
altText.tabIndex = "0";
|
||||
altText.addEventListener("contextmenu", AnnotationEditor.#noContextMenu);
|
||||
altText.addEventListener("contextmenu", noContextMenu);
|
||||
altText.addEventListener("pointerdown", event => event.stopPropagation());
|
||||
altText.addEventListener(
|
||||
"click",
|
||||
|
@ -20,6 +20,7 @@ import {
|
||||
} from "../../shared/util.js";
|
||||
import { AnnotationEditor } from "./editor.js";
|
||||
import { InkAnnotationElement } from "../annotation_layer.js";
|
||||
import { noContextMenu } from "../display_utils.js";
|
||||
import { opacityToHex } from "./tools.js";
|
||||
|
||||
/**
|
||||
@ -30,8 +31,6 @@ class InkEditor extends AnnotationEditor {
|
||||
|
||||
#baseWidth = 0;
|
||||
|
||||
#boundCanvasContextMenu = this.canvasContextMenu.bind(this);
|
||||
|
||||
#boundCanvasPointermove = this.canvasPointermove.bind(this);
|
||||
|
||||
#boundCanvasPointerleave = this.canvasPointerleave.bind(this);
|
||||
@ -360,7 +359,7 @@ class InkEditor extends AnnotationEditor {
|
||||
* @param {number} y
|
||||
*/
|
||||
#startDrawing(x, y) {
|
||||
this.canvas.addEventListener("contextmenu", this.#boundCanvasContextMenu);
|
||||
this.canvas.addEventListener("contextmenu", noContextMenu);
|
||||
this.canvas.addEventListener("pointerleave", this.#boundCanvasPointerleave);
|
||||
this.canvas.addEventListener("pointermove", this.#boundCanvasPointermove);
|
||||
this.canvas.addEventListener("pointerup", this.#boundCanvasPointerup);
|
||||
@ -661,14 +660,6 @@ class InkEditor extends AnnotationEditor {
|
||||
this.#startDrawing(event.offsetX, event.offsetY);
|
||||
}
|
||||
|
||||
/**
|
||||
* oncontextmenu callback for the canvas we're drawing on.
|
||||
* @param {PointerEvent} event
|
||||
*/
|
||||
canvasContextMenu(event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* onpointermove callback for the canvas we're drawing on.
|
||||
* @param {PointerEvent} event
|
||||
@ -714,10 +705,7 @@ class InkEditor extends AnnotationEditor {
|
||||
// Slight delay to avoid the context menu to appear (it can happen on a long
|
||||
// tap with a pen).
|
||||
setTimeout(() => {
|
||||
this.canvas.removeEventListener(
|
||||
"contextmenu",
|
||||
this.#boundCanvasContextMenu
|
||||
);
|
||||
this.canvas.removeEventListener("contextmenu", noContextMenu);
|
||||
}, 10);
|
||||
|
||||
this.#stopDrawing(event.offsetX, event.offsetY);
|
||||
|
@ -61,6 +61,7 @@ import {
|
||||
isDataScheme,
|
||||
isPdfFile,
|
||||
loadScript,
|
||||
noContextMenu,
|
||||
PDFDateString,
|
||||
PixelsPerInch,
|
||||
RenderingCancelledException,
|
||||
@ -104,6 +105,7 @@ export {
|
||||
isPdfFile,
|
||||
loadScript,
|
||||
MissingPDFException,
|
||||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
OPS,
|
||||
PasswordResponses,
|
||||
|
@ -50,6 +50,7 @@ import {
|
||||
isDataScheme,
|
||||
isPdfFile,
|
||||
loadScript,
|
||||
noContextMenu,
|
||||
PDFDateString,
|
||||
PixelsPerInch,
|
||||
RenderingCancelledException,
|
||||
@ -100,6 +101,7 @@ describe("pdfjs_api", function () {
|
||||
isPdfFile,
|
||||
loadScript,
|
||||
MissingPDFException,
|
||||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
OPS,
|
||||
PasswordResponses,
|
||||
|
@ -19,10 +19,9 @@ import {
|
||||
DEFAULT_SCALE_VALUE,
|
||||
MAX_SCALE,
|
||||
MIN_SCALE,
|
||||
noContextMenuHandler,
|
||||
toggleCheckedBtn,
|
||||
} from "./ui_utils.js";
|
||||
import { AnnotationEditorType } from "pdfjs-lib";
|
||||
import { AnnotationEditorType, noContextMenu } from "pdfjs-lib";
|
||||
|
||||
const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
|
||||
|
||||
@ -201,7 +200,7 @@ class Toolbar {
|
||||
}
|
||||
});
|
||||
// Suppress context menus for some controls.
|
||||
scaleSelect.oncontextmenu = noContextMenuHandler;
|
||||
scaleSelect.oncontextmenu = noContextMenu;
|
||||
|
||||
this.eventBus._on("localized", () => {
|
||||
this.#wasLocalized = true;
|
||||
|
@ -604,13 +604,6 @@ function getVisibleElements({
|
||||
return { first, last, views: visible, ids };
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler to suppress context menu.
|
||||
*/
|
||||
function noContextMenuHandler(evt) {
|
||||
evt.preventDefault();
|
||||
}
|
||||
|
||||
function normalizeWheelEventDirection(evt) {
|
||||
let delta = Math.hypot(evt.deltaX, evt.deltaY);
|
||||
const angle = Math.atan2(evt.deltaY, evt.deltaX);
|
||||
@ -881,7 +874,6 @@ export {
|
||||
MAX_AUTO_SCALE,
|
||||
MAX_SCALE,
|
||||
MIN_SCALE,
|
||||
noContextMenuHandler,
|
||||
normalizeWheelEventDelta,
|
||||
normalizeWheelEventDirection,
|
||||
OutputScale,
|
||||
|
Loading…
Reference in New Issue
Block a user