From 739fbbbf2ed3bb461988f83885b331d8e7b65684 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 24 May 2021 19:27:38 -0700 Subject: [PATCH] GUACAMOLE-1204: Provide convenience function for creating an element-relative Guacamole.Position from client coordinates. --- .../src/main/webapp/modules/Position.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/guacamole-common-js/src/main/webapp/modules/Position.js b/guacamole-common-js/src/main/webapp/modules/Position.js index faaeca343..18e895a34 100644 --- a/guacamole-common-js/src/main/webapp/modules/Position.js +++ b/guacamole-common-js/src/main/webapp/modules/Position.js @@ -90,3 +90,29 @@ Guacamole.Position = function Position(template) { }; }; + +/** + * Returns a new {@link Guacamole.Position} representing the relative position + * of the given clientX/clientY coordinates within the given element. The + * clientX and clientY coordinates are relative to the browser viewport and are + * commonly available within JavaScript event objects. The final position is + * translated to coordinates that are relative the given element. + * + * @param {Element} element + * The element the coordinates should be relative to. + * + * @param {Number} clientX + * The viewport-relative X coordinate to translate. + * + * @param {Number} clientY + * The viewport-relative Y coordinate to translate. + * + * @returns {Guacamole.Position} + * A new Guacamole.Position representing the relative position of the given + * client coordinates. + */ +Guacamole.Position.fromClientPosition = function fromClientPosition(element, clientX, clientY) { + var position = new Guacamole.Position(); + position.fromClientPosition(element, clientX, clientY); + return position; +};