Also use the cache event if not using back with browser. re #73

This commit is contained in:
Sébastien Lucas 2013-06-20 21:21:43 +02:00
parent 44c3a10487
commit b2d670a05d
2 changed files with 15 additions and 6 deletions

View file

@ -52,12 +52,14 @@
$(document).ready(function() { $(document).ready(function() {
// Handler for .ready() called. // Handler for .ready() called.
var url = "<?php echo "getJSON.php?" . str_replace ("&", "&amp;", addURLParameter ($_SERVER["QUERY_STRING"], "complete", 1)); ?>";
$.when($.get('templates/default/header.html'), $.when($.get('templates/default/header.html'),
$.get('templates/default/footer.html'), $.get('templates/default/footer.html'),
$.get('templates/default/bookdetail.html'), $.get('templates/default/bookdetail.html'),
$.get('templates/default/main.html'), $.get('templates/default/main.html'),
$.get('templates/default/page.html'), $.get('templates/default/page.html'),
$.getJSON('<?php echo "getJSON.php?" . str_replace ("&", "&amp;", addURLParameter ($_SERVER["QUERY_STRING"], "complete", 1)); ?>')).done(function(header, footer, bookdetail, main, page, data){ $.getJSON(url)).done(function(header, footer, bookdetail, main, page, data){
templateBookDetail = doT.template (bookdetail [0]); templateBookDetail = doT.template (bookdetail [0]);
var defMain = { var defMain = {
@ -77,7 +79,8 @@
currentData = data [0]; currentData = data [0];
updatePage (data [0]); updatePage (data [0]);
history.replaceState(data [0], "", window.location); cache.put (url, data [0]);
history.replaceState(url, "", window.location);
}); });
}); });

View file

@ -66,11 +66,17 @@ function htmlEscape(str) {
function navigateTo (url) { function navigateTo (url) {
before = new Date (); before = new Date ();
var jsonurl = url.replace ("index", "getJSON"); var jsonurl = url.replace ("index", "getJSON");
var cachedData = cache.get (jsonurl);
if (cachedData) {
history.pushState(jsonurl, "", url);
updatePage (cachedData);
} else {
$.getJSON(jsonurl, function(data) { $.getJSON(jsonurl, function(data) {
history.pushState(jsonurl, "", url); history.pushState(jsonurl, "", url);
cache.put (jsonurl, data); cache.put (jsonurl, data);
updatePage (data); updatePage (data);
}); });
}
} }
function updatePage (data) { function updatePage (data) {