diff --git a/src/bower_components/apiclient/appStorage.js b/src/bower_components/apiclient/appStorage.js new file mode 100644 index 0000000000..a67ad5f559 --- /dev/null +++ b/src/bower_components/apiclient/appStorage.js @@ -0,0 +1,52 @@ +define([], function() { + "use strict"; + + function onCachePutFail(e) { + console.log(e); + } + + function updateCache(instance) { + if (instance.cache) { + instance.cache.put("data", new Response(JSON.stringify(instance.localData))).catch(onCachePutFail); + } + } + + function onCacheOpened(result) { + this.cache = result; + this.localData = {}; + } + + function MyStore() { + + this.setItem = function(name, value) { + localStorage.setItem(name, value); + + if (this.localData && this.localData[name] !== value) { + this.localData[name] = value; + updateCache(this); + } + }; + + this.getItem = function(name) { + return localStorage.getItem(name); + }; + + this.removeItem = function(name) { + localStorage.removeItem(name); + + if (this.localData) { + this.localData[name] = null; + delete this.localData[name]; + updateCache(this); + } + }; + + try { + self.caches && caches.open("embydata").then(onCacheOpened.bind(this)); + } catch (err) { + console.log("Error opening cache: " + err); + } + } + + return new MyStore; +}); \ No newline at end of file diff --git a/src/bower_components/apiclient/appstorage-cache.js b/src/bower_components/apiclient/appstorage-cache.js deleted file mode 100644 index 1f584f2a2b..0000000000 --- a/src/bower_components/apiclient/appstorage-cache.js +++ /dev/null @@ -1,23 +0,0 @@ -define([], function() { - "use strict"; - - function MyStore() {} - - function updateCache(instance) { - instance.cache.put("data", new Response(JSON.stringify(instance.localData))) - } - return MyStore.prototype.init = function() { - var instance = this; - return caches.open("embydata").then(function(result) { - instance.cache = result, instance.localData = {} - }) - }, MyStore.prototype.setItem = function(name, value) { - if (this.localData) { - this.localData[name] !== value && (this.localData[name] = value, updateCache(this)) - } - }, MyStore.prototype.getItem = function(name) { - if (this.localData) return this.localData[name] - }, MyStore.prototype.removeItem = function(name) { - this.localData && (this.localData[name] = null, delete this.localData[name], updateCache(this)) - }, new MyStore -}); \ No newline at end of file diff --git a/src/bower_components/apiclient/appstorage-localstorage.js b/src/bower_components/apiclient/appstorage-localstorage.js deleted file mode 100644 index 4baa82618e..0000000000 --- a/src/bower_components/apiclient/appstorage-localstorage.js +++ /dev/null @@ -1,37 +0,0 @@ -define([], function() { - "use strict"; - - function onCachePutFail(e) { - console.log(e) - } - - function updateCache(instance) { - var cache = instance.cache; - cache && cache.put("data", new Response(JSON.stringify(instance.localData))).catch(onCachePutFail) - } - - function onCacheOpened(result) { - this.cache = result, this.localData = {} - } - - function MyStore() { - try { - self.caches && caches.open("embydata").then(onCacheOpened.bind(this)) - } catch (err) { - console.log("Error opening cache: " + err) - } - } - return MyStore.prototype.setItem = function(name, value) { - localStorage.setItem(name, value); - var localData = this.localData; - if (localData) { - localData[name] !== value && (localData[name] = value, updateCache(this)) - } - }, MyStore.prototype.getItem = function(name) { - return localStorage.getItem(name) - }, MyStore.prototype.removeItem = function(name) { - localStorage.removeItem(name); - var localData = this.localData; - localData && (localData[name] = null, delete localData[name], updateCache(this)) - }, new MyStore -}); \ No newline at end of file diff --git a/src/bower_components/apiclient/appstorage-memory.js b/src/bower_components/apiclient/appstorage-memory.js deleted file mode 100644 index 75aab19923..0000000000 --- a/src/bower_components/apiclient/appstorage-memory.js +++ /dev/null @@ -1,14 +0,0 @@ -define([], function() { - "use strict"; - - function MyStore() { - this.localData = {} - } - return MyStore.prototype.setItem = function(name, value) { - this.localData[name] = value - }, MyStore.prototype.getItem = function(name) { - return this.localData[name] - }, MyStore.prototype.removeItem = function(name) { - this.localData[name] = null - }, new MyStore -}); \ No newline at end of file diff --git a/src/scripts/site.js b/src/scripts/site.js index 58d242dc94..d960ccb40d 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -357,16 +357,6 @@ var AppInfo = {}; return layoutManager; } - function getAppStorage(basePath) { - try { - localStorage.setItem("_test", "0"); - localStorage.removeItem("_test"); - return basePath + "/appstorage-localstorage"; - } catch (e) { - return basePath + "/appstorage-memory"; - } - } - function createWindowHeadroom(Headroom) { var headroom = new Headroom([], {}); headroom.init(); @@ -858,7 +848,7 @@ var AppInfo = {}; }); paths.apphost = "components/apphost"; - paths.appStorage = getAppStorage(apiClientBowerPath); + define('appStorage', [apiClientBowerPath + '/appStorage'], returnFirstDependency); requirejs.config({ waitSeconds: 0,