{"version":3,"sources":["swx-session-storage.js"],"names":["angular","$sessionStorage","$window","$location","$cacheFactory","webStorage","prefix","host","substring","indexOf","oneMinute","isSessionStorageAvailable","cache","service","this","val","destroy","put","key","value","dataToStore","data","arguments","length","isNumber","expires","Date","getTime","setItem","toJson","get","item","fromJson","getItem","remove","removeItem","empty","clear","removeAll","sessionStorage","Math","round","random","e","$inject","module","window"],"mappings":"CAAA,SAAUA,GAEN,YA8BA,SAASC,GAAgBC,EAASC,EAAWC,GAEzC,GAGIC,GAHAC,EAASH,EAAUI,OAAOC,UAAU,EAAGL,EAAUI,OAAOE,QAAQ,MAAQ,IACxEC,EAAY,IACZC,GAA4B,EAE5BC,EAAQR,EAAc,iBACtBS,EAAUC,IAmBdD,GAAQP,OAAS,SAASS,GACtBT,EAASS,EAAM,IACfH,EAAMI,UACNJ,EAAQR,EAAcE,EAAS,UAcnCO,EAAQI,IAAM,SAASC,EAAKC,GAExB,GAAIC,IAAgBC,KAAMF,EAY1B,OAVIG,WAAUC,OAAS,GAAKvB,EAAQwB,SAASF,UAAU,MACnDF,EAAYK,SAAU,GAAIC,OAAOC,UAAaL,UAAU,GAAKZ,GAGjEE,EAAMK,IAAIC,EAAKE,GAEXT,GACAN,EAAWuB,QAAQtB,EAASY,EAAKlB,EAAQ6B,OAAOT,GAAa,IAG1DD,GAaXN,EAAQiB,IAAM,SAASZ,GAEnB,GAAIa,EASJ,OAPInB,GAAMkB,IAAIZ,GACVa,EAAOnB,EAAMkB,IAAIZ,GAEZP,IACLoB,EAAO/B,EAAQgC,SAAS3B,EAAW4B,QAAQ3B,EAASY,KAGnDa,EAIDA,EAAKN,SAAWM,EAAKN,SAAU,GAAIC,OAAOC,cAC1Cd,GAAQqB,OAAOhB,IAInBN,EAAMK,IAAIC,EAAKa,GAERA,EAAKV,MAXZ,QAuBJR,EAAQqB,OAAS,SAAShB,GACtBL,EAAQI,IAAIC,EAAK,QACbP,GACAN,EAAW8B,WAAW7B,EAASY,GAEnCN,EAAMsB,OAAOhB,IAUjBL,EAAQuB,MAAQ,WACRzB,GACAN,EAAWgC,QAEfzB,EAAM0B,aAQV,WAGI,IACIjC,EAAaH,EAAQqC,cACrB,IAAIrB,GAAM,WAAasB,KAAKC,MAAsB,IAAhBD,KAAKE,SACvCrC,GAAWuB,QAAQV,EAAK,QACxBb,EAAW8B,WAAWjB,GAE1B,MAAOyB,GACHhC,GAA4B,MA9IxCV,EAAgB2C,SAAW,UAAW,YAAa,iBA6JnD5C,EACK6C,OAAO,wBACPhC,QAAQ,kBAAmBZ,IAEjC6C,OAAO9C","file":"swx-session-storage.min.js","sourcesContent":["(function(angular) {\n\n 'use strict';\n\n /**\n * @ngdoc service\n * @name $sessionStorage\n *\n * @requires $window\n * @requires $location\n * @requires $cacheFactory\n *\n * @description Provides a key-value (string-object) session storage with expiry option (in minutes).\n *\n * @param {service} $window The $window service.\n * @param {service} $location The $location service.\n * @param {service} $cacheFactory The $cacheFactory service.\n *\n * @example\n * ```js\n * myApp.$inject = ['$sessionStorage'];\n * function myApp($sessionStorage) {\n * // Your app code...\n * }\n *\n * angular\n * .module('myApp', ['swxSessionStorage']);\n * ```\n *\n * @ngInject\n */\n $sessionStorage.$inject = ['$window', '$location', '$cacheFactory'];\n function $sessionStorage($window, $location, $cacheFactory) {\n\n var prefix = $location.host().substring(0, $location.host().indexOf('.')) + '_',\n oneMinute = 60 * 1000,\n isSessionStorageAvailable = true,\n webStorage,\n cache = $cacheFactory('session-cache'),\n service = this;\n\n /**\n * @ngdoc method\n * @name $sessionStorage.prefix\n * @methodOf $sessionStorage\n *\n * @description\n * Overrides the default domain prefix.\n *\n * N.B. Destroys the existing cache.\n *\n * @param {string} val The string to add to the persistent data prefix.\n *\n * @example\n * ```js\n * $sessionStorage.prefix('myPrefix');\n * ```\n */\n service.prefix = function(val) {\n prefix = val + '_';\n cache.destroy();\n cache = $cacheFactory(prefix + 'cache');\n };\n\n /**\n * @ngdoc function\n * @name $sessionStorage.put\n * @methodOf $sessionStorage\n *\n * @description Add data to storage\n *\n * @param {string} key The key to store the data with.\n * @param {*} value The data to store.\n * [@param {number} expires] (expiry in minutes)\n */\n service.put = function(key, value) {\n\n var dataToStore = { data: value };\n\n if (arguments.length > 2 && angular.isNumber(arguments[2])) {\n dataToStore.expires = new Date().getTime() + (arguments[2] * oneMinute);\n }\n\n cache.put(key, dataToStore);\n\n if (isSessionStorageAvailable) {\n webStorage.setItem(prefix + key, angular.toJson(dataToStore, false));\n }\n\n return value;\n };\n\n /**\n * @ngdoc function\n * @name $sessionStorage.get\n * @methodOf $sessionStorage\n *\n * @description Get data from storage, will return from session cache if possible for greater performance.\n *\n * @param {String} key The key of the stored data to retrieve.\n * @returns {*} The value of the stored data or undefined.\n */\n service.get = function(key) {\n\n var item;\n\n if (cache.get(key)) {\n item = cache.get(key);\n }\n else if (isSessionStorageAvailable) {\n item = angular.fromJson(webStorage.getItem(prefix + key));\n }\n\n if (!item) {\n return void 0;\n }\n\n if (item.expires && item.expires < new Date().getTime()) {\n service.remove(key);\n return void 0;\n }\n\n cache.put(key, item);\n\n return item.data;\n };\n\n /**\n * @ngdoc function\n * @name $sessionStorage.remove\n * @methodOf $sessionStorage\n *\n * @descriotion Remove data from storage.\n *\n * @param {String} key The key of the stored data to remove.\n */\n service.remove = function(key) {\n service.put(key, void 0);\n if (isSessionStorageAvailable) {\n webStorage.removeItem(prefix + key);\n }\n cache.remove(key);\n };\n\n /**\n * @ngdoc function\n * @name $sessionStorage.empty\n * @methodOf $sessionStorage\n *\n * @description Delete all data from session storage and cookie.\n */\n service.empty = function() {\n if (isSessionStorageAvailable) {\n webStorage.clear();\n }\n cache.removeAll();\n };\n\n /**\n * @private\n * @description\n * Check for $window.localStorage availability and functionality\n */\n (function() {\n\n // Some browsers will return true when in private browsing mode so test to make sure it's functional.\n try {\n webStorage = $window.sessionStorage;\n var key = 'swxTest_' + Math.round(Math.random() * 1e7);\n webStorage.setItem(key, 'test');\n webStorage.removeItem(key);\n }\n catch (e) {\n isSessionStorageAvailable = false;\n }\n\n })();\n }\n\n /**\n * @ngdoc overview\n * @name swxSessionStorage\n *\n * @description\n * $sessionService service for use in your AngularJS applications.\n *\n * Provides a key-value (string-object) session storage with expiry option (in minutes).\n */\n angular\n .module('swxSessionStorage', [])\n .service('$sessionStorage', $sessionStorage);\n\n})(window.angular);"],"sourceRoot":"/source/"}