Also use the cache event if not using back with browser. re #73
This commit is contained in:
parent
44c3a10487
commit
b2d670a05d
|
@ -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 ("&", "&", 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 ("&", "&", 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);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
6
util.js
6
util.js
|
@ -66,12 +66,18 @@ 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) {
|
||||||
var result;
|
var result;
|
||||||
|
|
Loading…
Reference in a new issue