Fixed JS error from merge and changed spacing

revert-117-master
Gregory Pike 11 years ago
parent 3dee44cac3
commit 91271179e7

@ -65,6 +65,11 @@ angularLocalStorage.provider('localStorageService', function(){
}
};
// 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) {
// If this browser does not support local storage use cookies
if (!browserSupportsLocalStorage()) {
$rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED');
@ -97,6 +102,7 @@ angularLocalStorage.provider('localStorageService', function(){
// Directly get a value from local storage
// Example use: localStorageService.get('library'); // returns 'angular'
var getFromLocalStorage = function (key) {
if (!browserSupportsLocalStorage()) {
$rootScope.$broadcast('LocalStorageModule.notification.warning','LOCAL_STORAGE_NOT_SUPPORTED');
return getFromCookies(key);
@ -105,11 +111,14 @@ angularLocalStorage.provider('localStorageService', function(){
var item = localStorage.getItem(prefix + key);
// angular.toJson will convert null to 'null', so a proper conversion is needed
// FIXME not a perfect solution, since a valid 'null' string can't be stored
if (!item || item === 'null') {return null;}
if (!item || item === 'null') {
return null;
}
if (item.charAt(0) === "{" || item.charAt(0) === "[") {
return angular.fromJson(item);
}
return item;
};
@ -214,12 +223,13 @@ angularLocalStorage.provider('localStorageService', function(){
}
try {
var expiry = '', expiryDate = new Date();
var expiry = '',
expiryDate = new Date();
if (value === null) {
// Mark that the cookie has expired one day ago
expiryDate.setTime(expiryDate.getTime() + (-1 * 24 * 60 * 60 * 1000));
expiry = "; expires=" + expiryDate.toGMTString();
value = '';
} else if (cookie.expiry !== 0) {
expiryDate.setTime(expiryDate.getTime() + (cookie.expiry * 24 * 60 * 60 * 1000));
@ -266,9 +276,11 @@ angularLocalStorage.provider('localStorageService', function(){
var cookies = document.cookie.split(';');
for(var i = 0; i < cookies.length; i++) {
thisCookie = cookies[i];
while (thisCookie.charAt(0) === ' ') {
thisCookie = thisCookie.substring(1, thisCookie.length);
}
key = thisCookie.substring(prefixLength, thisCookie.indexOf('='));
removeFromCookies(key);
}