mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
42 lines
961 B
CoffeeScript
42 lines
961 B
CoffeeScript
class app.AppCache
|
|
$.extend @prototype, Events
|
|
|
|
@isEnabled: ->
|
|
try
|
|
applicationCache and applicationCache.status isnt applicationCache.UNCACHED
|
|
catch
|
|
|
|
constructor: ->
|
|
@cache = applicationCache
|
|
@notifyUpdate = true
|
|
@onUpdateReady() if @cache.status is @cache.UPDATEREADY
|
|
|
|
$.on @cache, 'progress', @onProgress
|
|
$.on @cache, 'updateready', @onUpdateReady
|
|
|
|
update: ->
|
|
@notifyUpdate = true
|
|
@notifyProgress = true
|
|
try @cache.update() catch
|
|
return
|
|
|
|
updateInBackground: ->
|
|
@notifyUpdate = false
|
|
@notifyProgress = false
|
|
try @cache.update() catch
|
|
return
|
|
|
|
reload: ->
|
|
$.on @cache, 'updateready noupdate error', -> window.location = '/'
|
|
@notifyUpdate = false
|
|
@notifyProgress = true
|
|
try @cache.update() catch
|
|
return
|
|
|
|
onProgress: (event) =>
|
|
@trigger 'progress', event if @notifyProgress
|
|
return
|
|
|
|
onUpdateReady: =>
|
|
@trigger 'updateready' if @notifyUpdate
|
|
return
|