aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Sak <joe@joesak.com>2010-11-20 13:59:27 -0600
committerJoe Sak <joe@joesak.com>2010-11-20 13:59:27 -0600
commit2f94c8c08aec64403fdecf3a13d20dc35a595fb5 (patch)
treea241d59d20989fab950cc3500c22a5a23fc6f220
parentcab02942d0838219ea491f61bbb3c647221e0531 (diff)
downloadrefinerycms-blog-2f94c8c08aec64403fdecf3a13d20dc35a595fb5.tar.gz
refinerycms-blog-2f94c8c08aec64403fdecf3a13d20dc35a595fb5.tar.bz2
refinerycms-blog-2f94c8c08aec64403fdecf3a13d20dc35a595fb5.zip
ajaxify the nav
-rw-r--r--app/controllers/blog/posts_controller.rb33
-rw-r--r--app/views/admin/blog/comments/show.html.erb2
-rw-r--r--app/views/blog/posts/_nav.html.erb3
-rw-r--r--app/views/blog/posts/show.html.erb7
-rw-r--r--config/routes.rb1
-rw-r--r--public/javascripts/refinerycms-blog.js22
6 files changed, 58 insertions, 10 deletions
diff --git a/app/controllers/blog/posts_controller.rb b/app/controllers/blog/posts_controller.rb
index 8c627fd..10ec867 100644
--- a/app/controllers/blog/posts_controller.rb
+++ b/app/controllers/blog/posts_controller.rb
@@ -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
diff --git a/app/views/admin/blog/comments/show.html.erb b/app/views/admin/blog/comments/show.html.erb
index f22edd8..d4c2186 100644
--- a/app/views/admin/blog/comments/show.html.erb
+++ b/app/views/admin/blog/comments/show.html.erb
@@ -60,4 +60,4 @@
</table>
</div>
-<% content_for :stylesheets, stylesheet_link_tag('refinery/refinerycms-blog') %> \ No newline at end of file
+<% content_for :stylesheets, stylesheet_link_tag('refinery/refinerycms-blog') %>
diff --git a/app/views/blog/posts/_nav.html.erb b/app/views/blog/posts/_nav.html.erb
new file mode 100644
index 0000000..6a36a10
--- /dev/null
+++ b/app/views/blog/posts/_nav.html.erb
@@ -0,0 +1,3 @@
+<%= link_to raw(truncate(@blog_post.next.title) + "&nbsp;&#187;"), @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 "&#171;&nbsp;".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? %> \ No newline at end of file
diff --git a/app/views/blog/posts/show.html.erb b/app/views/blog/posts/show.html.erb
index 530bede..778b011 100644
--- a/app/views/blog/posts/show.html.erb
+++ b/app/views/blog/posts/show.html.erb
@@ -13,9 +13,7 @@
</article>
<% if next_or_previous?(@blog_post) -%>
<nav id="next_prev_article">
- <%= link_to raw(truncate(@blog_post.next.title) + "&nbsp;&#187;"), @blog_post.next, :class => 'next' if @blog_post.next.present? %>
- <%= link_to 'Blog Home', blog_root_path, :class => 'home' %>
- <%= link_to "&#171;&nbsp;".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') %> \ No newline at end of file
+<% content_for :stylesheets, stylesheet_link_tag('refinerycms-blog') %>
+<% content_for :javascripts, javascript_include_tag('jquery','refinerycms-blog') %> \ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 01fb501..1474c3f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/public/javascripts/refinerycms-blog.js b/public/javascripts/refinerycms-blog.js
new file mode 100644
index 0000000..f55e279
--- /dev/null
+++ b/public/javascripts/refinerycms-blog.js
@@ -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;
+ })
+}) \ No newline at end of file