-
-
Save seyhunak/1471973 to your computer and use it in GitHub Desktop.
Kaminari and pushState
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This doesn't work for me. "ajax:success" ist not triggered. So I changed it to the "click" event for now
For some reason it only works the first time
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
Why does this generate random numbers in query strings. How to avoid that?