From e84189d9d899a842db67cb15a3c93208b9269c6e Mon Sep 17 00:00:00 2001 From: raphael Date: Fri, 22 May 2020 18:04:17 +0200 Subject: [PATCH] fix rotation handler and drag offset --- src/js/whiteboard.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/js/whiteboard.js b/src/js/whiteboard.js index 318a1c9..8141b17 100644 --- a/src/js/whiteboard.js +++ b/src/js/whiteboard.js @@ -764,6 +764,7 @@ const whiteboard = { '' + "" + '' + + '
' + "" ); imgDiv.find(".xCanvasBtn").click(function () { @@ -799,7 +800,21 @@ const whiteboard = { _this.setTool(oldTool); }); _this.mouseOverlay.append(imgDiv); - imgDiv.draggable(); + var recoupLeft, recoupTop; + imgDiv.draggable({ + start: function (event, ui) { + var left = parseInt($(this).css("left"), 10); + left = isNaN(left) ? 0 : left; + var top = parseInt($(this).css("top"), 10); + top = isNaN(top) ? 0 : top; + recoupLeft = left - ui.position.left; + recoupTop = top - ui.position.top; + }, + drag: function (event, ui) { + ui.position.left += recoupLeft; + ui.position.top += recoupTop; + }, + }); imgDiv.resizable(); var params = { // Callback fired on rotation start. @@ -808,17 +823,9 @@ const whiteboard = { rotate: function (event, ui) {}, // Callback fired on rotation end. stop: function (event, ui) {}, - // Set the rotation center - rotationCenterOffset: { - top: 20, - left: 20, - }, - transforms: { - translate: "(50%, 50%)", - scale: "(2)", - }, + handle: imgDiv.find(".rotationHandle"), }; - imgDiv.rotatable(); + imgDiv.rotatable(params); // render newly added icons dom.i2svg();