added popstate functionality

This commit is contained in:
Julian Lam
2013-05-14 12:04:38 -04:00
parent 0bb0fd5789
commit c351d83418
2 changed files with 13 additions and 8 deletions

View File

@@ -21,11 +21,13 @@ var ajaxify = {};
window.onpopstate = function(event) {
// this breaks reloading and results in ajaxify.go calling twice, believe it messes around with sockets. ill come back for you later bitchez
// ajaxify.go(document.location.href.replace(rootUrl +'/', ''));
console.log('popstate called:', event);
if (event !== null && event.state && event.state.url) ajaxify.go(event.state.url, null, null, true);
};
ajaxify.go = function(url, callback, custom_tpl) {
ajaxify.go = function(url, callback, template, quiet) {
console.log('go', url, quiet);
// "quiet": If set to true, will not call pushState
// leave room and join global
app.enter_room('global');
@@ -41,7 +43,12 @@ var ajaxify = {};
}
if (templates[tpl_url]) {
window.history.pushState({}, url, "/" + url);
if (quiet !== true) {
console.log('pushing state');
window.history.pushState({
"url": url
}, url, "/" + url);
}
jQuery('#footer').fadeOut(100);
jQuery('#content').fadeOut(100);
@@ -55,7 +62,7 @@ var ajaxify = {};
}
jQuery('#content, #footer').fadeIn(200);
}, custom_tpl);
}, url, template);
return true;