Merge pull request #13801 from Snuffleupagus/AnnotationLayer-check-navigator

Access `navigator` safely in the `src/display/annotation_layer.js` file
This commit is contained in:
Tim van der Meij 2021-07-27 22:10:27 +02:00 committed by GitHub
commit e51cbe63bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,7 @@ import {
AnnotationBorderStyleType,
AnnotationType,
assert,
shadow,
stringToPDFString,
unreachable,
Util,
@ -359,6 +360,15 @@ class AnnotationElement {
render() {
unreachable("Abstract method `AnnotationElement.render` called");
}
static get platform() {
const platform = typeof navigator !== "undefined" ? navigator.platform : "";
return shadow(this, "platform", {
isWin: platform.includes("Win"),
isMac: platform.includes("Mac"),
});
}
}
class LinkAnnotationElement extends AnnotationElement {
@ -539,10 +549,8 @@ class WidgetAnnotationElement extends AnnotationElement {
}
_getKeyModifier(event) {
return (
(navigator.platform.includes("Win") && event.ctrlKey) ||
(navigator.platform.includes("Mac") && event.metaKey)
);
const { isWin, isMac } = AnnotationElement.platform;
return (isWin && event.ctrlKey) || (isMac && event.metaKey);
}
_setEventListener(element, baseName, eventName, valueGetter) {