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 ()) {
$out ["containsBook"] = 1;
}
$out["abouturl"] = "about.html";
if (getCurrentOption ('use_fancyapps') == 0) {
$out["abouturl"] = "index.php" . addURLParameter ("?page=16", DB, $database);
}
if ($page == Base::PAGE_ABOUT) {
$out ["fullhtml"] = file_get_contents('about.html');

View file

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

View file

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

View file

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

78
util.js
View file

@ -260,10 +260,12 @@ function updatePage (data) {
} else {
$("#sortForm").hide ();
}
}
if (currentData.page !== "19") { ajaxifyLinks (); }
$("#sort").click(function(){
function handleLinks () {
$("body").on ("click", "a[href^='index']", link_Clicked);
$("body").on ("submit", "#searchForm", search_Submitted);
$("body").on ("click", "#sort", function(){
$('.books').sortElements(function(a, b){
var test = 1;
if ($("#sortorder").val() === "desc")
@ -274,7 +276,7 @@ function updatePage (data) {
});
});
$(".headright").click(function(){
$("body").on ("click", ".headright", function(){
if ($("#tool").is(":hidden")) {
$("#tool").slideDown("slow");
$.cookie('toolbar', '1', { expires: 365 });
@ -283,16 +285,41 @@ function updatePage (data) {
$.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" ) {
$(".fancydetail").click(function(event){
return true;
}
return false;
}
});
}
function link_Clicked (event) {
var currentLink = $(this);
if (!isPushStateEnabled ||
currentData.page === "19") {
return;
}
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 url = $(this).attr("href");
var jsonurl = url.replace ("index", "getJSON");
$.getJSON(jsonurl, function(data) {
data ["const"] = currentData ["const"];
var detail = templateBookDetail (data);
var detail = "";
if (data.page === "16") {
detail = data.fullhtml;
} else {
detail = templateBookDetail (data);
}
$.magnificPopup.open({
items: {
src: detail,
@ -301,40 +328,19 @@ function updatePage (data) {
});
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' });
return;
}
}
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);
});
}
$("#searchForm").submit (function (event) {
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) {