From c05af1d38b32c02a2a09896b3fc9300634f37185 Mon Sep 17 00:00:00 2001 From: Mohit Bansal Date: Sun, 19 Feb 2023 15:49:43 +0530 Subject: [PATCH] add focus and blur event --- src/viewer.js | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/viewer.js b/src/viewer.js index f6b1f536..b65bc73e 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -307,7 +307,9 @@ $.Viewer = function( options ) { nonPrimaryPressHandler: $.delegate( this, onCanvasNonPrimaryPress ), nonPrimaryReleaseHandler: $.delegate( this, onCanvasNonPrimaryRelease ), scrollHandler: $.delegate( this, onCanvasScroll ), - pinchHandler: $.delegate( this, onCanvasPinch ) + pinchHandler: $.delegate( this, onCanvasPinch ), + focusHandler: $.delegate( this, onCanvasFocus ), + blurHandler: $.delegate( this, onCanvasBlur ), }); this.outerTracker = new $.MouseTracker({ @@ -3415,6 +3417,43 @@ function onCanvasPinch( event ) { } } +function onCanvasFocus( event ) { + + /** + * Raised when a pointer focus on the {@link OpenSeadragon.Viewer#canvas} element. + * + * @event canvas-focus + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. + * @property {OpenSeadragon.MouseTracker} tracker - A reference to the MouseTracker which originated this event. + * @property {Object} originalEvent - The original DOM event. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + this.raiseEvent( 'canvas-focus', { + tracker: event.eventSource, + originalEvent: event.originalEvent + }); +} + +function onCanvasBlur( event ) { + /** + * Raised when a pointer blur on the {@link OpenSeadragon.Viewer#canvas} element. + * + * @event canvas-blur + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. + * @property {OpenSeadragon.MouseTracker} tracker - A reference to the MouseTracker which originated this event. + * @property {Object} originalEvent - The original DOM event. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + this.raiseEvent( 'canvas-blur', { + tracker: event.eventSource, + originalEvent: event.originalEvent + }); +} + function onCanvasScroll( event ) { var canvasScrollEventArgs, gestureSettings,