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

@ -105,8 +105,6 @@ border:0;
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

@ -113,8 +113,6 @@ border:0;
background-color: white; background-color: white;
} }
.fancyabout { font-weight:400; text-decoration: none; }
/* ============================================================================= /* =============================================================================
Header stuff goes here Header stuff goes here
========================================================================== */ ========================================================================== */

78
util.js
View file

@ -260,10 +260,12 @@ function updatePage (data) {
} else { } else {
$("#sortForm").hide (); $("#sortForm").hide ();
} }
}
if (currentData.page !== "19") { ajaxifyLinks (); } function handleLinks () {
$("body").on ("click", "a[href^='index']", link_Clicked);
$("#sort").click(function(){ $("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,16 +285,41 @@ function updatePage (data) {
$.removeCookie('toolbar'); $.removeCookie('toolbar');
} }
}); });
$("body").magnificPopup({
delegate: '.fancycover', // child items selector, by clicking on it popup will open
type: 'image',
gallery:{enabled:true, preload: [0,2]},
disableOn: function() {
if( getCurrentOption ("use_fancyapps") === "1" ) { if( getCurrentOption ("use_fancyapps") === "1" ) {
$(".fancydetail").click(function(event){ return true;
}
return false;
}
});
}
function link_Clicked (event) {
var currentLink = $(this);
if (!isPushStateEnabled ||
currentData.page === "19") {
return;
}
event.preventDefault(); 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 (); before = new Date ();
var url = $(this).attr("href");
var jsonurl = url.replace ("index", "getJSON"); var jsonurl = url.replace ("index", "getJSON");
$.getJSON(jsonurl, function(data) { $.getJSON(jsonurl, function(data) {
data ["const"] = currentData ["const"]; data ["const"] = currentData ["const"];
var detail = templateBookDetail (data); var detail = "";
if (data.page === "16") {
detail = data.fullhtml;
} else {
detail = templateBookDetail (data);
}
$.magnificPopup.open({ $.magnificPopup.open({
items: { items: {
src: detail, src: detail,
@ -301,40 +328,19 @@ function updatePage (data) {
}); });
debug_log (elapsed ()); debug_log (elapsed ());
}); });
}); return;
$('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 () {
if (isPushStateEnabled) {
var links = $("a[href^='index']");
if (getCurrentOption ("use_fancyapps") === "1") { links = links.not (".fancydetail"); }
links.click (function (event) {
event.preventDefault();
var url = $(this).attr('href');
navigateTo (url); navigateTo (url);
}); }
$("#searchForm").submit (function (event) { function search_Submitted (event) {
if (!isPushStateEnabled ||
currentData.page === "19") {
return;
}
event.preventDefault(); event.preventDefault();
var url = strformat ("index.php?page=9&current={0}&query={1}&db={2}", currentData.page, $("input[name=query]").val (), currentData.databaseId); var url = strformat ("index.php?page=9&current={0}&query={1}&db={2}", currentData.page, $("input[name=query]").val (), currentData.databaseId);
navigateTo (url); navigateTo (url);
});
}
} }
window.onpopstate = function(event) { window.onpopstate = function(event) {