Move the last piece of javascript in util.js

This commit is contained in:
Sébastien Lucas 2014-02-06 21:05:35 +01:00
父節點 1880407cf4
當前提交 8fc7479a33
共有 2 個文件被更改,包括 40 次插入41 次删除

查看文件

@ -79,46 +79,7 @@
<script type="text/javascript">
$(document).ready(function() {
// Handler for .ready() called.
var url = "<?php echo "getJSON.php?" . addURLParameter (getQueryString (), "complete", 1); ?>";
$.when($.get('templates/default/header.html'),
$.get('templates/default/footer.html'),
$.get('templates/default/bookdetail.html'),
$.get('templates/default/main.html'),
$.get('templates/default/page.html'),
$.get('templates/default/suggestion.html'),
$.getJSON(url)).done(function(header, footer, bookdetail, main, page, suggestion, data){
templateBookDetail = doT.template (bookdetail [0]);
var defMain = {
bookdetail: bookdetail [0]
};
templateMain = doT.template (main [0], undefined, defMain);
var defPage = {
header: header [0],
footer: footer [0],
main : main [0],
bookdetail: bookdetail [0]
};
templatePage = doT.template (page [0], undefined, defPage);
templateSuggestion = doT.template (suggestion [0]);
currentData = data [0];
updatePage (data [0]);
cache.put (url, data [0]);
if (isPushStateEnabled) {
history.replaceState(url, "", window.location);
}
handleLinks ();
});
initiateAjax ("<?php echo "getJSON.php?" . addURLParameter (getQueryString (), "complete", 1); ?>");
});

38
util.js
查看文件

@ -440,3 +440,41 @@ $(document).keydown(function(e){
navigateTo ($("#nextLink").attr('href'));
}
});
function initiateAjax (url) {
$.when($.get('templates/default/header.html'),
$.get('templates/default/footer.html'),
$.get('templates/default/bookdetail.html'),
$.get('templates/default/main.html'),
$.get('templates/default/page.html'),
$.get('templates/default/suggestion.html'),
$.getJSON(url)).done(function(header, footer, bookdetail, main, page, suggestion, data){
templateBookDetail = doT.template (bookdetail [0]);
var defMain = {
bookdetail: bookdetail [0]
};
templateMain = doT.template (main [0], undefined, defMain);
var defPage = {
header: header [0],
footer: footer [0],
main : main [0],
bookdetail: bookdetail [0]
};
templatePage = doT.template (page [0], undefined, defPage);
templateSuggestion = doT.template (suggestion [0]);
currentData = data [0];
updatePage (data [0]);
cache.put (url, data [0]);
if (isPushStateEnabled) {
history.replaceState(url, "", window.location);
}
handleLinks ();
});
}