add tag seq nav
This commit is contained in:
@@ -50,18 +50,26 @@
|
||||
}
|
||||
|
||||
Danbooru.Post.nav_pool_prev = function() {
|
||||
location.href = $("#pool-nav a.active[rel=prev]").attr("href");
|
||||
if ($("#tag-seq-nav").length) {
|
||||
location.href = $("#tag-seq-nav a[rel=prev]").attr("href");
|
||||
} else {
|
||||
location.href = $("#pool-nav a.active[rel=prev]").attr("href");
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Post.nav_pool_next = function() {
|
||||
location.href = $("#pool-nav a.active[rel=next]").attr("href");
|
||||
if ($("#tag-seq-nav").length) {
|
||||
location.href = $("#tag-seq-nav a[rel=next]").attr("href");
|
||||
} else {
|
||||
location.href = $("#pool-nav a.active[rel=next]").attr("href");
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Post.nav_pool_scroll = function() {
|
||||
var scroll_top = $(window).scrollTop() + $(window).height();
|
||||
|
||||
if (scroll_top > $("#image").height() + $("#image").offset().top + 100) {
|
||||
location.href = $("#pool-nav a.active[rel=next]").attr("href");
|
||||
Danbooru.Post.nav_pool_next();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -321,10 +329,10 @@
|
||||
if (width > 1000) {
|
||||
width = 1000;
|
||||
}
|
||||
if (width < 400) {
|
||||
$("#pool-nav li").css("textAlign", "left");
|
||||
if (width > 700) {
|
||||
width = 700
|
||||
}
|
||||
$("#pool-nav").width(width);
|
||||
$("#pool-nav,#tag-seq-nav").width(width);
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
@@ -122,6 +122,13 @@ div#c-posts {
|
||||
}
|
||||
}
|
||||
|
||||
div.nav-notice {
|
||||
padding: 1em;
|
||||
margin-bottom: 1em;
|
||||
background: #EEE;
|
||||
border: 1px solid #AAA;
|
||||
}
|
||||
|
||||
aside#sidebar #tag-list h2 {
|
||||
font-size: $h4_size;
|
||||
}
|
||||
@@ -205,11 +212,11 @@ div#c-posts {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.pool-name {
|
||||
.pool-name, .tag-name {
|
||||
margin: 0 1em;
|
||||
}
|
||||
|
||||
#pool-nav {
|
||||
#pool-nav, #tag-seq-nav {
|
||||
margin: 1em 0;
|
||||
|
||||
li {
|
||||
|
||||
@@ -27,6 +27,15 @@ class PostsController < ApplicationController
|
||||
respond_with(@post)
|
||||
end
|
||||
|
||||
def show_seq
|
||||
context = PostSearchContext.new(params)
|
||||
if context.post_id
|
||||
redirect_to(post_path(context.post_id, :tags => params[:tags]))
|
||||
else
|
||||
redirect_to(post_path(params[:id], :tags => params[:tags]))
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@post = Post.find(params[:id])
|
||||
@post.update_attributes(params[:post], :as => CurrentUser.role)
|
||||
|
||||
25
app/logical/post_search_context.rb
Normal file
25
app/logical/post_search_context.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class PostSearchContext
|
||||
attr_reader :params, :post_id
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
raise unless params[:seq].present?
|
||||
raise unless params[:id].present?
|
||||
|
||||
@post_id = find_post_id
|
||||
end
|
||||
|
||||
def find_post_id
|
||||
if params[:seq] == "prev"
|
||||
post = Post.tag_match(params[:tags]).where("posts.id > ?", params[:id].to_i).reorder("posts.id asc").first
|
||||
else
|
||||
post = Post.tag_match(params[:tags]).where("posts.id < ?", params[:id].to_i).reorder("posts.id desc").first
|
||||
end
|
||||
|
||||
if post
|
||||
post.id
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -16,7 +16,12 @@ class PostPresenter < Presenter
|
||||
path = options[:path_prefix] || "/posts"
|
||||
|
||||
html = %{<article class="post-preview" id="post_#{post.id}" data-id="#{post.id}" data-tags="#{h(post.tag_string)}" data-uploader="#{h(post.uploader_name)}" data-rating="#{post.rating}" data-width="#{post.image_width}" data-height="#{post.image_height}" data-flags="#{flags.join(' ')}" data-parent-id="#{post.parent_id}" data-has-children="#{post.has_children?}" data-score="#{post.score}">}
|
||||
html << %{<a href="#{path}/#{post.id}">}
|
||||
if options[:tags]
|
||||
tag_param = "?tags=#{CGI::escape(options[:tags])}"
|
||||
else
|
||||
tag_param = nil
|
||||
end
|
||||
html << %{<a href="#{path}/#{post.id}#{tag_param}">}
|
||||
html << %{<img src="#{post.preview_file_url}" alt="#{h(post.tag_string)}">}
|
||||
html << %{</a>}
|
||||
html << %{</article>}
|
||||
|
||||
@@ -12,7 +12,7 @@ module PostSetPresenters
|
||||
end
|
||||
|
||||
posts.each do |post|
|
||||
html << PostPresenter.preview(post)
|
||||
html << PostPresenter.preview(post, :tags => template.params[:tags])
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<section id="pool-nav">
|
||||
<div id="pool-nav" class="ui-corner-all nav-notice">
|
||||
<%= @post.presenter.pool_html(self) %>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
9
app/views/posts/partials/show/_tag_seq.html.erb
Normal file
9
app/views/posts/partials/show/_tag_seq.html.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
<div id="tag-seq-nav" class="ui-corner-all nav-notice">
|
||||
<ul>
|
||||
<li>
|
||||
<%= link_to "«prev".html_safe, show_seq_post_path(post, :tags => params[:tags], :seq => "prev"), :rel => "prev" %>
|
||||
<span class="tag-name">Search: <%= params[:tags] %></span>
|
||||
<%= link_to "next»".html_safe, show_seq_post_path(post, :tags => params[:tags], :seq => "next"), :rel => "next" %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -39,10 +39,14 @@
|
||||
<%= @post.presenter.image_html(self) %>
|
||||
</section>
|
||||
|
||||
<% if params[:tags] %>
|
||||
<%= render "posts/partials/show/tag_seq", :post => @post %>
|
||||
<% end %>
|
||||
|
||||
<% if @post.pools.active.any? %>
|
||||
<%= render "posts/partials/show/pools", :post => @post %>
|
||||
<% end %>
|
||||
|
||||
|
||||
<menu id="post-sections">
|
||||
<li><a href="#comments">Comments</a></li>
|
||||
<li><a href="#edit" id="post-edit-link">Edit</a></li>
|
||||
|
||||
@@ -134,6 +134,7 @@ Danbooru::Application.routes.draw do
|
||||
resources :votes, :controller => "post_votes", :only => [:create, :destroy]
|
||||
member do
|
||||
put :revert
|
||||
get :show_seq
|
||||
end
|
||||
end
|
||||
resources :post_appeals, :only => [:new, :index, :create]
|
||||
|
||||
Reference in New Issue
Block a user