mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
Disable offline page when IndexedDB isn't available
This commit is contained in:
parent
ba09a14ec0
commit
0b56ef1c02
4 changed files with 16 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -22,6 +22,11 @@ app.templates.bootError = ->
|
|||
""" 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. """
|
||||
|
||||
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 = """
|
||||
<div class="_fail">
|
||||
<h1 class="_fail-title">Your browser is unsupported, sorry.</h1>
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue