From 8a147535dea2a74322e2bd02eed7dfbf36c2333f Mon Sep 17 00:00:00 2001 From: jalf Date: Tue, 29 Jan 2013 17:06:03 +0100 Subject: [PATCH] Clamp mouseclick coordinates to target element bounds --- include/util.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/util.js b/include/util.js index 6f6c52a6..dd1f252f 100644 --- a/include/util.js +++ b/include/util.js @@ -298,7 +298,9 @@ Util.getEventPosition = function (e, obj, scale) { if (typeof scale === "undefined") { scale = 1; } - return {'x': (docX - pos.x) / scale, 'y': (docY - pos.y) / scale}; + var x = Math.max(Math.min(docX - pos.x, obj.width-1), 0); + var y = Math.max(Math.min(docY - pos.y, obj.height-1), 0); + return {'x': x / scale, 'y': y / scale}; };