From ffe57d98ba902f537c8fd5dbd041b766ccb49f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= Date: Sat, 23 Feb 2013 15:36:07 +1100 Subject: [PATCH] More accurate and simple note scaling --- app/assets/javascripts/notes.js | 52 ++++++--------------------------- app/assets/javascripts/posts.js | 3 -- 2 files changed, 9 insertions(+), 46 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index aa81df529..dc6ace680 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -88,23 +88,15 @@ Danbooru.Note = { }, scale: function($note_box) { - var $image = $("#image"); - var original_width = parseFloat($image.data("original-width")); - var ratio = $image.width() / original_width; - - if (ratio < 1) { - var scaled_width = Math.round($note_box.width() * ratio); - var scaled_height = Math.round($note_box.height() * ratio); - var scaled_top = Math.round($note_box.position().top * ratio); - var scaled_left = Math.round($note_box.position().left * ratio); - $note_box.css({ - top: scaled_top, - left: scaled_left, - width: scaled_width, - height: scaled_height - }); - Danbooru.Note.Box.resize_inner_border($note_box); - } + var ratio = $image.width() / parseFloat($("#image").data("original-width")); + var $note = $("#notes > article[data-id=" + $note_box.data("id") + "]"); + $note_box.css({ + top: parseFloat($note.data("y")) * ratio, + left: parseFloat($note.data("x")) * ratio, + width: parseFloat($note.data("width")) * ratio, + height: parseFloat($note.data("height")) * ratio + }); + Danbooru.Note.Box.resize_inner_border($note_box); }, scale_all: function() { @@ -113,32 +105,6 @@ Danbooru.Note = { }); }, - descale: function($note_box) { - var $image = $("#image"); - var original_width = parseFloat($image.data("original-width")); - var ratio = original_width / $image.width(); - - if (ratio > 1) { - var scaled_width = Math.round($note_box.width() * ratio); - var scaled_height = Math.round($note_box.height() * ratio); - var scaled_top = Math.round($note_box.position().top * ratio); - var scaled_left = Math.round($note_box.position().left * ratio); - $note_box.css({ - top: scaled_top, - left: scaled_left, - width: scaled_width, - height: scaled_height - }); - Danbooru.Note.Box.resize_inner_border($note_box); - } - }, - - descale_all: function() { - $(".note-box").each(function(i, v) { - Danbooru.Note.Box.descale($(v)); - }); - }, - toggle_all: function() { $(".note-box").toggle(); } diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index 7b381539a..6f67902af 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -82,7 +82,6 @@ Danbooru.Post.initialize_post_image_resize_links = function() { $("#image-resize-link").click(function(e) { - Danbooru.Note.Box.descale_all(); var $link = $(e.target); var $image = $("#image"); $image.attr("src", $link.attr("href")); @@ -99,8 +98,6 @@ $("#image-resize-to-window-link").click(function(e) { var $img = $("#image"); - Danbooru.Note.Box.descale_all(); - if (($img.data("scale_factor") === 1) || ($img.data("scale_factor") === undefined)) { $img.data("original_width", $img.width()); $img.data("original_height", $img.height());