LP1837059 Angular local admin page
[Evergreen.git] / Open-ILS / web / upup.sw.min.js
1 //! UpUp Service Worker
2 //! version : 0.3.0
3 //! author  : Tal Ater @TalAter
4 //! license : MIT
5 //! https://github.com/TalAter/UpUp
6 var _CACHE_NAME_PREFIX="upup-cache",_calculateHash=function(a){a=a.toString();var b,c,d=0,e=a.length;if(0===e)return d;for(b=0;b<e;b++)c=a.charCodeAt(b),d=(d<<5)-d+c,d|=0;return d};self.addEventListener("message",function(a){"set-settings"===a.data.action&&_parseSettingsAndCache(a.data.settings)}),self.addEventListener("fetch",function(a){a.respondWith(fetch(a.request).catch(function(){return caches.match(a.request).then(function(b){return b||("navigate"===a.request.mode||"GET"===a.request.method&&a.request.headers.get("accept").includes("text/html")?caches.match("sw-offline-content"):void 0)})}))});var _parseSettingsAndCache=function(a){var b=_CACHE_NAME_PREFIX+"-"+(a["cache-version"]?a["cache-version"]+"-":"")+_calculateHash(a.content+a["content-url"]+a.assets);return caches.open(b).then(function(b){return a.assets&&b.addAll(a.assets.map(function(a){return new Request(a,{mode:"no-cors"})})),a["content-url"]?fetch(a["content-url"],{mode:"no-cors"}).then(function(a){return b.put("sw-offline-content",a)}):a.content?b.put("sw-offline-content",_buildResponse(a.content)):b.put("sw-offline-content",_buildResponse("You are offline"))}).then(function(){return caches.keys().then(function(a){return Promise.all(a.map(function(a){if(a.startsWith(_CACHE_NAME_PREFIX)&&b!==a)return caches.delete(a)}))})})},_buildResponse=function(a){return new Response(a,{headers:{"Content-Type":"text/html"}})};
7 //# sourceMappingURL=upup.sw.min.js.map