diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3447b3306..c018be562 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -297,7 +297,7 @@ module ApplicationHelper can_approve_posts disable_categorized_saved_searches disable_mobile_gestures disable_post_tooltips enable_auto_complete enable_post_navigation enable_safe_mode hide_deleted_posts - show_deleted_children style_usernames + show_deleted_children style_usernames default_image_size ] + User::Roles.map { |role| :"is_#{role}?" } end diff --git a/app/javascript/src/javascripts/posts.js.erb b/app/javascript/src/javascripts/posts.js.erb index ef6731983..a16825c6f 100644 --- a/app/javascript/src/javascripts/posts.js.erb +++ b/app/javascript/src/javascripts/posts.js.erb @@ -306,22 +306,17 @@ Post.view_original = function(e) { return; } - var $link = $(e.target); var $image = $("#image"); - var $notice = $("#image-resize-notice"); - $image.attr("src", $link.attr("href")); + $image.attr("src", $(".image-container").data("file-url")); $image.css("filter", "blur(8px)"); $image.width($image.data("original-width")); $image.height($image.data("original-height")); $image.on("load.danbooru", function() { $image.css("animation", "sharpen 0.5s forwards"); - $notice.hide(); - $("#post-option-view-large").show(); }); - $notice.children().eq(0).hide(); - $notice.children().eq(1).show(); // Loading message Note.Box.scale_all(); - e.preventDefault(); + $("body").attr("data-post-current-image-size", "original"); + return false; } Post.view_large = function(e) { @@ -331,20 +326,16 @@ Post.view_large = function(e) { } var $image = $("#image"); - var $notice = $("#image-resize-notice"); $image.attr("src", $(".image-container").data("large-file-url")); $image.css("filter", "blur(8px)"); $image.width($image.data("large-width")); $image.height($image.data("large-height")); - $notice.children().eq(0).show(); - $notice.children().eq(1).hide(); // Loading message $image.on("load.danbooru", function() { $image.css("animation", "sharpen 0.5s forwards"); - $notice.show(); - $("#post-option-view-large").hide(); }); Note.Box.scale_all(); - e.preventDefault(); + $("body").attr("data-post-current-image-size", "large"); + return false; } Post.toggle_fit_window = function(e) { @@ -355,16 +346,16 @@ Post.toggle_fit_window = function(e) { }; Post.initialize_post_image_resize_links = function() { - $("#image-resize-link").on("click.danbooru", Post.view_original); - $("#image-view-large-link").on("click.danbooru", Post.view_large); + $(document).on("click.danbooru", ".image-view-original-link", Post.view_original); + $(document).on("click.danbooru", ".image-view-large-link", Post.view_large); $(document).on("click.danbooru", ".image-resize-to-window-link", Post.toggle_fit_window); if ($("#image-resize-notice").length) { Utility.keydown("v", "resize", function(e) { - if ($("#image-resize-notice").is(":visible")) { - $("#image-resize-link").click(); + if ($("body").attr("data-post-current-image-size") === "large") { + Post.view_original(); } else { - $("#image-view-large-link").click(); + Post.view_large(); } }); } diff --git a/app/javascript/src/styles/specific/posts.scss b/app/javascript/src/styles/specific/posts.scss index 00ad7f2c3..e90f3f59a 100644 --- a/app/javascript/src/styles/specific/posts.scss +++ b/app/javascript/src/styles/specific/posts.scss @@ -433,6 +433,12 @@ div#c-posts { } } +body[data-post-current-image-size="large"] .image-view-large-link, +body[data-post-current-image-size="original"] .image-view-original-link, +body[data-post-current-image-size="original"] #image-resize-notice { + display: none; +} + div#c-post-versions, div#c-artist-versions { div#a-index { a { diff --git a/app/models/post.rb b/app/models/post.rb index 2b9881f20..b709c7f5f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -269,6 +269,11 @@ class Post < ApplicationRecord def resize_percentage 100 * large_image_width.to_f / image_width.to_f end + + # XXX + def current_image_size + has_large? && CurrentUser.default_image_size == "large" ? "large" : "original" + end end module ApprovalMethods @@ -1764,6 +1769,10 @@ class Post < ApplicationRecord save end + def html_data_attributes + super + [:has_large?, :current_image_size] + end + def self.available_includes [:uploader, :updater, :approver, :parent, :upload, :artist_commentary, :flags, :appeals, :notes, :comments, :children, :approvals, :replacements, :pixiv_ugoira_frame_data] end diff --git a/app/views/posts/partials/show/_notices.html.erb b/app/views/posts/partials/show/_notices.html.erb index c34441759..700950efa 100644 --- a/app/views/posts/partials/show/_notices.html.erb +++ b/app/views/posts/partials/show/_notices.html.erb @@ -68,8 +68,7 @@ <% end %> <% if policy(post).visible? && post.has_large? && !post.is_ugoira? %> -
"> - Resized to <%= number_to_percentage post.resize_percentage.floor, :precision => 0 %> of original (<%= link_to "view original", post.tagged_file_url, :id => "image-resize-link" %>) - Loading... +
+ Resized to <%= number_to_percentage post.resize_percentage.floor, precision: 0 %> of original (<%= link_to "view original", post.tagged_file_url, class: "image-view-original-link" %>)
<% end %> diff --git a/app/views/posts/partials/show/_options.html.erb b/app/views/posts/partials/show/_options.html.erb index fbd5e7098..18c8a340f 100644 --- a/app/views/posts/partials/show/_options.html.erb +++ b/app/views/posts/partials/show/_options.html.erb @@ -4,9 +4,12 @@ <%= link_to "Resize to window", "#", class: "image-resize-to-window-link", "data-shortcut": "z" %> <% end %> - <% if post.visible? && post.has_large? && !post.is_ugoira? %> -
  • "> - <%= link_to "View large", post.tagged_large_file_url, id: "image-view-large-link" %> + <% if policy(post).visible? && post.has_large? && !post.is_ugoira? %> +
  • + <%= link_to "View smaller", post.tagged_large_file_url, class: "image-view-large-link" %> +
  • +
  • + <%= link_to "View original", post.tagged_file_url, class: "image-view-original-link" %>
  • <% end %>