From 3144c528e5bc10daf9aa43fab2d1ae9a18885b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Thu, 20 Jun 2013 14:43:31 +0200 Subject: [PATCH] Handle better if pushState is available or not. re #73 --- util.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/util.js b/util.js index 6860741..530e20e 100644 --- a/util.js +++ b/util.js @@ -2,6 +2,9 @@ var templatePage, templateBookDetail, templateMain, currentData, before; var DEBUG = true; var isEink = /Kobo|Kindle|EBRD1101/i.test(navigator.userAgent); +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)/); function debug_log(text) { if ( DEBUG ) { @@ -131,18 +134,10 @@ function updatePage (data) { $(".fancyabout").fancybox(fancyBoxObject ('COPS ' + currentData.version, 'ajax')); } - - $("#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); - }); - } function ajaxifyLinks () { - if (history.pushState) { + if (isPushStateEnabled) { var links = $("a[href^='index']"); if (getCurrentOption ("use_fancyapps") == 1) links = links.not (".fancydetail"); links.click (function (event) { @@ -151,6 +146,13 @@ function ajaxifyLinks () { var url = $(this).attr('href'); navigateTo (url); }); + + $("#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); + }); } }