Handle links better. re #73

This commit is contained in:
Sébastien Lucas 2013-07-16 21:56:55 +02:00
parent 948c1cb3fa
commit fb51523b33
5 changed files with 63 additions and 62 deletions

View file

@ -88,10 +88,8 @@
if ($currentPage->containsBook ()) { if ($currentPage->containsBook ()) {
$out ["containsBook"] = 1; $out ["containsBook"] = 1;
} }
$out["abouturl"] = "about.html";
if (getCurrentOption ('use_fancyapps') == 0) { $out["abouturl"] = "index.php" . addURLParameter ("?page=16", DB, $database);
$out["abouturl"] = "index.php" . addURLParameter ("?page=16", DB, $database);
}
if ($page == Base::PAGE_ABOUT) { if ($page == Base::PAGE_ABOUT) {
$out ["fullhtml"] = file_get_contents('about.html'); $out ["fullhtml"] = file_get_contents('about.html');

View file

@ -81,6 +81,7 @@
updatePage (data [0]); updatePage (data [0]);
cache.put (url, data [0]); cache.put (url, data [0]);
history.replaceState(url, "", window.location); history.replaceState(url, "", window.location);
handleLinks ();
}); });
}); });

View file

@ -104,8 +104,6 @@ border:0;
.container{ .container{
background: #414141; border:1px solid #000; border-radius:10px; background: #414141; border:1px solid #000; border-radius:10px;
max-width:800px;width:95%;margin:0 auto;position:relative; } max-width:800px;width:95%;margin:0 auto;position:relative; }
.fancyabout { font-weight:400; text-decoration: none; }
/* ============================================================================= /* =============================================================================
Header stuff goes here Header stuff goes here

View file

@ -112,8 +112,6 @@ border:0;
max-width:800px;width:95%;margin:0 auto;position:relative; max-width:800px;width:95%;margin:0 auto;position:relative;
background-color: white; background-color: white;
} }
.fancyabout { font-weight:400; text-decoration: none; }
/* ============================================================================= /* =============================================================================
Header stuff goes here Header stuff goes here

114
util.js
View file

@ -260,10 +260,12 @@ function updatePage (data) {
} else { } else {
$("#sortForm").hide (); $("#sortForm").hide ();
} }
}
if (currentData.page !== "19") { ajaxifyLinks (); }
function handleLinks () {
$("#sort").click(function(){ $("body").on ("click", "a[href^='index']", link_Clicked);
$("body").on ("submit", "#searchForm", search_Submitted);
$("body").on ("click", "#sort", function(){
$('.books').sortElements(function(a, b){ $('.books').sortElements(function(a, b){
var test = 1; var test = 1;
if ($("#sortorder").val() === "desc") if ($("#sortorder").val() === "desc")
@ -274,7 +276,7 @@ function updatePage (data) {
}); });
}); });
$(".headright").click(function(){ $("body").on ("click", ".headright", function(){
if ($("#tool").is(":hidden")) { if ($("#tool").is(":hidden")) {
$("#tool").slideDown("slow"); $("#tool").slideDown("slow");
$.cookie('toolbar', '1', { expires: 365 }); $.cookie('toolbar', '1', { expires: 365 });
@ -283,58 +285,62 @@ function updatePage (data) {
$.removeCookie('toolbar'); $.removeCookie('toolbar');
} }
}); });
$("body").magnificPopup({
if (getCurrentOption ("use_fancyapps") === "1") { delegate: '.fancycover', // child items selector, by clicking on it popup will open
$(".fancydetail").click(function(event){ type: 'image',
event.preventDefault(); gallery:{enabled:true, preload: [0,2]},
before = new Date (); disableOn: function() {
var url = $(this).attr("href"); if( getCurrentOption ("use_fancyapps") === "1" ) {
var jsonurl = url.replace ("index", "getJSON"); return true;
$.getJSON(jsonurl, function(data) { }
data ["const"] = currentData ["const"]; return false;
var detail = templateBookDetail (data); }
$.magnificPopup.open({ });
items: {
src: detail,
type: 'inline'
}
});
debug_log (elapsed ());
});
});
$('section').magnificPopup({
delegate: '.fancycover', // child items selector, by clicking on it popup will open
type: 'image',
gallery:{enabled:true, preload: [0,2]}
// other options
});
$('.fancyabout').magnificPopup({ type: 'ajax' });
}
} }
function ajaxifyLinks () { function link_Clicked (event) {
if (isPushStateEnabled) { var currentLink = $(this);
var links = $("a[href^='index']"); if (!isPushStateEnabled ||
if (getCurrentOption ("use_fancyapps") === "1") { links = links.not (".fancydetail"); } currentData.page === "19") {
links.click (function (event) { return;
event.preventDefault();
var url = $(this).attr('href');
navigateTo (url);
});
$("#searchForm").submit (function (event) {
event.preventDefault();
var url = strformat ("index.php?page=9&current={0}&query={1}&db={2}", currentData.page, $("input[name=query]").val (), currentData.databaseId);
navigateTo (url);
});
} }
event.preventDefault();
var url = currentLink.attr('href');
// The bookdetail / about should be displayed in a lightbox
if (getCurrentOption ("use_fancyapps") === "1" &&
(currentLink.hasClass ("fancydetail") || currentLink.hasClass ("fancyabout"))) {
before = new Date ();
var jsonurl = url.replace ("index", "getJSON");
$.getJSON(jsonurl, function(data) {
data ["const"] = currentData ["const"];
var detail = "";
if (data.page === "16") {
detail = data.fullhtml;
} else {
detail = templateBookDetail (data);
}
$.magnificPopup.open({
items: {
src: detail,
type: 'inline'
}
});
debug_log (elapsed ());
});
return;
}
navigateTo (url);
}
function search_Submitted (event) {
if (!isPushStateEnabled ||
currentData.page === "19") {
return;
}
event.preventDefault();
var url = strformat ("index.php?page=9&current={0}&query={1}&db={2}", currentData.page, $("input[name=query]").val (), currentData.databaseId);
navigateTo (url);
} }
window.onpopstate = function(event) { window.onpopstate = function(event) {