add hotkey navigationf or posts/pools

This commit is contained in:
albert
2013-02-25 10:13:01 -05:00
parent 10b6dcebd0
commit 436c9af9da
6 changed files with 74 additions and 19 deletions

View File

@@ -2,7 +2,6 @@
Danbooru.Paginator = {};
Danbooru.Paginator.next_page = function() {
console.log("next");
if ($('.paginator li span').parent().next().length) {
window.location = $('.paginator li span').parent().next().find('a').attr('href');
}
@@ -16,7 +15,9 @@
})();
$(function() {
$(document).bind("keydown.right", Danbooru.Paginator.next_page);
$(document).bind("keydown.left", Danbooru.Paginator.prev_page);
if ($(".paginator").length) {
$(document).bind("keydown.right", Danbooru.Paginator.next_page);
$(document).bind("keydown.left", Danbooru.Paginator.prev_page);
}
});

View File

@@ -2,6 +2,7 @@
Danbooru.Post = {};
Danbooru.Post.pending_update_count = 0;
Danbooru.Post.scroll_top = 0;
Danbooru.Post.initialize_all = function() {
this.initialize_titles();
@@ -21,6 +22,7 @@
this.initialize_post_image_resize_to_window_link();
this.initialize_similar();
this.place_jlist_ads();
this.center_pool_nav();
if (Danbooru.meta("always-resize-images") === "true") {
$("#image-resize-to-window-link").click();
@@ -60,6 +62,28 @@
$("#post_tag_string").trigger("focus");
e.preventDefault();
});
$(document).bind("keydown.left", function(e) {
location.href = $("#pool-nav a.active[rel=prev]").attr("href");
e.preventDefault();
});
$(document).bind("keydown.right", function(e) {
location.href = $("#pool-nav a.active[rel=next]").attr("href");
e.preventDefault();
});
$(document).bind("keydown.space", function() {
Danbooru.Post.scroll_top = Danbooru.Post.scroll_top + 800;
if (Danbooru.Post.scroll_top > $("#image").height() + $("#image").offset().top + 100) {
location.href = $("#pool-nav a.active[rel=next]").attr("href");
}
$('html, body').animate({
scrollTop: Danbooru.Post.scroll_top
}, 500);
})
}
}
@@ -111,6 +135,7 @@
Danbooru.Note.Box.scale_all();
$("#image-resize-notice").hide();
Danbooru.Post.place_jlist_ads();
Danbooru.Post.center_pool_nav();
e.preventDefault();
});
}
@@ -139,6 +164,7 @@
Danbooru.Note.Box.scale_all();
Danbooru.Post.place_jlist_ads()
Danbooru.Post.center_pool_nav();
e.preventDefault();
});
}
@@ -276,6 +302,17 @@
}
}
}
Danbooru.Post.center_pool_nav = function() {
var width = $("#image").width();
if (width > 1000) {
width = 1000;
}
if (width < 400) {
$("#pool-nav li").css("textAlign", "left");
}
$("#pool-nav").width(width);
}
})();
$(document).ready(function() {

View File

@@ -176,16 +176,16 @@ div#c-posts {
}
div#a-show {
.active {
font-weight: bold;
}
menu#post-sections {
margin: 0;
font-size: $h3_size;
li {
padding: 0 1em 0 0;
&.active {
font-weight: bold;
}
}
div.share a {
@@ -204,6 +204,19 @@ div#c-posts {
span.quick-mod {
float: right;
}
.pool-name {
margin: 0 1em;
}
#pool-nav {
margin: 1em 0;
li {
text-align: center;
height: 1.5em;
}
}
}
div#quick-edit-div {

View File

@@ -115,27 +115,31 @@ class PostPresenter < Presenter
if options[:include_rel]
prev_rel = "prev"
next_rel = "next"
klass = "active"
else
prev_rel = nil
next_rel = nil
klass = ""
end
if pool.neighbors(@post).previous
pool_html << template.link_to("&laquo;prev".html_safe, template.post_path(pool.neighbors(@post).previous, :pool_id => pool.id), :rel => prev_rel)
pool_html << template.link_to("&laquo;prev".html_safe, template.post_path(pool.neighbors(@post).previous, :pool_id => pool.id), :rel => prev_rel, :class => klass)
match_found = true
else
pool_html << "&laquo;prev"
end
pool_html << ' <span class="pool-name ' + klass + '">'
pool_html << template.link_to("Pool: #{pool.pretty_name}", template.pool_path(pool))
pool_html << '</span> '
if pool.neighbors(@post).next
pool_html << template.link_to("next&raquo;".html_safe, template.post_path(pool.neighbors(@post).next, :pool_id => pool.id), :rel => next_rel)
pool_html << template.link_to("next&raquo;".html_safe, template.post_path(pool.neighbors(@post).next, :pool_id => pool.id), :rel => next_rel, :class => klass)
match_found = true
else
pool_html << "next&raquo;"
end
pool_html << " "
pool_html << template.link_to(pool.pretty_name, template.pool_path(pool))
pool_html << "</li>"
if match_found

View File

@@ -0,0 +1,3 @@
<section id="pool-nav">
<%= @post.presenter.pool_html(self) %>
</section>

View File

@@ -5,13 +5,6 @@
<%= render_advertisement("vertical") %>
<% if @post.pools.active.any? %>
<section id="pool-sidebar">
<h1>Pools</h1>
<%= @post.presenter.pool_html(self) %>
</section>
<% end %>
<section id="tag-list">
<%= @post.presenter.split_tag_list_html(self) %>
</section>
@@ -45,7 +38,11 @@
<div id="note-container"></div>
<%= @post.presenter.image_html(self) %>
</section>
<% 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>