posts: add "view original" sidebar option.
* Add a "View original" sidebar option. * Rename the "View large" sidebar option to "View smaller". * Remove the "Loading..." message when switching image sizes. * Fix the V hotkey not working after using it once. * Change #image-resize-link to .image-view-original link (note that there are two of these links now, one in the notice bar and one in the sidebar). * Add a `data-post-current-image-size` attribute on the <body> element and use it to control visibility of links and notices.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -68,8 +68,7 @@
|
||||
<% end %>
|
||||
|
||||
<% if policy(post).visible? && post.has_large? && !post.is_ugoira? %>
|
||||
<div class="notice notice-small post-notice post-notice-resized" id="image-resize-notice" style="<%= CurrentUser.default_image_size == "original" ? "display: none;" : "" %>">
|
||||
<span>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" %>)</span>
|
||||
<span style="display: none;">Loading...</span>
|
||||
<div class="notice notice-small post-notice post-notice-resized" id="image-resize-notice">
|
||||
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" %>)
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
<%= link_to "Resize to window", "#", class: "image-resize-to-window-link", "data-shortcut": "z" %>
|
||||
</li>
|
||||
<% end %>
|
||||
<% if post.visible? && post.has_large? && !post.is_ugoira? %>
|
||||
<li id="post-option-view-large" style="<%= CurrentUser.default_image_size == "original" ? "" : "display: none;" %>">
|
||||
<%= link_to "View large", post.tagged_large_file_url, id: "image-view-large-link" %>
|
||||
<% if policy(post).visible? && post.has_large? && !post.is_ugoira? %>
|
||||
<li id="post-option-view-large">
|
||||
<%= link_to "View smaller", post.tagged_large_file_url, class: "image-view-large-link" %>
|
||||
</li>
|
||||
<li id="post-option-view-original">
|
||||
<%= link_to "View original", post.tagged_file_url, class: "image-view-original-link" %>
|
||||
</li>
|
||||
<% end %>
|
||||
<li id="post-option-find-similar">
|
||||
|
||||
Reference in New Issue
Block a user