From 0b56ef1c026d8ae9d1b828a5c51f6ba78da719c7 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Thu, 1 Jan 2015 17:22:35 -0500 Subject: [PATCH] Disable offline page when IndexedDB isn't available --- assets/javascripts/app/db.coffee | 6 ++---- assets/javascripts/collections/docs.coffee | 5 +++-- assets/javascripts/templates/error_tmpl.coffee | 5 +++++ assets/javascripts/views/content/offline_page.coffee | 9 ++++++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/assets/javascripts/app/db.coffee b/assets/javascripts/app/db.coffee index 04bace5e..7892ec44 100644 --- a/assets/javascripts/app/db.coffee +++ b/assets/javascripts/app/db.coffee @@ -109,16 +109,14 @@ class app.DB versions: (docs, fn) -> @db (db) -> - result = {} - unless db - result[doc.slug] = false for doc in docs - fn(result) + fn(false) return txn = db.transaction ['docs'], 'readonly' txn.oncomplete = -> fn(result) store = txn.objectStore('docs') + result = {} docs.forEach (doc) -> req = store.get(doc.slug) diff --git a/assets/javascripts/collections/docs.coffee b/assets/javascripts/collections/docs.coffee index 42c5a2e0..4e19f6d6 100644 --- a/assets/javascripts/collections/docs.coffee +++ b/assets/javascripts/collections/docs.coffee @@ -37,6 +37,7 @@ class app.collections.Docs extends app.Collection getDownloadStatuses: (callback) -> app.db.versions @models, (statuses) -> - for key, value of statuses - statuses[key] = downloaded: !!value, version: value + if statuses + for key, value of statuses + statuses[key] = downloaded: !!value, version: value callback(statuses) diff --git a/assets/javascripts/templates/error_tmpl.coffee b/assets/javascripts/templates/error_tmpl.coffee index ce7ad5da..11941c03 100644 --- a/assets/javascripts/templates/error_tmpl.coffee +++ b/assets/javascripts/templates/error_tmpl.coffee @@ -22,6 +22,11 @@ app.templates.bootError = -> """ Check your Internet connection and try reloading.
If you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. """ +app.templates.offlineError = -> + error """ Your browser is unsupported, sorry. """, + """ DevDocs uses IndexedDB to cache complete documentations for offline access.
+ Unfortunately your browser either doesn't support IndexedDB, or its implementation is buggy. """ + app.templates.unsupportedBrowser = """

Your browser is unsupported, sorry.

diff --git a/assets/javascripts/views/content/offline_page.coffee b/assets/javascripts/views/content/offline_page.coffee index e374cab7..49243997 100644 --- a/assets/javascripts/views/content/offline_page.coffee +++ b/assets/javascripts/views/content/offline_page.coffee @@ -11,9 +11,12 @@ class app.views.OfflinePage extends app.View render: -> app.docs.getDownloadStatuses (statuses) => - html = '' - html += @renderDoc(doc, statuses[doc.slug]) for doc in app.docs.all() - @html @tmpl('offlinePage', html) + if statuses is false + @html @tmpl('offlineError') + else + html = '' + html += @renderDoc(doc, statuses[doc.slug]) for doc in app.docs.all() + @html @tmpl('offlinePage', html) return return