From 5895f4faa63902b325a058172336163d950f3e41 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Mon, 23 Nov 2020 18:13:57 +0100 Subject: [PATCH] Rewrite CropEditor.positionBoundary --- public/js/crop_editor.js | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/public/js/crop_editor.js b/public/js/crop_editor.js index 92c4caf..172733f 100644 --- a/public/js/crop_editor.js +++ b/public/js/crop_editor.js @@ -258,21 +258,10 @@ class CropEditor { } positionBoundary(event) { - let source_x = parseInt(this.source_x.value), - source_y = parseInt(this.source_y.value), - crop_width = parseInt(this.crop_width.value), - crop_height = parseInt(this.crop_height.value), - real_width = this.original_image.naturalWidth, - real_height = this.original_image.naturalHeight, - scaled_width = this.original_image.clientWidth, - scaled_height = this.original_image.clientHeight; - - let width_scale = scaled_width / real_width, - height_scale = scaled_height / real_height; - - crop_boundary.style.left = (this.source_x.value) * width_scale + "px"; - crop_boundary.style.top = (this.source_y.value) * height_scale + "px"; - crop_boundary.style.width = (this.crop_width.value) * width_scale + "px"; - crop_boundary.style.height = (this.crop_height.value) * height_scale + "px"; + let scaleFactor = this.getScaleFactor(); + crop_boundary.style.left = parseInt(this.source_x.value) * scaleFactor + "px"; + crop_boundary.style.top = parseInt(this.source_y.value) * scaleFactor + "px"; + crop_boundary.style.width = parseInt(this.crop_width.value) * scaleFactor + "px"; + crop_boundary.style.height = parseInt(this.crop_height.value) * scaleFactor + "px"; } }