From 2ff857c6b232cd31931d36f9ffba90a207c46c26 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Mon, 6 Aug 2012 23:08:07 +0200 Subject: [PATCH] Offline first http://natalian.org/archives/2012/07/16/navigator.onLine/ --- clean-up-locks.sh | 1 - create.cgi | 1 - grep.php | 16 ---------------- greptweet.appcache | 2 -- main.js | 25 +++++++------------------ 5 files changed, 7 insertions(+), 38 deletions(-) delete mode 100755 clean-up-locks.sh delete mode 100644 grep.php diff --git a/clean-up-locks.sh b/clean-up-locks.sh deleted file mode 100755 index 32dd0ed..0000000 --- a/clean-up-locks.sh +++ /dev/null @@ -1 +0,0 @@ -find $(dirname $0) -name lock | xargs rm -f diff --git a/create.cgi b/create.cgi index fc029cd..77b94ca 100755 --- a/create.cgi +++ b/create.cgi @@ -66,7 +66,6 @@ fi cd u/$id ln -sf ../../index.html || true -ln -sf ../../grep.php || true if echo $id | grep -q -v '_' # Underscores in domain names is a no no then diff --git a/grep.php b/grep.php deleted file mode 100644 index ab5e324..0000000 --- a/grep.php +++ /dev/null @@ -1,16 +0,0 @@ - diff --git a/greptweet.appcache b/greptweet.appcache index b0809f3..4ee33e2 100644 --- a/greptweet.appcache +++ b/greptweet.appcache @@ -8,5 +8,3 @@ tweets.txt /bootstrap/docs/assets/img/glyphicons-halflings.png /style.css /jquery-1.7.2.min.js -NETWORK: -grep.php diff --git a/main.js b/main.js index 094cd01..67852e9 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,5 @@ var l = []; // avoid expensive $.get for local searches + function search(query, lines) { var results = "

Searched for: " + query + "

    "; for (var i = 0; i < lines.length; i++) { @@ -21,27 +22,15 @@ function search(query, lines) { function grep(query) { - if (navigator.onLine) { - - $.getJSON("/u/" + NAME + "/grep.php?jsoncallback=?", { - q: query - }, - function(data) { - search(query, data); - }); - + if (l.length > 0) { + search(query, l); } else { - - if (l.length > 0) { + $.get('tweets.txt', function(data) { + l = data.split("\n"); search(query, l); - } else { - $.get('tweets.txt', function(data) { - l = data.split("\n"); - search(query, l); - }); - } - + }); } + } $(document).ready(function() {