Disable offline page when IndexedDB isn't available

This commit is contained in:
Thibaut 2015-01-01 17:22:35 -05:00
parent ba09a14ec0
commit 0b56ef1c02
4 changed files with 16 additions and 9 deletions

View file

@ -109,16 +109,14 @@ class app.DB
versions: (docs, fn) -> versions: (docs, fn) ->
@db (db) -> @db (db) ->
result = {}
unless db unless db
result[doc.slug] = false for doc in docs fn(false)
fn(result)
return return
txn = db.transaction ['docs'], 'readonly' txn = db.transaction ['docs'], 'readonly'
txn.oncomplete = -> fn(result) txn.oncomplete = -> fn(result)
store = txn.objectStore('docs') store = txn.objectStore('docs')
result = {}
docs.forEach (doc) -> docs.forEach (doc) ->
req = store.get(doc.slug) req = store.get(doc.slug)

View file

@ -37,6 +37,7 @@ class app.collections.Docs extends app.Collection
getDownloadStatuses: (callback) -> getDownloadStatuses: (callback) ->
app.db.versions @models, (statuses) -> app.db.versions @models, (statuses) ->
for key, value of statuses if statuses
statuses[key] = downloaded: !!value, version: value for key, value of statuses
statuses[key] = downloaded: !!value, version: value
callback(statuses) callback(statuses)

View file

@ -22,6 +22,11 @@ app.templates.bootError = ->
""" Check your Internet connection and try <a href="javascript:location.reload()">reloading</a>.<br> """ Check your Internet connection and try <a href="javascript:location.reload()">reloading</a>.<br>
If you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. """ 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.<br>
Unfortunately your browser either doesn't support IndexedDB, or its implementation is buggy. """
app.templates.unsupportedBrowser = """ app.templates.unsupportedBrowser = """
<div class="_fail"> <div class="_fail">
<h1 class="_fail-title">Your browser is unsupported, sorry.</h1> <h1 class="_fail-title">Your browser is unsupported, sorry.</h1>

View file

@ -11,9 +11,12 @@ class app.views.OfflinePage extends app.View
render: -> render: ->
app.docs.getDownloadStatuses (statuses) => app.docs.getDownloadStatuses (statuses) =>
html = '' if statuses is false
html += @renderDoc(doc, statuses[doc.slug]) for doc in app.docs.all() @html @tmpl('offlineError')
@html @tmpl('offlinePage', html) else
html = ''
html += @renderDoc(doc, statuses[doc.slug]) for doc in app.docs.all()
@html @tmpl('offlinePage', html)
return return
return return