More accurate and simple note scaling

This commit is contained in:
小太
2013-02-23 15:36:07 +11:00
parent 800b62b614
commit ffe57d98ba
2 changed files with 9 additions and 46 deletions

View File

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

View File

@@ -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());