From f2863a5d3a6447ba5076238694fab131b36cbcbf Mon Sep 17 00:00:00 2001 From: mankowitz Date: Sun, 2 Jan 2022 02:38:29 -0500 Subject: [PATCH] better click handler --- pdfannotate.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pdfannotate.js b/pdfannotate.js index 40f1dd8..dd29828 100644 --- a/pdfannotate.js +++ b/pdfannotate.js @@ -97,10 +97,26 @@ var PDFAnnotate = function (container_id, url, options = {}) { background, fabricObj.renderAll.bind(fabricObj) ); - $(fabricObj.upperCanvasEl).click(function (event) { - inst.active_canvas = index; - inst.fabricClickHandler(event, fabricObj); - }); + + $(fabricObj.upperCanvasEl).on('mousedown', function(e) { + $(this).data('p0', { + x: e.pageX, + y: e.pageY + }); + }).on('mouseup', function(e) { + var p0 = $(this).data('p0'), + p1 = { + x: e.pageX, + y: e.pageY + }, + d = Math.sqrt(Math.pow(p1.x - p0.x, 2) + Math.pow(p1.y - p0.y, 2)); + + if (d < 4) { + inst.active_canvas = index; + inst.fabricClickHandler(e, fabricObj); + } + }) + fabricObj.on('after:render', function () { inst.fabricObjectsData[index] = fabricObj.toJSON(); fabricObj.off('after:render');