From 71e1d7c2a50c46d750ae593257dbfd8e6ba12886 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 28 Mar 2020 14:56:38 -0500 Subject: [PATCH] notes: fix note mispositioning when image is blacklisted. If the image is blacklisted on initial page load then unblacklisted after the image is loaded, then the notes will be mispositioned at the bottom of the image. This is because we relied on $image.height() to calculate the note position, but the image height is zero when the image is hidden. Potential fix for #4370. --- app/javascript/src/javascripts/notes.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/javascript/src/javascripts/notes.js b/app/javascript/src/javascripts/notes.js index 4da264995..462a1f354 100644 --- a/app/javascript/src/javascripts/notes.js +++ b/app/javascript/src/javascripts/notes.js @@ -379,11 +379,12 @@ let Note = { scale: function($note_box) { var $image = $("#image"); - var ratio = $image.width() / parseFloat($image.data("original-width")); - var x_percent = 100 * ratio * ($note_box.data('x') / $image.width()); - var y_percent = 100 * ratio * ($note_box.data('y') / $image.height()); - var height_percent = 100 * ratio * ($note_box.data('height') / $image.height()); - var width_percent = 100 * ratio * ($note_box.data('width') / $image.width()); + var original_width = $image.data("original-width"); + var original_height = $image.data("original-height"); + var x_percent = 100 * ($note_box.data('x') / original_width); + var y_percent = 100 * ($note_box.data('y') / original_height); + var height_percent = 100 * ($note_box.data('height') / original_height); + var width_percent = 100 * ($note_box.data('width') / original_width); $note_box.css({ top: y_percent + '%', left: x_percent + '%',