diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index f0146be48..1d588b7ae 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -18,6 +18,7 @@ this.initialize_links(); this.initialize_post_sections(); this.initialize_post_image_resize_links(); + this.initialize_post_image_resize_to_window_link(); this.place_jlist_ads(); } } @@ -88,6 +89,37 @@ }); } + Danbooru.Post.initialize_post_image_resize_to_window_link = function() { + $("#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()); + var client_width = $(window).width() - $("#sidebar").width() - 75; + var client_height = $(window).height(); + + if ($img.width() > client_width) { + var ratio = client_width / $img.width(); + $img.data("scale_factor", ratio); + $img.css("width", $img.width() * ratio); + $img.css("height", $img.height() * ratio); + console.log("ratio=%f", ratio); + } + } else { + $img.data("scale_factor", 1); + $img.width($img.data("original_width")); + $img.height($img.data("original_height")); + } + + Danbooru.Note.Box.scale_all(); + Danbooru.Post.place_jlist_ads() + e.preventDefault(); + }); + } + Danbooru.Post.initialize_wiki_page_excerpt = function() { $("#wiki-page-excerpt").hide(); diff --git a/app/views/posts/partials/show/_information.html.erb b/app/views/posts/partials/show/_information.html.erb index 5724108d8..eab65adb1 100644 --- a/app/views/posts/partials/show/_information.html.erb +++ b/app/views/posts/partials/show/_information.html.erb @@ -13,7 +13,6 @@