Browse Source

Merge pull request #564 from artemave/better-dom-cache

push.js: cache dom before leaving the page, rather than right after loading it
pull/658/head
Connor Sears 10 years ago
parent
commit
d911d8fc71
  1. 9
      js/push.js

9
js/push.js

@ -43,7 +43,6 @@
} }
cacheMapping[data.id] = JSON.stringify(data); cacheMapping[data.id] = JSON.stringify(data);
window.history.replaceState(data.id, data.title, data.url); window.history.replaceState(data.id, data.title, data.url);
domCache[data.id] = document.body.cloneNode(true);
}; };
var cachePush = function () { var cachePush = function () {
@ -61,7 +60,7 @@
delete cacheMapping[cacheBackStack.shift()]; delete cacheMapping[cacheBackStack.shift()];
} }
window.history.pushState(null, '', cacheMapping[PUSH.id].url); window.history.pushState(null, '', getCached(PUSH.id).url);
cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack); cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack);
cacheMapping.cacheBackStack = JSON.stringify(cacheBackStack); cacheMapping.cacheBackStack = JSON.stringify(cacheBackStack);
@ -244,6 +243,8 @@
}); });
} }
cacheCurrentContent();
if (options.timeout) { if (options.timeout) {
options._timeout = setTimeout(function () { xhr.abort('timeout'); }, options.timeout); options._timeout = setTimeout(function () { xhr.abort('timeout'); }, options.timeout);
} }
@ -255,6 +256,10 @@
} }
}; };
function cacheCurrentContent() {
domCache[PUSH.id] = document.body.cloneNode(true);
}
// Main XHR handlers // Main XHR handlers
// ================= // =================

Loading…
Cancel
Save