From 34d2e72df2d4a16c88b21f790b72554dc7c51a17 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sat, 23 Jan 2021 19:09:26 +0100 Subject: [PATCH] JS - Fix mouse event names - fix issue #12895 --- src/display/annotation_layer.js | 26 ++++++++++++-------------- src/scripting_api/event.js | 2 +- src/shared/util.js | 8 ++++---- test/unit/annotation_spec.js | 6 +++--- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 2e8e5f5265946..65919d1914a03 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -370,8 +370,8 @@ class LinkAnnotationElement extends AnnotationElement { parameters.data.isTooltipOnly || (parameters.data.actions && (parameters.data.actions.Action || - parameters.data.actions.MouseUp || - parameters.data.actions.MouseDown)) + parameters.data.actions["Mouse Up"] || + parameters.data.actions["Mouse Down"])) ); super(parameters, { isRenderable, createQuadrilaterals: true }); } @@ -395,7 +395,9 @@ class LinkAnnotationElement extends AnnotationElement { this._bindLink(link, data.dest); } else if ( data.actions && - (data.actions.Action || data.actions.MouseUp || data.actions.MouseDown) && + (data.actions.Action || + data.actions["Mouse Up"] || + data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions ) { @@ -469,8 +471,8 @@ class LinkAnnotationElement extends AnnotationElement { link.href = this.linkService.getAnchorUrl(""); const map = new Map([ ["Action", "onclick"], - ["MouseUp", "onmouseup"], - ["MouseDown", "onmousedown"], + ["Mouse Up", "onmouseup"], + ["Mouse Down", "onmousedown"], ]); for (const name of Object.keys(data.actions)) { const jsName = map.get(name); @@ -575,11 +577,7 @@ class WidgetAnnotationElement extends AnnotationElement { _setEventListeners(element, names, getter) { for (const [baseName, eventName] of names) { - if ( - eventName === "Action" || - (this.data.actions && - this.data.actions[eventName.replace(" ", "")] !== undefined) - ) { + if (eventName === "Action" || this.data.actions?.[eventName]) { this._setEventListener(element, baseName, eventName, getter); } } @@ -803,7 +801,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], - ["mouseup", "MouseUp"], + ["mouseup", "Mouse Up"], ], event => event.target.value ); @@ -942,7 +940,7 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement { ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], - ["mouseup", "MouseUp"], + ["mouseup", "Mouse Up"], ], event => event.target.checked ); @@ -1031,7 +1029,7 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement { ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], - ["mouseup", "MouseUp"], + ["mouseup", "Mouse Up"], ], event => event.target.checked ); @@ -1165,7 +1163,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], - ["mouseup", "MouseUp"], + ["mouseup", "Mouse Up"], ], event => event.target.checked ); diff --git a/src/scripting_api/event.js b/src/scripting_api/event.js index 5e62bffa54639..2806a6a0c16b6 100644 --- a/src/scripting_api/event.js +++ b/src/scripting_api/event.js @@ -83,7 +83,7 @@ class EventDispatcher { return; } - const name = baseEvent.name.replace(" ", ""); + const name = baseEvent.name; const source = this._objects[id]; const event = (globalThis.event = new Event(baseEvent)); let savedChange; diff --git a/src/shared/util.js b/src/shared/util.js index 66f0e502e5da7..84fcb0bcee6b1 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -145,10 +145,10 @@ const AnnotationBorderStyleType = { }; const AnnotationActionEventType = { - E: "MouseEnter", - X: "MouseExit", - D: "MouseDown", - U: "MouseUp", + E: "Mouse Enter", + X: "Mouse Exit", + D: "Mouse Down", + U: "Mouse Up", Fo: "Focus", Bl: "Blur", PO: "PageOpen", diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 222a1a0e9f8e2..d647fbe4243c6 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -2238,15 +2238,15 @@ describe("annotation", function () { }) .then(object => { const actions = object.actions; - expect(actions.MouseEnter).toEqual(["hello()"]); - expect(actions.MouseExit).toEqual([ + expect(actions["Mouse Enter"]).toEqual(["hello()"]); + expect(actions["Mouse Exit"]).toEqual([ "world()", "olleh()", "foo()", "dlrow()", "oof()", ]); - expect(actions.MouseDown).toEqual(["bar()"]); + expect(actions["Mouse Down"]).toEqual(["bar()"]); done(); }, done.fail); });