2013-06-16 09:46:41 +03:00
|
|
|
var templatePage, templateBookDetail, templateMain, result;
|
2013-06-15 09:27:33 +03:00
|
|
|
|
2013-06-16 08:50:14 +03:00
|
|
|
var isEink = /Kobo|Kindle|EBRD1101/i.test(navigator.userAgent);
|
|
|
|
|
|
|
|
function fancyBoxObject (title, type) {
|
|
|
|
var out = { prevEffect : 'none', nextEffect : 'none' };
|
|
|
|
if (isEink) {
|
|
|
|
out ["openEffect"] = 'none';
|
|
|
|
out ["closeEffect"] = 'none';
|
|
|
|
out ["helper"] = { overlay : null };
|
|
|
|
}
|
|
|
|
if (title) out ["title"] = title;
|
|
|
|
if (type) out ["type"] = type;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2013-06-15 09:03:22 +03:00
|
|
|
function htmlEscape(str) {
|
|
|
|
return String(str)
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
.replace(/'/g, ''')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>');
|
2013-06-15 09:27:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function navigateTo (url) {
|
2013-06-15 17:09:37 +03:00
|
|
|
var jsonurl = url.replace ("index", "getJSON");
|
2013-06-15 09:27:33 +03:00
|
|
|
$.getJSON(jsonurl, function(data) {
|
|
|
|
history.pushState(data, "", url);
|
|
|
|
updatePage (data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatePage (data) {
|
2013-06-16 09:46:41 +03:00
|
|
|
result = templatePage (data);
|
2013-06-15 09:27:33 +03:00
|
|
|
document.title = data.title;
|
|
|
|
$(".container").html (result);
|
|
|
|
|
|
|
|
ajaxifyLinks ();
|
2013-06-15 17:09:37 +03:00
|
|
|
|
|
|
|
$(".fancydetail").click(function(event){
|
|
|
|
event.preventDefault();
|
|
|
|
var url = $(this).attr("href");
|
|
|
|
var jsonurl = url.replace ("bookdetail", "getJSON");
|
|
|
|
$.getJSON(jsonurl, function(data) {
|
|
|
|
var detail = templateBookDetail (data);
|
|
|
|
$.fancybox( {
|
|
|
|
content: detail,
|
|
|
|
autoSize: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-06-15 09:27:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxifyLinks () {
|
|
|
|
if (history.pushState) {
|
|
|
|
$("a[href^='index']").click (function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var url = $(this).attr('href');
|
|
|
|
navigateTo (url);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onpopstate = function(event) {
|
|
|
|
updatePage (event.state);
|
|
|
|
};
|
|
|
|
|
2013-06-16 15:47:11 +03:00
|
|
|
$(document).keydown(function(e){
|
2013-06-15 09:27:33 +03:00
|
|
|
if (e.keyCode == 37 && $("#prevLink").length > 0) {
|
|
|
|
navigateTo ($("#prevLink").attr('href'));
|
|
|
|
}
|
|
|
|
if (e.keyCode == 39 && $("#nextLink").length > 0) {
|
|
|
|
navigateTo ($("#nextLink").attr('href'));
|
|
|
|
}
|
|
|
|
});
|