Skip to content

Instantly share code, notes, and snippets.

@seyhunak
Forked from moro/gist:1024620
Created December 13, 2011 12:29
Show Gist options
  • Save seyhunak/1471973 to your computer and use it in GitHub Desktop.
Save seyhunak/1471973 to your computer and use it in GitHub Desktop.
Kaminari and pushState
(function($){
$('.pagination a[data-remote=true]').live('ajax:success', function(e){ window.history.pushState('', '', $(e.target).attr('href')) })
$(window).bind('popstate', function(){ $.ajax({url:window.location, dataType:'script'}) ; return true });
})(jQuery);
@cserb
Copy link

cserb commented May 13, 2013

This doesn't work for me. "ajax:success" ist not triggered. So I changed it to the "click" event for now

@renevall
Copy link

For some reason it only works the first time

@renevall
Copy link

Ok I finally have a code up to date on this code

jQuery ->
  $(document).on "click",'.pagination a[data-remote=true]', (e) ->
    history.pushState {}, '', $(@).attr('href')

.live is deprecated, .click stops working after first click, since according to kaminari example, they use .html() function which to keep it simple, destroy the event handler. By using on() like this, you recreate the bindings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment