fixes #805
This commit is contained in:
41
app/assets/javascripts/post_popular.js
Normal file
41
app/assets/javascripts/post_popular.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
(function() {
|
||||||
|
Danbooru.PostPopular = {};
|
||||||
|
|
||||||
|
Danbooru.PostPopular.nav_prev = function() {
|
||||||
|
if ($("#popular-nav-links").length) {
|
||||||
|
var href = $("#popular-nav-links a[rel=prev]").attr("href");
|
||||||
|
if (href) {
|
||||||
|
location.href = href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Danbooru.PostPopular.nav_next = function() {
|
||||||
|
if ($("#popular-nav-links").length) {
|
||||||
|
var href = $("#popular-nav-links a[rel=next]").attr("href");
|
||||||
|
if (href) {
|
||||||
|
location.href = href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Danbooru.PostPopular.initialize_all = function() {
|
||||||
|
if ($("#c-explore-posts").length) {
|
||||||
|
if (Danbooru.meta("enable-js-navigation") === "true") {
|
||||||
|
$(document).bind("keydown.a", function(e) {
|
||||||
|
Danbooru.PostPopular.nav_prev();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).bind("keydown.d", function(e) {
|
||||||
|
Danbooru.PostPopular.nav_next();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
Danbooru.PostPopular.initialize_all();
|
||||||
|
});
|
||||||
@@ -31,6 +31,83 @@ module PostSetPresenters
|
|||||||
1.month.since(date)
|
1.month.since(date)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def link_rel_for_scale?(template, scale)
|
||||||
|
(template.params[:scale].blank? && scale == "day") || template.params[:scale].to_s.include?(scale)
|
||||||
|
end
|
||||||
|
|
||||||
|
def next_date_for_scale(scale)
|
||||||
|
case scale
|
||||||
|
when "Day"
|
||||||
|
next_day
|
||||||
|
|
||||||
|
when "Week"
|
||||||
|
next_week
|
||||||
|
|
||||||
|
when "Month"
|
||||||
|
next_month
|
||||||
|
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def prev_date_for_scale(scale)
|
||||||
|
case scale
|
||||||
|
when "Day"
|
||||||
|
prev_day
|
||||||
|
|
||||||
|
when "Week"
|
||||||
|
prev_week
|
||||||
|
|
||||||
|
when "Month"
|
||||||
|
prev_month
|
||||||
|
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def nav_links_for_scale(template, scale)
|
||||||
|
html = []
|
||||||
|
html << '<span class="period">'
|
||||||
|
html << template.link_to(
|
||||||
|
"«prev".html_safe,
|
||||||
|
template.popular_explore_posts_path(
|
||||||
|
:date => prev_date_for_scale(scale),
|
||||||
|
:scale => scale.downcase
|
||||||
|
),
|
||||||
|
:rel => (link_rel_for_scale?(template, scale.downcase) ? "prev" : nil)
|
||||||
|
)
|
||||||
|
html << template.link_to(
|
||||||
|
scale,
|
||||||
|
template.popular_explore_posts_path(
|
||||||
|
:date => date,
|
||||||
|
:scale => scale.downcase
|
||||||
|
),
|
||||||
|
:class => "desc"
|
||||||
|
)
|
||||||
|
html << template.link_to(
|
||||||
|
"next»".html_safe,
|
||||||
|
template.popular_explore_posts_path(
|
||||||
|
:date => next_date_for_scale(scale),
|
||||||
|
:scale => scale.downcase
|
||||||
|
),
|
||||||
|
:rel => (link_rel_for_scale?(template, scale.downcase) ? "next" : nil)
|
||||||
|
)
|
||||||
|
html << '</span>'
|
||||||
|
html.join("\n").html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
def nav_links(template)
|
||||||
|
html = []
|
||||||
|
html << '<p id="popular-nav-links">'
|
||||||
|
html << nav_links_for_scale(template, "Day")
|
||||||
|
html << nav_links_for_scale(template, "Week")
|
||||||
|
html << nav_links_for_scale(template, "Month")
|
||||||
|
html << '</p>'
|
||||||
|
html.join("\n").html_safe
|
||||||
|
end
|
||||||
|
|
||||||
def range_text
|
def range_text
|
||||||
if min_date == max_date
|
if min_date == max_date
|
||||||
date.strftime("%B %d, %Y")
|
date.strftime("%B %d, %Y")
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
<p>
|
|
||||||
<span class="period">
|
|
||||||
<%= link_to "«prev".html_safe, popular_explore_posts_path(:date => post_set.presenter.prev_day, :scale => "day") %>
|
|
||||||
<%= link_to "Day", popular_explore_posts_path(:date => post_set.presenter.date, :scale => "day"), :class => "desc" %>
|
|
||||||
<%= link_to "next»".html_safe, popular_explore_posts_path(:date => post_set.presenter.next_day, :scale => "day") %>
|
|
||||||
</span>
|
|
||||||
|
|
|
||||||
<span class="period">
|
|
||||||
<%= link_to "«prev".html_safe, popular_explore_posts_path(:date => post_set.presenter.prev_week, :scale => "week") %>
|
|
||||||
<%= link_to "Week", popular_explore_posts_path(:date => post_set.presenter.date, :scale => "week"), :class => "desc" %>
|
|
||||||
<%= link_to "next»".html_safe, popular_explore_posts_path(:date => post_set.presenter.next_week, :scale => "week") %>
|
|
||||||
</span>
|
|
||||||
|
|
|
||||||
<span class="period">
|
|
||||||
<%= link_to "«prev".html_safe, popular_explore_posts_path(:date => post_set.presenter.prev_month, :scale => "month") %>
|
|
||||||
<%= link_to "Month", popular_explore_posts_path(:date => post_set.presenter.date, :scale => "month"), :class => "desc" %>
|
|
||||||
<%= link_to "next»".html_safe, popular_explore_posts_path(:date => post_set.presenter.next_month, :scale => "month") %>
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<div id="a-index">
|
<div id="a-index">
|
||||||
<h1>Popular: <%= @post_set.presenter.range_text %></h1>
|
<h1>Popular: <%= @post_set.presenter.range_text %></h1>
|
||||||
|
|
||||||
<%= render "date_explore", :post_set => @post_set %>
|
<%= @post_set.presenter.nav_links(self) %>
|
||||||
|
|
||||||
<%= render "blacklists" %>
|
<%= render "blacklists" %>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user