GUACAMOLE-1204: Provide convenience function for creating an element-relative Guacamole.Position from client coordinates.

This commit is contained in:
Michael Jumper
2021-05-24 19:27:38 -07:00
parent 568355140d
commit 739fbbbf2e

View File

@@ -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;
};