diff --git a/src/lib/events.js b/src/lib/events.js index d7a3a592a..6d15933ff 100644 --- a/src/lib/events.js +++ b/src/lib/events.js @@ -3,6 +3,7 @@ export const VIEWER_EVENT = { default: 'viewerevent', // The default viewer event. download: 'download', // Begin downloading the file. error: 'error', // When an error occurs. + imageZoomClick: 'imagezoomclick', // When image is clicked directly to zoom/reset load: 'load', // Preview is finished loading. mediaEndAutoplay: 'mediaendautoplay', // Media playback has completed, with autoplay enabled. metric: 'viewermetric', // A viewer metric. diff --git a/src/lib/viewers/image/ImageBaseViewer.js b/src/lib/viewers/image/ImageBaseViewer.js index 5100f8aeb..84555b44c 100644 --- a/src/lib/viewers/image/ImageBaseViewer.js +++ b/src/lib/viewers/image/ImageBaseViewer.js @@ -373,10 +373,12 @@ class ImageBaseViewer extends BaseViewer { if (!this.isPannable && this.isZoomable) { // If the mouse up was not due to panning, and the image is zoomable, then zoom in. this.zoom('in'); + this.emitMetric(VIEWER_EVENT.imageZoomClick, 'in'); } else if (!this.didPan) { // If the mouse up was not due to ending of panning, then assume it was a regular // click mouse up. In that case reset the image size, mimicking single-click-unzoom. this.zoom('reset'); + this.emitMetric(VIEWER_EVENT.imageZoomClick, 'reset'); } } } diff --git a/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js b/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js index 07847bd01..4caa97477 100644 --- a/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js +++ b/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js @@ -313,6 +313,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => { describe('handleMouseUp()', () => { beforeEach(() => { + stubs.emitMetric = sandbox.stub(imageBase, 'emitMetric'); stubs.pan = sandbox.stub(imageBase, 'stopPanning'); stubs.zoom = sandbox.stub(imageBase, 'zoom'); imageBase.isPanning = false; @@ -335,6 +336,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => { event.metaKey = 'blah'; imageBase.handleMouseUp(event); expect(stubs.zoom).to.not.have.been.called; + expect(stubs.emitMetric).to.not.have.been.called; }); it('should zoom in if zoomable but not pannable', () => { @@ -349,6 +351,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => { imageBase.isZoomable = true; imageBase.handleMouseUp(event); expect(stubs.zoom).to.have.been.calledWith('in'); + expect(stubs.emitMetric).to.be.calledWith('imagezoomclick', 'in'); }); it('should reset zoom if mouseup was not due to end of panning', () => { @@ -364,6 +367,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => { imageBase.didPan = false; imageBase.handleMouseUp(event); expect(stubs.zoom).to.have.been.calledWith('reset'); + expect(stubs.emitMetric).to.be.calledWith('imagezoomclick', 'reset'); }); it('should not zoom if mouse up was due to end of panning', () => {