diff --git a/angular-local-storage.js b/angular-local-storage.js index cb7c126..5a7f9a4 100644 --- a/angular-local-storage.js +++ b/angular-local-storage.js @@ -52,10 +52,28 @@ } }; - // Directly adds a value to local storage - // If local storage is not available in the browser use cookies - // Example use: localStorageService.add('library','angular'); - var addToLocalStorage = function (key, value) { + // Checks the browser to see if local storage is supported + var browserSupportsLocalStorage = function () { + try { + var supported = ('localStorage' in window && window['localStorage'] !== null); + + // When Safari (OS X or iOS) is in private browsing mode, it appears as though localStorage + // is available, but trying to call .setItem throws an exception. + // + // "QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage + // that exceeded the quota." + var key = prefix + '__' + Math.round(Math.random() * 1e7); + if (supported) { + localStorage.setItem(key, ''); + localStorage.removeItem(key); + } + + return true; + } catch (e) { + $rootScope.$broadcast('LocalStorageModule.notification.error',e.message); + return false; + } + }; // If this browser does not support local storage use cookies if (!browserSupportsLocalStorage()) { diff --git a/bower.json b/bower.json index 337630e..cf45adc 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-local-storage", - "version": "0.0.1", + "version": "0.0.2", "homepage": "http://gregpike.net/demos/angular-local-storage/demo.html", "authors": [ "grevory " @@ -21,6 +21,6 @@ ], "devDependencies": { "angularjs": "*", - "angular-mocks": "~1.0.8" + "angular-mocks": "~1.2.1" } } diff --git a/package.json b/package.json index e065a85..86c5717 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-local-storage", - "version": "0.0.1", + "version": "0.0.2", "description": "An Angular module that gives you access to the browsers local storage", "main": "angular-local-storage.js", "scripts": {