ajaxify the nav
This commit is contained in:
parent
cab02942d0
commit
2f94c8c08a
6 changed files with 58 additions and 10 deletions
|
@ -1,18 +1,36 @@
|
|||
class Blog::PostsController < BlogController
|
||||
|
||||
before_filter :find_all_blog_posts, :except => [:archive]
|
||||
before_filter :find_blog_post, :only => [:show, :comment]
|
||||
before_filter :find_blog_post, :only => [:show, :comment, :update_nav]
|
||||
|
||||
respond_to :html, :js, :rss if Rails.version >= '3.0.0'
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.rss
|
||||
if Rails.version < '3.0.0'
|
||||
# TODO: respond_to block
|
||||
else
|
||||
respond_with (@blog_posts) do |format|
|
||||
format.html
|
||||
format.rss
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@blog_comment = BlogComment.new
|
||||
present(@page)
|
||||
|
||||
if Rails.version < '3.0.0'
|
||||
# TODO: respond_to block
|
||||
else
|
||||
respond_with (@blog_post) do |format|
|
||||
format.html { present(@page) }
|
||||
format.js { render :partial => 'post', :layout => false }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_nav
|
||||
render :partial => 'nav'
|
||||
end
|
||||
|
||||
def comment
|
||||
|
@ -49,6 +67,11 @@ class Blog::PostsController < BlogController
|
|||
:page => params[:page],
|
||||
:per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
|
||||
})
|
||||
if Rails.version < '3.0.0'
|
||||
# TODO: respond_to block
|
||||
else
|
||||
respond_with (@blog_posts)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -60,4 +60,4 @@
|
|||
</table>
|
||||
</div>
|
||||
|
||||
<% content_for :stylesheets, stylesheet_link_tag('refinery/refinerycms-blog') %>
|
||||
<% content_for :stylesheets, stylesheet_link_tag('refinery/refinerycms-blog') %>
|
||||
|
|
3
app/views/blog/posts/_nav.html.erb
Normal file
3
app/views/blog/posts/_nav.html.erb
Normal file
|
@ -0,0 +1,3 @@
|
|||
<%= link_to raw(truncate(@blog_post.next.title) + " »"), @blog_post.next, :class => 'next', :"data-nav-url" => update_blog_nav_path(@blog_post.next) if @blog_post.next.present? %>
|
||||
<%= link_to 'Blog Home', blog_root_path, :class => 'home' %>
|
||||
<%= link_to "« ".html_safe + truncate(@blog_post.prev.title), @blog_post.prev, :class => 'prev', :"data-nav-url" => update_blog_nav_path(@blog_post.prev) if @blog_post.prev.present? %>
|
|
@ -13,9 +13,7 @@
|
|||
</article>
|
||||
<% if next_or_previous?(@blog_post) -%>
|
||||
<nav id="next_prev_article">
|
||||
<%= link_to raw(truncate(@blog_post.next.title) + " »"), @blog_post.next, :class => 'next' if @blog_post.next.present? %>
|
||||
<%= link_to 'Blog Home', blog_root_path, :class => 'home' %>
|
||||
<%= link_to "« ".html_safe + truncate(@blog_post.prev.title), @blog_post.prev, :class => 'prev' if @blog_post.prev.present? %>
|
||||
<%= render 'nav' %>
|
||||
</nav><!-- /next_prev_article -->
|
||||
<% end -%>
|
||||
<% if BlogPost.comments_allowed? %>
|
||||
|
@ -79,4 +77,5 @@
|
|||
<% end %>
|
||||
|
||||
<%= render :partial => "/shared/content_page", :locals => { :remove_automatic_sections => true } %>
|
||||
<% content_for :stylesheets, stylesheet_link_tag('refinerycms-blog') %>
|
||||
<% content_for :stylesheets, stylesheet_link_tag('refinerycms-blog') %>
|
||||
<% content_for :javascripts, javascript_include_tag('jquery','refinerycms-blog') %>
|
|
@ -42,6 +42,7 @@ else
|
|||
match 'categories/:id', :to => 'categories#show', :as => 'blog_category'
|
||||
match ':id/comments', :to => 'posts#comment', :as => 'blog_post_blog_comments'
|
||||
get 'archive/:year/:month', :to => 'posts#archive', :as => 'archive_blog_posts'
|
||||
get ':id/update_nav.js', :to => 'posts#update_nav', :as => 'update_blog_nav'
|
||||
end
|
||||
|
||||
scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
|
||||
|
|
22
public/javascripts/refinerycms-blog.js
Normal file
22
public/javascripts/refinerycms-blog.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
$(document).ready(function(){
|
||||
height = $('#show_blog_post').height();
|
||||
$('#show_blog_post').height(height);
|
||||
$('#next_prev_article a:not(".home")').click(function(){
|
||||
url = this.href + ".js";
|
||||
nav_url = $(this).attr('data-nav-url');
|
||||
$('#show_blog_post, #next_prev_article').fadeOut();
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function(data) {
|
||||
$('#show_blog_post').html(data).fadeIn().height('auto');
|
||||
$.ajax({
|
||||
url: nav_url,
|
||||
success: function(data) {
|
||||
$('#next_prev_article').html(data).fadeIn();
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
return false;
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue