Merge pull request #70 from AdamQuadmon/cookieDomain

Added setCookieDomain option
revert-117-master
Gregory Pike 10 years ago
commit 72b1231295

@ -40,6 +40,11 @@ angularLocalStorage.provider('localStorageService', function(){
}; };
}; };
// Setter for cookie domain
this.setStorageCookieDomain = function(domain){
this.cookie.domain = domain;
};
// Setter for notification config // Setter for notification config
// itemSet & itemRemove should be booleans // itemSet & itemRemove should be booleans
this.setNotify = function(itemSet, itemRemove){ this.setNotify = function(itemSet, itemRemove){
@ -248,7 +253,8 @@ angularLocalStorage.provider('localStorageService', function(){
try { try {
var expiry = '', var expiry = '',
expiryDate = new Date(); expiryDate = new Date(),
cookieDomain = '';
if (value === null) { if (value === null) {
// Mark that the cookie has expired one day ago // Mark that the cookie has expired one day ago
@ -260,8 +266,12 @@ angularLocalStorage.provider('localStorageService', function(){
expiry = "; expires=" + expiryDate.toGMTString(); expiry = "; expires=" + expiryDate.toGMTString();
} }
if (!!key) { if (!!key) {
$document.cookie = prefix + key + "=" + encodeURIComponent(value) + expiry + "; path="+cookie.path; var cookiePath = "; path=" + cookie.path;
if(cookie.domain){
cookieDomain = "; domain=" + cookie.domain;
} }
$document.cookie = prefix + key + "=" + encodeURIComponent(value) + expiry + cookiePath + cookieDomain;
}
} catch (e) { } catch (e) {
$rootScope.$broadcast('LocalStorageModule.notification.error',e.message); $rootScope.$broadcast('LocalStorageModule.notification.error',e.message);
return false; return false;