appcache.coffee 977 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. @notifyProgress = true
  16. try @cache.update() catch
  17. return
  18. updateInBackground: ->
  19. @notifyUpdate = false
  20. @notifyProgress = false
  21. try @cache.update() catch
  22. return
  23. reload: ->
  24. $.on @cache, 'updateready noupdate error', -> window.location = '/'
  25. @updateInBackground()
  26. @notifyUpdate = false
  27. @notifyProgress = true
  28. @cache.update()
  29. return
  30. onProgress: (event) =>
  31. @trigger 'progress', event if @notifyProgress
  32. return
  33. onUpdateReady: =>
  34. @trigger 'updateready' if @notifyUpdate
  35. return