From 24b6f4d1d670004702a0461eb736b7b49ac054b1 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Fri, 15 Aug 2014 19:46:09 +0300 Subject: [PATCH 1/8] refactor(src): create and remove src files to src dir --- angular-local-storage.min.js | 1 - angular-local-storage.js => src/angular-local-storage.js | 0 2 files changed, 1 deletion(-) delete mode 100644 angular-local-storage.min.js rename angular-local-storage.js => src/angular-local-storage.js (100%) diff --git a/angular-local-storage.min.js b/angular-local-storage.min.js deleted file mode 100644 index 0c66ac5..0000000 --- a/angular-local-storage.min.js +++ /dev/null @@ -1 +0,0 @@ -(function(){"use strict";var a=angular.module("LocalStorageModule",[]);a.provider("localStorageService",function(){this.prefix="ls",this.storageType="localStorage",this.cookie={expiry:30,path:"/"},this.notify={setItem:!0,removeItem:!1},this.setPrefix=function(a){this.prefix=a},this.setStorageType=function(a){this.storageType=a},this.setStorageCookie=function(a,b){this.cookie={expiry:a,path:b}},this.setStorageCookieDomain=function(a){this.cookie.domain=a},this.setNotify=function(a,b){this.notify={setItem:a,removeItem:b}},this.$get=["$rootScope","$window","$document",function(a,b,c){var d,e=this,f=e.prefix,g=e.cookie,h=e.notify,i=e.storageType;c?c[0]&&(c=c[0]):c=document,"."!==f.substr(-1)&&(f=f?f+".":"");var j=function(a){return f+a},k=function(){try{var c=i in b&&null!==b[i],e=j("__"+Math.round(1e7*Math.random()));return c&&(d=b[i],d.setItem(e,""),d.removeItem(e)),c}catch(f){return i="cookie",a.$broadcast("LocalStorageModule.notification.error",f.message),!1}}(),l=function(b,c){if(!k||"cookie"===e.storageType)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),h.setItem&&a.$broadcast("LocalStorageModule.notification.setitem",{key:b,newvalue:c,storageType:"cookie"}),r(b,c);"undefined"==typeof c&&(c=null);try{(angular.isObject(c)||angular.isArray(c))&&(c=angular.toJson(c)),d&&d.setItem(j(b),c),h.setItem&&a.$broadcast("LocalStorageModule.notification.setitem",{key:b,newvalue:c,storageType:e.storageType})}catch(f){return a.$broadcast("LocalStorageModule.notification.error",f.message),r(b,c)}return!0},m=function(b){if(!k||"cookie"===e.storageType)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),s(b);var c=d?d.getItem(j(b)):null;return c&&"null"!==c?"{"===c.charAt(0)||"["===c.charAt(0)?angular.fromJson(c):c:null},n=function(b){if(!k)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),h.removeItem&&a.$broadcast("LocalStorageModule.notification.removeitem",{key:b,storageType:"cookie"}),t(b);try{d.removeItem(j(b)),h.removeItem&&a.$broadcast("LocalStorageModule.notification.removeitem",{key:b,storageType:e.storageType})}catch(c){return a.$broadcast("LocalStorageModule.notification.error",c.message),t(b)}return!0},o=function(){if(!k)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),!1;var b=f.length,c=[];for(var e in d)if(e.substr(0,b)===f)try{c.push(e.substr(b))}catch(g){return a.$broadcast("LocalStorageModule.notification.error",g.Description),[]}return c},p=function(b){b=b||"";var c=f.slice(0,-1),e=new RegExp(c+"."+b);if(!k)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),u();var g=f.length;for(var h in d)if(e.test(h))try{n(h.substr(g))}catch(i){return a.$broadcast("LocalStorageModule.notification.error",i.message),u()}return!0},q=function(){try{return navigator.cookieEnabled||"cookie"in c&&(c.cookie.length>0||(c.cookie="test").indexOf.call(c.cookie,"test")>-1)}catch(b){return a.$broadcast("LocalStorageModule.notification.error",b.message),!1}},r=function(b,d){if("undefined"==typeof d)return!1;if(!q())return a.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;try{var e="",f=new Date,h="";if(null===d?(f.setTime(f.getTime()+-864e5),e="; expires="+f.toGMTString(),d=""):0!==g.expiry&&(f.setTime(f.getTime()+24*g.expiry*60*60*1e3),e="; expires="+f.toGMTString()),b){var i="; path="+g.path;g.domain&&(h="; domain="+g.domain),c.cookie=j(b)+"="+encodeURIComponent(d)+e+i+h}}catch(k){return a.$broadcast("LocalStorageModule.notification.error",k.message),!1}return!0},s=function(b){if(!q())return a.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;for(var d=c.cookie&&c.cookie.split(";")||[],e=0;e Date: Fri, 15 Aug 2014 19:48:04 +0300 Subject: [PATCH 2/8] fix(package): add grunt-concat --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 107de2f..8ea03ca 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "angular-local-storage", "version": "0.0.7", "description": "An Angular module that gives you access to the browsers local storage", + "homepage": "https://github.com/grevory/angular-local-storage", "main": "angular-local-storage.js", "scripts": { "test": "grunt test" @@ -26,7 +27,8 @@ "grunt-contrib-jshint": "~0.8.0", "grunt": "~0.4.2", "grunt-cli": "~0.1.9", - "grunt-contrib-uglify": "~0.3.2", + "grunt-contrib-uglify": "*", + "grunt-contrib-concat": "*", "karma": "~0.10", "grunt-karma": "~0.6.2", "karma-jasmine": "*" From 0c86054aba0e1170c284a0f7fadd09057ba92b60 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Fri, 15 Aug 2014 19:49:49 +0300 Subject: [PATCH 3/8] feat(gruntfile): robust gruntfile --- Gruntfile.js | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index a555bff..feb8df2 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -8,6 +8,41 @@ module.exports = function(grunt) { require('time-grunt')(grunt); grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + meta: { + banner: [ + '/**', + ' * <%= pkg.description %>', + ' * @version v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>', + ' * @link <%= pkg.homepage %>', + ' * @author <%= pkg.author %>', + ' * @license MIT License, http://www.opensource.org/licenses/MIT', + ' */' + ].join('\n') + }, + dirs: { + dest: 'dist' + }, + concat: { + options: { + banner: '<%= meta.banner %>' + '\n' + + '(function ( window, angular, undefined ) {' + '\n', + footer: '})( window, window.angular );' + }, + dist: { + src: ['src/*.js'], + dest: '<%= dirs.dest %>/<%= pkg.name %>.js' + } + }, + uglify: { + options: { + banner: '<%= meta.banner %>' + }, + dist: { + src: ['<%= concat.dist.dest %>'], + dest: '<%= dirs.dest %>/<%= pkg.name %>.min.js' + } + }, karma: { options: { autowatch: true, @@ -37,13 +72,6 @@ module.exports = function(grunt) { jshintrc: 'test/.jshintrc', } } - }, - uglify: { - dist: { - files: { - 'angular-local-storage.min.js': 'angular-local-storage.js' - } - } } }); @@ -57,6 +85,7 @@ module.exports = function(grunt) { ]); grunt.registerTask('dist', [ + 'concat', 'uglify' ]); }; From 38a769ea882762c9c2ca122719b3b268a741de16 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Fri, 15 Aug 2014 19:52:42 +0300 Subject: [PATCH 4/8] fix(karma.conf.js): update file src --- test/karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/karma.conf.js b/test/karma.conf.js index 0b29914..08ee9fb 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -28,7 +28,7 @@ module.exports = function(config) { files: [ bower + 'angular/angular.js', bower + 'angular-mocks/angular-mocks.js', - 'angular-local-storage.js', + 'src/angular-local-storage.js', 'test/spec/**/*.js' ], From 50fb50d58c955e1a07e2e8b07ad68f605f819483 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Fri, 15 Aug 2014 19:54:02 +0300 Subject: [PATCH 5/8] fix(demo.demo.html): update module path --- demo/demo.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/demo.html b/demo/demo.html index 6f6fb7b..54b5aa3 100644 --- a/demo/demo.html +++ b/demo/demo.html @@ -72,7 +72,7 @@
Dependencies:
JS Example
@@ -148,7 +148,7 @@ var YourCtrl = function($scope, localStorageService, ...) { - + From ea2065e51c3c26df993ac422c183e0b23d3e9958 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Fri, 15 Aug 2014 19:55:47 +0300 Subject: [PATCH 6/8] refactor(angular-local-storage): removes wrap closure to concat task --- src/angular-local-storage.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/angular-local-storage.js b/src/angular-local-storage.js index af4f8ce..cbe2a5e 100644 --- a/src/angular-local-storage.js +++ b/src/angular-local-storage.js @@ -1,5 +1,3 @@ -(function() { -/* Start angularLocalStorage */ 'use strict'; var angularLocalStorage = angular.module('LocalStorageModule', []); @@ -386,5 +384,3 @@ angularLocalStorage.provider('localStorageService', function() { }; }]; }); -}).call(this); - From b1b426698adfb8494f80c1daea4f0f0a1e45adda Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Fri, 15 Aug 2014 20:05:57 +0300 Subject: [PATCH 7/8] fix(dist): build for version v0.0.8 --- dist/angular-local-storage.js | 395 ++++++++++++++++++++++++++++++ dist/angular-local-storage.min.js | 7 + 2 files changed, 402 insertions(+) create mode 100644 dist/angular-local-storage.js create mode 100644 dist/angular-local-storage.min.js diff --git a/dist/angular-local-storage.js b/dist/angular-local-storage.js new file mode 100644 index 0000000..79e4ea3 --- /dev/null +++ b/dist/angular-local-storage.js @@ -0,0 +1,395 @@ +/** + * An Angular module that gives you access to the browsers local storage + * @version v0.0.8 - 2014-08-15 + * @link https://github.com/grevory/angular-local-storage + * @author grevory + * @license MIT License, http://www.opensource.org/licenses/MIT + */ +(function ( window, angular, undefined ) { +'use strict'; +var angularLocalStorage = angular.module('LocalStorageModule', []); + +angularLocalStorage.provider('localStorageService', function() { + + // You should set a prefix to avoid overwriting any local storage variables from the rest of your app + // e.g. localStorageServiceProvider.setPrefix('youAppName'); + // With provider you can use config as this: + // myApp.config(function (localStorageServiceProvider) { + // localStorageServiceProvider.prefix = 'yourAppName'; + // }); + this.prefix = 'ls'; + + // You could change web storage type localstorage or sessionStorage + this.storageType = 'localStorage'; + + // Cookie options (usually in case of fallback) + // expiry = Number of days before cookies expire // 0 = Does not expire + // path = The web path the cookie represents + this.cookie = { + expiry: 30, + path: '/' + }; + + // Send signals for each of the following actions? + this.notify = { + setItem: true, + removeItem: false + }; + + // Setter for the prefix + this.setPrefix = function(prefix) { + this.prefix = prefix; + }; + + // Setter for the storageType + this.setStorageType = function(storageType) { + this.storageType = storageType; + }; + + // Setter for cookie config + this.setStorageCookie = function(exp, path) { + this.cookie = { + expiry: exp, + path: path + }; + }; + + // Setter for cookie domain + this.setStorageCookieDomain = function(domain) { + this.cookie.domain = domain; + }; + + // Setter for notification config + // itemSet & itemRemove should be booleans + this.setNotify = function(itemSet, itemRemove) { + this.notify = { + setItem: itemSet, + removeItem: itemRemove + }; + }; + + + + this.$get = ['$rootScope', '$window', '$document', function($rootScope, $window, $document) { + var self = this; + var prefix = self.prefix; + var cookie = self.cookie; + var notify = self.notify; + var storageType = self.storageType; + var webStorage; + + // When Angular's $document is not available + if (!$document) { + $document = document; + } else if ($document[0]) { + $document = $document[0]; + } + + // If there is a prefix set in the config lets use that with an appended period for readability + if (prefix.substr(-1) !== '.') { + prefix = !!prefix ? prefix + '.' : ''; + } + var deriveQualifiedKey = function(key) { + return prefix + key; + } + // Checks the browser to see if local storage is supported + var browserSupportsLocalStorage = (function () { + try { + var supported = (storageType in $window && $window[storageType] !== 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 = deriveQualifiedKey('__' + Math.round(Math.random() * 1e7)); + if (supported) { + webStorage = $window[storageType]; + webStorage.setItem(key, ''); + webStorage.removeItem(key); + } + + return supported; + } catch (e) { + storageType = 'cookie'; + $rootScope.$broadcast('LocalStorageModule.notification.error', e.message); + return false; + } + }()); + + + + // 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 || self.storageType === 'cookie') { + $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); + if (notify.setItem) { + $rootScope.$broadcast('LocalStorageModule.notification.setitem', {key: key, newvalue: value, storageType: 'cookie'}); + } + return addToCookies(key, value); + } + + // Let's convert undefined values to null to get the value consistent + if (typeof value === "undefined") { + value = null; + } + + try { + if (angular.isObject(value) || angular.isArray(value)) { + value = angular.toJson(value); + } + if (webStorage) {webStorage.setItem(deriveQualifiedKey(key), value)}; + if (notify.setItem) { + $rootScope.$broadcast('LocalStorageModule.notification.setitem', {key: key, newvalue: value, storageType: self.storageType}); + } + } catch (e) { + $rootScope.$broadcast('LocalStorageModule.notification.error', e.message); + return addToCookies(key, value); + } + return true; + }; + + // Directly get a value from local storage + // Example use: localStorageService.get('library'); // returns 'angular' + var getFromLocalStorage = function (key) { + + if (!browserSupportsLocalStorage || self.storageType === 'cookie') { + $rootScope.$broadcast('LocalStorageModule.notification.warning','LOCAL_STORAGE_NOT_SUPPORTED'); + return getFromCookies(key); + } + + var item = webStorage ? webStorage.getItem(deriveQualifiedKey(key)) : null; + // 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.charAt(0) === "{" || item.charAt(0) === "[") { + return angular.fromJson(item); + } + + return item; + }; + + // Remove an item from local storage + // Example use: localStorageService.remove('library'); // removes the key/value pair of library='angular' + var removeFromLocalStorage = function (key) { + if (!browserSupportsLocalStorage) { + $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); + if (notify.removeItem) { + $rootScope.$broadcast('LocalStorageModule.notification.removeitem', {key: key, storageType: 'cookie'}); + } + return removeFromCookies(key); + } + + try { + webStorage.removeItem(deriveQualifiedKey(key)); + if (notify.removeItem) { + $rootScope.$broadcast('LocalStorageModule.notification.removeitem', {key: key, storageType: self.storageType}); + } + } catch (e) { + $rootScope.$broadcast('LocalStorageModule.notification.error', e.message); + return removeFromCookies(key); + } + return true; + }; + + // Return array of keys for local storage + // Example use: var keys = localStorageService.keys() + var getKeysForLocalStorage = function () { + + if (!browserSupportsLocalStorage) { + $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); + return false; + } + + var prefixLength = prefix.length; + var keys = []; + for (var key in webStorage) { + // Only return keys that are for this app + if (key.substr(0,prefixLength) === prefix) { + try { + keys.push(key.substr(prefixLength)); + } catch (e) { + $rootScope.$broadcast('LocalStorageModule.notification.error', e.Description); + return []; + } + } + } + return keys; + }; + + // Remove all data for this app from local storage + // Also optionally takes a regular expression string and removes the matching key-value pairs + // Example use: localStorageService.clearAll(); + // Should be used mostly for development purposes + var clearAllFromLocalStorage = function (regularExpression) { + + regularExpression = regularExpression || ""; + //accounting for the '.' in the prefix when creating a regex + var tempPrefix = prefix.slice(0, -1); + var testRegex = new RegExp(tempPrefix + '.' + regularExpression); + + if (!browserSupportsLocalStorage) { + $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); + return clearAllFromCookies(); + } + + var prefixLength = prefix.length; + + for (var key in webStorage) { + // Only remove items that are for this app and match the regular expression + if (testRegex.test(key)) { + try { + removeFromLocalStorage(key.substr(prefixLength)); + } catch (e) { + $rootScope.$broadcast('LocalStorageModule.notification.error',e.message); + return clearAllFromCookies(); + } + } + } + return true; + }; + + // Checks the browser to see if cookies are supported + var browserSupportsCookies = function() { + try { + return navigator.cookieEnabled || + ("cookie" in $document && ($document.cookie.length > 0 || + ($document.cookie = "test").indexOf.call($document.cookie, "test") > -1)); + } catch (e) { + $rootScope.$broadcast('LocalStorageModule.notification.error', e.message); + return false; + } + }; + + // Directly adds a value to cookies + // Typically used as a fallback is local storage is not available in the browser + // Example use: localStorageService.cookie.add('library','angular'); + var addToCookies = function (key, value) { + + if (typeof value === "undefined") { + return false; + } + + if (!browserSupportsCookies()) { + $rootScope.$broadcast('LocalStorageModule.notification.error', 'COOKIES_NOT_SUPPORTED'); + return false; + } + + try { + var expiry = '', + expiryDate = new Date(), + cookieDomain = ''; + + 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)); + expiry = "; expires=" + expiryDate.toGMTString(); + } + if (!!key) { + var cookiePath = "; path=" + cookie.path; + if(cookie.domain){ + cookieDomain = "; domain=" + cookie.domain; + } + $document.cookie = deriveQualifiedKey(key) + "=" + encodeURIComponent(value) + expiry + cookiePath + cookieDomain; + } + } catch (e) { + $rootScope.$broadcast('LocalStorageModule.notification.error',e.message); + return false; + } + return true; + }; + + // Directly get a value from a cookie + // Example use: localStorageService.cookie.get('library'); // returns 'angular' + var getFromCookies = function (key) { + if (!browserSupportsCookies()) { + $rootScope.$broadcast('LocalStorageModule.notification.error', 'COOKIES_NOT_SUPPORTED'); + return false; + } + + var cookies = $document.cookie && $document.cookie.split(';') || []; + for(var i=0; i < cookies.length; i++) { + var thisCookie = cookies[i]; + while (thisCookie.charAt(0) === ' ') { + thisCookie = thisCookie.substring(1,thisCookie.length); + } + if (thisCookie.indexOf(deriveQualifiedKey(key) + '=') === 0) { + return decodeURIComponent(thisCookie.substring(prefix.length + key.length + 1, thisCookie.length)); + } + } + return null; + }; + + var removeFromCookies = function (key) { + addToCookies(key,null); + }; + + var clearAllFromCookies = function () { + var thisCookie = null, thisKey = null; + var prefixLength = prefix.length; + 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); + } + + var key = thisCookie.substring(prefixLength, thisCookie.indexOf('=')); + removeFromCookies(key); + } + }; + + var getStorageType = function() { + return storageType; + }; + + var bindToScope = function(scope, key, def) { + var value = getFromLocalStorage(key); + + if (value === null && angular.isDefined(def)) { + value = def; + } else if (angular.isObject(value) && angular.isObject(def)) { + value = angular.extend(def, value); + } + + scope[key] = value; + + scope.$watchCollection(key, function(newVal) { + addToLocalStorage(key, newVal); + }); + }; + + return { + isSupported: browserSupportsLocalStorage, + getStorageType: getStorageType, + set: addToLocalStorage, + add: addToLocalStorage, //DEPRECATED + get: getFromLocalStorage, + keys: getKeysForLocalStorage, + remove: removeFromLocalStorage, + clearAll: clearAllFromLocalStorage, + bind: bindToScope, + deriveKey: deriveQualifiedKey, + cookie: { + set: addToCookies, + add: addToCookies, //DEPRECATED + get: getFromCookies, + remove: removeFromCookies, + clearAll: clearAllFromCookies + } + }; + }]; +}); +})( window, window.angular ); \ No newline at end of file diff --git a/dist/angular-local-storage.min.js b/dist/angular-local-storage.min.js new file mode 100644 index 0000000..4672c1f --- /dev/null +++ b/dist/angular-local-storage.min.js @@ -0,0 +1,7 @@ +/** + * An Angular module that gives you access to the browsers local storage + * @version v0.0.8 - 2014-08-15 + * @link https://github.com/grevory/angular-local-storage + * @author grevory + * @license MIT License, http://www.opensource.org/licenses/MIT + */!function(a,b){"use strict";var c=b.module("LocalStorageModule",[]);c.provider("localStorageService",function(){this.prefix="ls",this.storageType="localStorage",this.cookie={expiry:30,path:"/"},this.notify={setItem:!0,removeItem:!1},this.setPrefix=function(a){this.prefix=a},this.setStorageType=function(a){this.storageType=a},this.setStorageCookie=function(a,b){this.cookie={expiry:a,path:b}},this.setStorageCookieDomain=function(a){this.cookie.domain=a},this.setNotify=function(a,b){this.notify={setItem:a,removeItem:b}},this.$get=["$rootScope","$window","$document",function(a,c,d){var e,f=this,g=f.prefix,h=f.cookie,i=f.notify,j=f.storageType;d?d[0]&&(d=d[0]):d=document,"."!==g.substr(-1)&&(g=g?g+".":"");var k=function(a){return g+a},l=function(){try{var b=j in c&&null!==c[j],d=k("__"+Math.round(1e7*Math.random()));return b&&(e=c[j],e.setItem(d,""),e.removeItem(d)),b}catch(f){return j="cookie",a.$broadcast("LocalStorageModule.notification.error",f.message),!1}}(),m=function(c,d){if(!l||"cookie"===f.storageType)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),i.setItem&&a.$broadcast("LocalStorageModule.notification.setitem",{key:c,newvalue:d,storageType:"cookie"}),s(c,d);"undefined"==typeof d&&(d=null);try{(b.isObject(d)||b.isArray(d))&&(d=b.toJson(d)),e&&e.setItem(k(c),d),i.setItem&&a.$broadcast("LocalStorageModule.notification.setitem",{key:c,newvalue:d,storageType:f.storageType})}catch(g){return a.$broadcast("LocalStorageModule.notification.error",g.message),s(c,d)}return!0},n=function(c){if(!l||"cookie"===f.storageType)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),t(c);var d=e?e.getItem(k(c)):null;return d&&"null"!==d?"{"===d.charAt(0)||"["===d.charAt(0)?b.fromJson(d):d:null},o=function(b){if(!l)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),i.removeItem&&a.$broadcast("LocalStorageModule.notification.removeitem",{key:b,storageType:"cookie"}),u(b);try{e.removeItem(k(b)),i.removeItem&&a.$broadcast("LocalStorageModule.notification.removeitem",{key:b,storageType:f.storageType})}catch(c){return a.$broadcast("LocalStorageModule.notification.error",c.message),u(b)}return!0},p=function(){if(!l)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),!1;var b=g.length,c=[];for(var d in e)if(d.substr(0,b)===g)try{c.push(d.substr(b))}catch(f){return a.$broadcast("LocalStorageModule.notification.error",f.Description),[]}return c},q=function(b){b=b||"";var c=g.slice(0,-1),d=new RegExp(c+"."+b);if(!l)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),v();var f=g.length;for(var h in e)if(d.test(h))try{o(h.substr(f))}catch(i){return a.$broadcast("LocalStorageModule.notification.error",i.message),v()}return!0},r=function(){try{return navigator.cookieEnabled||"cookie"in d&&(d.cookie.length>0||(d.cookie="test").indexOf.call(d.cookie,"test")>-1)}catch(b){return a.$broadcast("LocalStorageModule.notification.error",b.message),!1}},s=function(b,c){if("undefined"==typeof c)return!1;if(!r())return a.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;try{var e="",f=new Date,g="";if(null===c?(f.setTime(f.getTime()+-864e5),e="; expires="+f.toGMTString(),c=""):0!==h.expiry&&(f.setTime(f.getTime()+24*h.expiry*60*60*1e3),e="; expires="+f.toGMTString()),b){var i="; path="+h.path;h.domain&&(g="; domain="+h.domain),d.cookie=k(b)+"="+encodeURIComponent(c)+e+i+g}}catch(j){return a.$broadcast("LocalStorageModule.notification.error",j.message),!1}return!0},t=function(b){if(!r())return a.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;for(var c=d.cookie&&d.cookie.split(";")||[],e=0;e Date: Fri, 15 Aug 2014 20:06:45 +0300 Subject: [PATCH 8/8] fix(bower,package): update version --- bower.json | 7 ++++--- package.json | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bower.json b/bower.json index 4ae53d9..0eb443f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-local-storage", - "version": "0.0.7", + "version": "0.0.8", "homepage": "http://gregpike.net/demos/angular-local-storage/demo.html", "authors": [ "grevory " @@ -17,11 +17,12 @@ ], "license": "MIT", "ignore": [ - "**/.*", + "src", "node_modules", "bower_components", "test", - "tests" + "tests", + "Gruntfile.js" ], "devDependencies": { "angularjs": "*", diff --git a/package.json b/package.json index 8ea03ca..7130386 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-local-storage", - "version": "0.0.7", + "version": "0.0.8", "description": "An Angular module that gives you access to the browsers local storage", "homepage": "https://github.com/grevory/angular-local-storage", "main": "angular-local-storage.js",