cache_handler.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // OFFLINE CACHE DEBUGGING
  2. /*var cacheStatusValues=[];
  3. cacheStatusValues[0]='uncached';
  4. cacheStatusValues[1]='idle';
  5. cacheStatusValues[2]='checking';
  6. cacheStatusValues[3]='downloading';
  7. cacheStatusValues[4]='updateready';
  8. cacheStatusValues[5]='obsolete';
  9. var cache=window.applicationCache;
  10. cache.addEventListener('cached', logEvent, false);
  11. cache.addEventListener('checking', logEvent, false);
  12. cache.addEventListener('downloading', logEvent, false);
  13. cache.addEventListener('error', logEvent, false);
  14. cache.addEventListener('noupdate', logEvent, false);
  15. cache.addEventListener('obsolete', logEvent, false);
  16. cache.addEventListener('progress', logEvent, false);
  17. cache.addEventListener('updateready', logEvent, false);
  18. function logEvent(e)
  19. {
  20. var online, status, type, message;
  21. online=(navigator.onLine) ? 'yes' : 'no';
  22. status=cacheStatusValues[cache.status];
  23. type=e.type;
  24. message='online: '+online;
  25. message+=', event: '+type;
  26. message+=', status: '+status;
  27. if(type=='error' && navigator.onLine)
  28. message+=' (prolly a syntax error in manifest)';
  29. console.log(message);
  30. }
  31. window.applicationCache.addEventListener('updateready', function(){
  32. window.applicationCache.swapCache();
  33. console.log('swap cache has been called');
  34. }, false
  35. );
  36. //setInterval(function(){cache.update()}, 10000);*/
  37. // Check if a new cache is available on page load.
  38. window.addEventListener('load', function(e)
  39. {
  40. window.applicationCache.addEventListener('cached', function(e)
  41. {
  42. if(!isUserLogged)
  43. window.location.reload();
  44. else
  45. $('#cacheDialog').css('display','block');
  46. }, false);
  47. window.applicationCache.addEventListener('updateready', function(e)
  48. {
  49. if(!isUserLogged)
  50. window.location.reload();
  51. else
  52. $('#cacheDialog').css('display','block');
  53. }, false);
  54. window.applicationCache.addEventListener('obsolete', function(e)
  55. {
  56. if(!isUserLogged)
  57. window.location.reload();
  58. else
  59. $('#cacheDialog').css('display','block');
  60. }, false);
  61. window.applicationCache.addEventListener('noupdate', function(e)
  62. {
  63. if(!isUserLogged)
  64. {
  65. clearInterval(globalCacheUpdateInterval);
  66. globalCacheUpdateInterval=setInterval(function(){window.applicationCache.update();}, 300000);
  67. //$('#LoginPage .window').css('display', 'inline-block');
  68. }
  69. }, false);
  70. }, false);