2013-06-20 15:34:10 +03:00
|
|
|
var templatePage, templateBookDetail, templateMain, currentData, before;
|
2013-06-15 09:27:33 +03:00
|
|
|
|
2013-06-20 22:08:50 +03:00
|
|
|
var cache = new LRUCache(30);
|
|
|
|
|
2013-06-20 15:34:10 +03:00
|
|
|
var DEBUG = true;
|
2013-06-16 08:50:14 +03:00
|
|
|
var isEink = /Kobo|Kindle|EBRD1101/i.test(navigator.userAgent);
|
2013-06-20 15:43:31 +03:00
|
|
|
var isPushStateEnabled = window.history && window.history.pushState && window.history.replaceState &&
|
|
|
|
// pushState isn't reliable on iOS until 5.
|
|
|
|
!navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]|WebApps\/.+CFNetwork)/);
|
2013-06-16 08:50:14 +03:00
|
|
|
|
2013-06-20 15:34:10 +03:00
|
|
|
function debug_log(text) {
|
|
|
|
if ( DEBUG ) {
|
|
|
|
console.log(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function elapsed () {
|
|
|
|
var elapsed = new Date () - before;
|
|
|
|
return "Elapsed : " + elapsed;
|
|
|
|
}
|
|
|
|
|
2013-06-21 22:31:49 +03:00
|
|
|
function retourMail(data, textStatus, jqXHR ) {
|
|
|
|
alert (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendToMailAddress (component, dataid) {
|
|
|
|
$toto = $.cookie ('email');
|
|
|
|
if (!$.cookie ('email')) {
|
|
|
|
var email = window.prompt ("Please enter your email : ", "");
|
|
|
|
$.cookie ('email', email);
|
|
|
|
}
|
|
|
|
email = $.cookie ('email');
|
|
|
|
var url = 'sendtomail.php';
|
|
|
|
if (currentData.databaseId) url = url + '?db=' + currentData.databaseId;
|
|
|
|
$.ajax ({url: url, type: 'post', data: { data: dataid, email: email }, success: retourMail});
|
|
|
|
}
|
|
|
|
|
2013-06-17 23:23:58 +03:00
|
|
|
function strformat () {
|
|
|
|
var s = arguments[0];
|
2013-06-17 23:30:09 +03:00
|
|
|
for (var i = 0; i < arguments.length - 1; i++) {
|
|
|
|
var reg = new RegExp("\\{" + i + "\\}", "gm");
|
2013-06-17 23:23:58 +03:00
|
|
|
s = s.replace(reg, arguments[i + 1]);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-06-20 12:11:01 +03:00
|
|
|
function isDefined(x) {
|
|
|
|
var undefined;
|
|
|
|
return x !== undefined;
|
|
|
|
}
|
|
|
|
|
2013-06-16 23:01:13 +03:00
|
|
|
function getCurrentOption (option) {
|
2013-06-20 21:31:57 +03:00
|
|
|
if (!$.cookie (option)) {
|
|
|
|
if (currentData && currentData.const && currentData.const.config && currentData.const.config [option]) {
|
|
|
|
return currentData.const.config [option];
|
|
|
|
}
|
|
|
|
}
|
2013-06-16 23:01:13 +03:00
|
|
|
return $.cookie (option);
|
|
|
|
}
|
|
|
|
|
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-20 15:34:10 +03:00
|
|
|
before = new Date ();
|
2013-06-15 17:09:37 +03:00
|
|
|
var jsonurl = url.replace ("index", "getJSON");
|
2013-06-20 22:21:43 +03:00
|
|
|
var cachedData = cache.get (jsonurl);
|
|
|
|
if (cachedData) {
|
2013-06-20 22:08:50 +03:00
|
|
|
history.pushState(jsonurl, "", url);
|
2013-06-20 22:21:43 +03:00
|
|
|
updatePage (cachedData);
|
|
|
|
} else {
|
|
|
|
$.getJSON(jsonurl, function(data) {
|
|
|
|
history.pushState(jsonurl, "", url);
|
|
|
|
cache.put (jsonurl, data);
|
|
|
|
updatePage (data);
|
|
|
|
});
|
|
|
|
}
|
2013-06-15 09:27:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function updatePage (data) {
|
2013-06-20 15:34:10 +03:00
|
|
|
var result;
|
2013-06-17 22:21:52 +03:00
|
|
|
data ["const"] = currentData ["const"];
|
2013-06-20 15:34:10 +03:00
|
|
|
if (false && $("section").length && currentData.isPaginated == 0 && data.isPaginated == 0) {
|
|
|
|
// Partial update (for now disabled)
|
|
|
|
debug_log ("Partial update");
|
|
|
|
result = templateMain (data);
|
|
|
|
$("h1").html (data.title);
|
|
|
|
$("section").html (result);
|
|
|
|
} else {
|
|
|
|
// Full update
|
|
|
|
result = templatePage (data);
|
|
|
|
$("body").html (result);
|
|
|
|
}
|
2013-06-15 09:27:33 +03:00
|
|
|
document.title = data.title;
|
2013-06-20 15:34:10 +03:00
|
|
|
currentData = data;
|
|
|
|
|
|
|
|
debug_log (elapsed ());
|
2013-06-15 09:27:33 +03:00
|
|
|
|
2013-06-16 16:08:47 +03:00
|
|
|
if ($.cookie('toolbar') == 1) $("#tool").show ();
|
2013-06-20 15:34:10 +03:00
|
|
|
if (currentData.containsBook == 1) {
|
|
|
|
$("#sortForm").show ();
|
|
|
|
} else {
|
|
|
|
$("#sortForm").hide ();
|
|
|
|
}
|
2013-06-16 16:08:47 +03:00
|
|
|
|
2013-06-15 09:27:33 +03:00
|
|
|
ajaxifyLinks ();
|
2013-06-15 17:09:37 +03:00
|
|
|
|
2013-06-16 23:01:13 +03:00
|
|
|
$("#sort").click(function(){
|
|
|
|
$('.books').sortElements(function(a, b){
|
|
|
|
var test = 1;
|
|
|
|
if ($("#sortorder").val() == "desc")
|
|
|
|
{
|
|
|
|
test = -1;
|
|
|
|
}
|
|
|
|
return $(a).find ("." + $("#sortchoice").val()).text() > $(b).find ("." + $("#sortchoice").val()).text() ? test : -test;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-06-16 16:08:47 +03:00
|
|
|
$(".headright").click(function(){
|
|
|
|
if ($("#tool").is(":hidden")) {
|
|
|
|
$("#tool").slideDown("slow");
|
|
|
|
$.cookie('toolbar', '1');
|
|
|
|
} else {
|
|
|
|
$("#tool").slideUp();
|
|
|
|
$.removeCookie('toolbar');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-06-16 23:01:13 +03:00
|
|
|
if (getCurrentOption ("use_fancyapps") == 1) {
|
|
|
|
$(".fancydetail").click(function(event){
|
|
|
|
event.preventDefault();
|
2013-06-20 15:34:10 +03:00
|
|
|
before = new Date ();
|
2013-06-16 23:01:13 +03:00
|
|
|
var url = $(this).attr("href");
|
2013-06-17 22:41:59 +03:00
|
|
|
var jsonurl = url.replace ("index", "getJSON");
|
2013-06-16 23:01:13 +03:00
|
|
|
$.getJSON(jsonurl, function(data) {
|
2013-06-17 22:21:52 +03:00
|
|
|
data ["const"] = currentData ["const"];
|
2013-06-16 23:01:13 +03:00
|
|
|
var detail = templateBookDetail (data);
|
2013-06-25 09:53:38 +03:00
|
|
|
$.magnificPopup.open({
|
|
|
|
items: {
|
|
|
|
src: detail,
|
|
|
|
type: 'inline'
|
|
|
|
}
|
|
|
|
});
|
2013-06-20 15:34:10 +03:00
|
|
|
debug_log (elapsed ());
|
2013-06-15 17:09:37 +03:00
|
|
|
});
|
|
|
|
});
|
2013-06-16 23:01:13 +03:00
|
|
|
|
2013-06-25 09:53:38 +03:00
|
|
|
|
|
|
|
$('section').magnificPopup({
|
|
|
|
delegate: '.fancycover', // child items selector, by clicking on it popup will open
|
|
|
|
type: 'image',
|
|
|
|
gallery:{enabled:true, preload: [0,2]}
|
|
|
|
// other options
|
|
|
|
});
|
|
|
|
|
2013-06-16 23:01:13 +03:00
|
|
|
|
2013-06-25 09:53:38 +03:00
|
|
|
|
|
|
|
$('.fancyabout').magnificPopup({ type: 'ajax' });
|
2013-06-16 23:01:13 +03:00
|
|
|
}
|
2013-06-15 09:27:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxifyLinks () {
|
2013-06-20 15:43:31 +03:00
|
|
|
if (isPushStateEnabled) {
|
2013-06-17 22:41:59 +03:00
|
|
|
var links = $("a[href^='index']");
|
|
|
|
if (getCurrentOption ("use_fancyapps") == 1) links = links.not (".fancydetail");
|
|
|
|
links.click (function (event) {
|
2013-06-15 09:27:33 +03:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var url = $(this).attr('href');
|
|
|
|
navigateTo (url);
|
|
|
|
});
|
2013-06-20 15:43:31 +03:00
|
|
|
|
|
|
|
$("#searchForm").submit (function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var url = strformat ("index.php?page=9¤t={0}&query={1}&db={2}", currentData.page, $("input[name=query]").val (), currentData.databaseId);
|
|
|
|
navigateTo (url);
|
|
|
|
});
|
2013-06-15 09:27:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onpopstate = function(event) {
|
2013-06-20 15:34:10 +03:00
|
|
|
before = new Date ();
|
2013-06-20 22:08:50 +03:00
|
|
|
var data = cache.get (event.state)
|
|
|
|
updatePage (data);
|
2013-06-15 09:27:33 +03:00
|
|
|
};
|
|
|
|
|
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'));
|
|
|
|
}
|
|
|
|
});
|