Permalink
Browse files

fix pjax

  • Loading branch information...
1 parent f0acbc0 commit cb6fdf88ef996c19ba833eb80d5bd33610979759 @mcfiredrill committed Jul 23, 2012
@@ -25,26 +25,9 @@ function insert_emoticon(face) {
}
$(document).ready(function() {
- img_src = '/images/spinner.gif';
-
- function createSpinner() {
- return $('<img/>', {
- src: img_src,
- class: 'spinner'
- });
- }
-
- $('.pagination a').on('click', function(e) {
- e.preventDefault();
-
- var $el = $(e.target);
- $el.closest('.pagination').append(createSpinner());
- target = $('branches');
- $.pjax({
- url: $el.attr('href'),
- container: '#page'
- });
- });
+ $('.pagination a').pjax('#branches',{timeout:2000});
+ $('#branches').bind('pjax:start', function(){ $('.loader').show(); })
+ .bind('pjax:end', function(){ $('.loader').hide(); });
});
/* yoinked from wakaba */
@@ -2,14 +2,17 @@ class BranchesController < ApplicationController
before_filter :check_password, :only => [:destroy]
+ layout :set_layout
+
def new
+ logger.info "HEADERS: #{request.headers['X-PJAX']}"
@branch = Branch.new
@leaf = Leaf.new
@branches = Branch.paginate(:page => params[:page])
- if request.headers['X-PJAX']
- render :partial => 'cur_page'
- end
+ if request.headers['X-PJAX']
+ render :partial => 'cur_page'
+ end
end
def create
@@ -60,4 +63,14 @@ def destroy
format.html { redirect_to new_branch_path }
end
end
+
+ protected
+
+ def set_layout
+ if request.headers['X-PJAX']
+ false
+ else
+ "application"
+ end
+ end
end
@@ -1,5 +1,5 @@
%div#page
- = will_paginate
- %div.branches
+ %div#branches
+ = will_paginate
= render @branches, :action => :show
- = will_paginate
+ = will_paginate
@@ -1,7 +1,11 @@
= render :partial => "layouts/form", :locals => { :newpost => @branch, :leaf => @leaf, :branch => @branch }
= form_for :branch, :html => { :method => :delete } do |del|
+ %div.loader(style='display:none')
+ %img(src='/images/spinner.gif')
= render :partial => 'cur_page', :locals => { :del => del }
+ %div.loader(style='display:none')
+ %img(src='/images/spinner.gif')
%table.deleteform
%tbody
%tr

0 comments on commit cb6fdf8

Please sign in to comment.