added ajaxify popstate cache, so back/forward will just put back the already loaded page

This commit is contained in:
Julian Lam
2015-02-22 01:29:40 -05:00
parent 094cd6df32
commit 77d154bb8b
2 changed files with 48 additions and 2 deletions

View File

@@ -1,9 +1,11 @@
"use strict";
var ajaxify = ajaxify || {};
var ajaxify = ajaxify || {
isPopState: false
};
$(document).ready(function() {
require(['templates'], function (templatesModule) {
require(['templates', 'ajaxifyCache'], function (templatesModule, cache) {
/*global app, templates, utils, socket, translator, config, RELATIVE_PATH*/
var location = document.location || window.location,
@@ -13,7 +15,9 @@ $(document).ready(function() {
window.onpopstate = function (event) {
if (event !== null && event.state && event.state.url !== undefined && !ajaxify.initialLoad) {
ajaxify.isPopState = true;
ajaxify.go(event.state.url, function() {
ajaxify.isPopState = false;
$(window).trigger('action:popstate', {url: event.state.url});
}, true);
}
@@ -55,6 +59,12 @@ $(document).ready(function() {
// "quiet": If set to true, will not call pushState
app.enterRoom('');
// If the url is in the cache, load from cache instead
if (cache.get(url)) { return true; }
else {
cache.url = ajaxify.currentPage;
}
$(window).off('scroll');
if ($('#content').hasClass('ajaxifying') && apiXHR) {
@@ -114,6 +124,7 @@ $(document).ready(function() {
templates.parse(tpl_url, data, function(template) {
translator.translate(template, function(translatedTemplate) {
setTimeout(function() {
cache.set();
$('#content').html(translatedTemplate);
ajaxify.variables.parse();