Created
May 8, 2014 14:09
-
-
Save alxfv/98c4b943a25acb0aa610 to your computer and use it in GitHub Desktop.
ajax history.js
This file contains hidden or 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
History.Adapter.bind(window, 'statechange',function(){ // Note: We are using statechange instead of popstate | |
var State = History.getState(); // Note: We are using History.getState() instead of event.state | |
if (State.data.state !== undefined) { | |
var url = State.url; | |
$.ajax({ | |
url: url | |
}).done(function(data) { | |
$('.content').html(data); | |
}); | |
} | |
}); | |
$(document).on('click', '.b-menu > li > a', function(e) { | |
e.preventDefault(); | |
var $this = $(this); | |
var url = $this.attr('href'); | |
var state = $this.attr('data-state'); | |
History.pushState({ state: state }, "State " + state, url); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment