appcache.coffee 830 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. class app.AppCache
  2. $.extend @prototype, Events
  3. @isEnabled: ->
  4. try
  5. applicationCache and applicationCache.status isnt applicationCache.UNCACHED
  6. catch
  7. constructor: ->
  8. @cache = applicationCache
  9. @notifyUpdate = true
  10. @onUpdateReady() if @cache.status is @cache.UPDATEREADY
  11. $.on @cache, 'progress', @onProgress
  12. $.on @cache, 'updateready', @onUpdateReady
  13. update: ->
  14. @notifyUpdate = true
  15. try @cache.update() catch
  16. return
  17. updateInBackground: ->
  18. @notifyUpdate = false
  19. try @cache.update() catch
  20. return
  21. reload: ->
  22. $.on @cache, 'updateready noupdate error', -> window.location = '/'
  23. @updateInBackground()
  24. return
  25. onProgress: (event) =>
  26. @trigger 'progress', event
  27. return
  28. onUpdateReady: =>
  29. @trigger 'updateready' if @notifyUpdate
  30. return