diff --git a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js
index 5321dfecba182..d50541504662d 100644
--- a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js
+++ b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js
@@ -78,7 +78,7 @@ define([
var parameters;
sectionNames = sectionConfig.filterClientSideSections(sectionNames);
- parameters = _.isArray(sectionNames) ? {
+ parameters = _.isArray(sectionNames) && sectionNames.indexOf('*') < 0 ? {
sections: sectionNames.join(',')
} : [];
parameters['force_new_section_timestamp'] = forceNewSectionTimestamp;
diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js
index 7063b846ed166..ae7c03dfd7792 100644
--- a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js
+++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js
@@ -3,30 +3,35 @@
* See COPYING.txt for license details.
*/
-/*eslint-disable max-nested-callbacks*/
-/*jscs:disable jsDoc*/
+/* global _ */
+/* eslint max-nested-callbacks: 0 */
+/* jscs:disable jsDoc*/
define([
+ 'squire',
'jquery',
- 'underscore',
'Magento_Customer/js/section-config',
- 'Magento_Customer/js/customer-data'
-], function (
- $,
- _,
- sectionConfig,
- customerData
-) {
+ 'Magento_Customer/js/customer-data',
+ 'jquery/jquery-storageapi'
+], function (Squire, $, sectionConfig, customerData) {
'use strict';
- var sectionConfigSettings = {
+ var injector = new Squire(),
+ obj,
+ originaljQuery,
+ originalGetJSON,
+ originalReload,
+ originalIsEmpty,
+ originalEach,
+ cookieLifeTime = 3600,
+ sectionConfigSettings = {
baseUrls: [
'http://localhost/'
],
sections: {
'customer/account/loginpost': ['*'],
'checkout/cart/add': ['cart'],
- 'rest/*/v1/guest-carts/*/selected-payment-method': ['cart','checkout-data'],
+ 'rest/*/v1/guest-carts/*/selected-payment-method': ['cart', 'checkout-data'],
'*': ['messages']
},
clientSideSections: [
@@ -39,9 +44,7 @@ define([
'cart',
'messages'
]
- },
- cookieLifeTime = 3600,
- jQueryGetJSON;
+ };
function init(config) {
var defaultConfig = {
@@ -95,75 +98,102 @@ define([
}
describe('Magento_Customer/js/customer-data', function () {
+
+ var _;
+
beforeAll(function () {
clearLocalStorage();
});
- beforeEach(function () {
- jQueryGetJSON = $.getJSON;
+ beforeEach(function (done) {
+ originalGetJSON = $.getJSON;
sectionConfig['Magento_Customer/js/section-config'](sectionConfigSettings);
+
+ injector.require([
+ 'underscore',
+ 'Magento_Customer/js/customer-data'
+ ], function (underscore, Constr) {
+ _ = underscore;
+ obj = Constr;
+ done();
+ });
});
afterEach(function () {
- $.getJSON = jQueryGetJSON;
- clearLocalStorage();
+ try {
+ $.getJSON = originalGetJSON;
+ clearLocalStorage();
+ injector.clean();
+ injector.remove();
+ } catch (e) {
+ }
});
- describe('getExpiredSectionNames()', function () {
- it('check that result contains expired section names', function () {
- setupLocalStorage({
- 'cart': {
- 'data_id': Math.floor(Date.now() / 1000) - 61 * 60, // 61 minutes ago
- 'content': {}
- }
- });
- init();
- expect(customerData.getExpiredSectionNames()).toEqual(['cart']);
+ describe('"init" method', function () {
+ var storageInvalidation = {
+ keys: function () {
+ return ['section'];
+ }
+ };
+
+ beforeEach(function () {
+ originalReload = obj.reload;
+ originalIsEmpty = _.isEmpty;
+
+ $.initNamespaceStorage('mage-cache-storage').localStorage;
+ $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;
+
+ spyOn(storageInvalidation, 'keys').and.returnValue(['section']);
});
- it('check that result doest not contain unexpired section names', function () {
- setupLocalStorage({
- 'cart': {
- 'data_id': Math.floor(Date.now() / 1000) + 60, // in 1 minute
- 'content': {}
- }
- });
- init();
- expect(customerData.getExpiredSectionNames()).toEqual([]);
+ afterEach(function () {
+ obj.reload = originalReload;
+ _.isEmpty = originalIsEmpty;
+ $.namespaceStorages = {};
});
- it('check that result contains invalidated section names', function () {
- setupLocalStorage({
- 'cart': { // without storage content
- 'data_id': Math.floor(Date.now() / 1000) + 60 // in 1 minute
- }
- });
+ it('Should be defined', function () {
+ expect(obj.hasOwnProperty('init')).toBeDefined();
+ });
- init();
- expect(customerData.getExpiredSectionNames()).toEqual(['cart']);
+ it('Does not throw before component is initialized', function () {
+ obj.initStorage();
+
+ expect(function () {
+ obj.init();
+ }).not.toThrow();
});
- it('check that result does not contain unsupported section names', function () {
- setupLocalStorage({
- 'catalog': { // without storage content
- 'data_id': Math.floor(Date.now() / 1000) + 60 // in 1 minute
- }
- });
+ it('Calls "getExpiredSectionNames" method', function () {
+ spyOn(obj, 'getExpiredSectionNames').and.returnValue([]);
+ obj.init();
+ expect(obj.getExpiredSectionNames).toHaveBeenCalled();
+ });
- init();
- expect(customerData.getExpiredSectionNames()).toEqual([]);
+ it('Calls "reload" method when expired sections exist', function () {
+ spyOn(obj, 'getExpiredSectionNames').and.returnValue(['section']);
+ spyOn(obj, 'reload').and.returnValue(true);
+ obj.init();
+ expect(obj.reload).toHaveBeenCalled();
});
- });
- describe('init()', function () {
- it('check that sections are not requested from server, if there are no expired sections', function () {
+ it('Calls "reload" method when expired sections do not exist', function () {
+ spyOn(obj, 'getExpiredSectionNames').and.returnValue([]);
+ spyOn(obj, 'reload').and.returnValue(true);
+ spyOn(_, 'isEmpty').and.returnValue(false);
+
+ obj.init();
+ expect(obj.reload).toHaveBeenCalled();
+ });
+
+ it('Check it does not request sections from the server if there are no expired sections', function () {
setupLocalStorage({
'catalog': { // without storage content
'data_id': Math.floor(Date.now() / 1000) + 60 // in 1 minute
}
});
- $.getJSON = jasmine.createSpy('$.getJSON').and.callFake(function () {
+ $.getJSON = jasmine.createSpy().and.callFake(function () {
var deferred = $.Deferred();
return deferred.promise();
@@ -172,7 +202,8 @@ define([
init();
expect($.getJSON).not.toHaveBeenCalled();
});
- it('check that sections are requested from server, if there are expired sections', function () {
+
+ it('Check it requests sections from the server if there are expired sections', function () {
setupLocalStorage({
'customer': {
'data_id': Math.floor(Date.now() / 1000) + 60 // invalidated,
@@ -209,5 +240,280 @@ define([
);
});
});
+
+ describe('"getExpiredSectionNames method', function () {
+ it('Should be defined', function () {
+ expect(obj.hasOwnProperty('getExpiredSectionNames')).toBeDefined();
+ });
+
+ it('Does not throw before component is initialized', function () {
+ expect(function () {
+ obj.getExpiredSectionNames();
+ }).not.toThrow();
+ });
+
+ it('Check that result contains expired section names', function () {
+ setupLocalStorage({
+ 'cart': {
+ 'data_id': Math.floor(Date.now() / 1000) - 61 * 60, // 61 minutes ago
+ 'content': {}
+ }
+ });
+
+ $.getJSON = jasmine.createSpy('$.getJSON').and.callFake(function () {
+ var deferred = $.Deferred();
+
+ return deferred.promise();
+ });
+
+ init();
+ expect(customerData.getExpiredSectionNames()).toEqual(['cart']);
+ });
+
+ it('Check that result does not contain unexpired section names', function () {
+ setupLocalStorage({
+ 'cart': {
+ 'data_id': Math.floor(Date.now() / 1000) + 60, // in 1 minute
+ 'content': {}
+ }
+ });
+ init();
+ expect(customerData.getExpiredSectionNames()).toEqual([]);
+ });
+
+ it('Check that result contains invalidated section names', function () {
+ setupLocalStorage({
+ 'cart': { // without storage content
+ 'data_id': Math.floor(Date.now() / 1000) + 60 // in 1 minute
+ }
+ });
+
+ $.getJSON = jasmine.createSpy('$.getJSON').and.callFake(function () {
+ var deferred = $.Deferred();
+
+ return deferred.promise();
+ });
+
+ init();
+ expect(customerData.getExpiredSectionNames()).toEqual(['cart']);
+ });
+
+ it('Check that result does not contain unsupported section names', function () {
+ setupLocalStorage({
+ 'catalog': { // without storage content
+ 'data_id': Math.floor(Date.now() / 1000) + 60 // in 1 minute
+ }
+ });
+
+ init();
+ expect(customerData.getExpiredSectionNames()).toEqual([]);
+ });
+ });
+
+ describe('"get" method', function () {
+ it('Should be defined', function () {
+ expect(obj.hasOwnProperty('get')).toBeDefined();
+ });
+
+ it('Does not throw before component is initialized', function () {
+ expect(function () {
+ obj.get();
+ }).not.toThrow();
+ });
+ });
+
+ describe('"set" method', function () {
+ beforeEach(function () {
+ originalEach = _.each;
+ });
+
+ afterEach(function () {
+ _.each = originalEach;
+ });
+
+ it('Should be defined', function () {
+ expect(obj.hasOwnProperty('set')).toBeDefined();
+ });
+
+ it('Does not throw before component is initialized', function () {
+ _.each = jasmine.createSpy().and.returnValue(true);
+
+ expect(function () {
+ obj.set();
+ }).not.toThrow();
+ });
+ });
+
+ describe('"reload" method', function () {
+ beforeEach(function () {
+ originaljQuery = $;
+ $ = jQuery;
+
+ $.getJSON = jasmine.createSpy().and.callFake(function () {
+ var deferred = $.Deferred();
+
+ /**
+ * Mock Done Method for getJSON
+ * @returns object
+ */
+ deferred.promise().done = function () {
+ return {
+ responseJSON: {
+ section: {}
+ }
+ };
+ };
+
+ return deferred.promise();
+ });
+ });
+
+ afterEach(function () {
+ $ = originaljQuery;
+ });
+
+ it('Should be defined', function () {
+ expect(obj.hasOwnProperty('reload')).toBeDefined();
+ });
+
+ it('Does not throw before component is initialized', function () {
+ expect(function () {
+ obj.reload();
+ }).not.toThrow();
+ });
+
+ it('Check it returns proper sections object when passed array with a single section name', function () {
+ var result;
+
+ spyOn(sectionConfig, 'filterClientSideSections').and.returnValue(['section']);
+
+ $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) {
+ var deferred = $.Deferred();
+
+ /**
+ * Mock Done Method for getJSON
+ * @returns object
+ */
+ deferred.promise().done = function () {
+ return {
+ responseJSON: {
+ section: {}
+ }
+ };
+ };
+
+ expect(parameters).toEqual(jasmine.objectContaining({
+ sections: 'section'
+ }));
+
+ return deferred.promise();
+ });
+
+ result = obj.reload(['section'], true);
+
+ expect(result).toEqual(jasmine.objectContaining({
+ responseJSON: {
+ section: {}
+ }
+ }));
+ });
+
+ it('Check it returns proper sections object when passed array with multiple section names', function () {
+ var result;
+
+ spyOn(sectionConfig, 'filterClientSideSections').and.returnValue(['cart,customer,messages']);
+
+ $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) {
+ var deferred = $.Deferred();
+
+ expect(parameters).toEqual(jasmine.objectContaining({
+ sections: 'cart,customer,messages'
+ }));
+
+ /**
+ * Mock Done Method for getJSON
+ * @returns object
+ */
+ deferred.promise().done = function () {
+ return {
+ responseJSON: {
+ cart: {},
+ customer: {},
+ messages: {}
+ }
+ };
+ };
+
+ return deferred.promise();
+ });
+
+ result = obj.reload(['cart', 'customer', 'messages'], true);
+
+ expect(result).toEqual(jasmine.objectContaining({
+ responseJSON: {
+ cart: {},
+ customer: {},
+ messages: {}
+ }
+ }));
+ });
+ //
+ it('Check it returns all sections when passed wildcard string', function () {
+ var result;
+
+ $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) {
+ var deferred = $.Deferred();
+
+ expect(parameters).toEqual(jasmine.objectContaining({
+ 'force_new_section_timestamp': true
+ }));
+
+ /**
+ * Mock Done Method for getJSON
+ * @returns object
+ */
+ deferred.promise().done = function () {
+ return {
+ responseJSON: {
+ cart: {},
+ customer: {},
+ messages: {}
+ }
+ };
+ };
+
+ return deferred.promise();
+ });
+
+ result = obj.reload('*', true);
+
+ expect($.getJSON).toHaveBeenCalled();
+ expect(result).toEqual(jasmine.objectContaining({
+ responseJSON: {
+ cart: {},
+ customer: {},
+ messages: {}
+ }
+ }));
+ });
+ });
+
+ describe('"invalidated" method', function () {
+ it('Should be defined', function () {
+ expect(obj.hasOwnProperty('invalidate')).toBeDefined();
+ });
+
+ it('Does not throw before component is initialized', function () {
+ expect(function () {
+ obj.invalidate();
+ }).not.toThrow();
+ });
+ });
+
+ describe('"Magento_Customer/js/customer-data" method', function () {
+ it('Should be defined', function () {
+ expect(obj.hasOwnProperty('Magento_Customer/js/customer-data')).toBeDefined();
+ });
+ });
});
});
diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Multishipping/frontend/js/multi-shipping.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Multishipping/frontend/js/multi-shipping.test.js
index 65ee180476f3a..a8ae8ab65e378 100644
--- a/dev/tests/js/jasmine/tests/app/code/Magento/Multishipping/frontend/js/multi-shipping.test.js
+++ b/dev/tests/js/jasmine/tests/app/code/Magento/Multishipping/frontend/js/multi-shipping.test.js
@@ -68,9 +68,11 @@ define([
var addNewAddressBtn,
addressflag,
canContinueBtn,
- canContinueFlag;
+ canContinueFlag,
+ originalGetJSON;
beforeEach(function () {
+ originalGetJSON = $.getJSON;
addNewAddressBtn = $('');
addressflag = $('');
canContinueBtn = $('');
@@ -79,6 +81,12 @@ define([
.append(addressflag)
.append(canContinueBtn)
.append(canContinueFlag);
+
+ $.getJSON = jasmine.createSpy().and.callFake(function () {
+ var deferred = $.Deferred();
+
+ return deferred.promise();
+ });
});
afterEach(function () {
@@ -86,6 +94,7 @@ define([
addressflag.remove();
canContinueBtn.remove();
canContinueFlag.remove();
+ $.getJSON = originalGetJSON;
});
it('Check add new address event', function () {
diff --git a/lib/web/jquery/jquery.storageapi.min.js b/lib/web/jquery/jquery.storageapi.min.js
index 886c3d847ed3b..fcf296a384bce 100644
--- a/lib/web/jquery/jquery.storageapi.min.js
+++ b/lib/web/jquery/jquery.storageapi.min.js
@@ -1,2 +1,2 @@
/* jQuery Storage API Plugin 1.7.3 https://github.com/julien-maurel/jQuery-Storage-API */
-!function(e){"function"==typeof define&&define.amd?define(["jquery", "jquery/jquery.cookie"],e):e("object"==typeof exports?require("jquery"):jQuery)}(function(e){function t(t){var r,i,n,o=arguments.length,s=window[t],a=arguments,u=a[1];if(2>o)throw Error("Minimum 2 arguments must be given");if(e.isArray(u)){i={};for(var f in u){r=u[f];try{i[r]=JSON.parse(s.getItem(r))}catch(c){i[r]=s.getItem(r)}}return i}if(2!=o){try{i=JSON.parse(s.getItem(u))}catch(c){throw new ReferenceError(u+" is not defined in this storage")}for(var f=2;o-1>f;f++)if(i=i[a[f]],void 0===i)throw new ReferenceError([].slice.call(a,1,f+1).join(".")+" is not defined in this storage");if(e.isArray(a[f])){n=i,i={};for(var m in a[f])i[a[f][m]]=n[a[f][m]];return i}return i[a[f]]}try{return JSON.parse(s.getItem(u))}catch(c){return s.getItem(u)}}function r(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1],u=s[2],f={};if(2>n||!e.isPlainObject(a)&&3>n)throw Error("Minimum 3 arguments must be given or second parameter must be an object");if(e.isPlainObject(a)){for(var c in a)r=a[c],e.isPlainObject(r)?o.setItem(c,JSON.stringify(r)):o.setItem(c,r);return a}if(3==n)return"object"==typeof u?o.setItem(a,JSON.stringify(u)):o.setItem(a,u),u;try{i=o.getItem(a),null!=i&&(f=JSON.parse(i))}catch(m){}i=f;for(var c=2;n-2>c;c++)r=s[c],i[r]&&e.isPlainObject(i[r])||(i[r]={}),i=i[r];return i[s[c]]=s[c+1],o.setItem(a,JSON.stringify(f)),f}function i(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1];if(2>n)throw Error("Minimum 2 arguments must be given");if(e.isArray(a)){for(var u in a)o.removeItem(a[u]);return!0}if(2==n)return o.removeItem(a),!0;try{r=i=JSON.parse(o.getItem(a))}catch(f){throw new ReferenceError(a+" is not defined in this storage")}for(var u=2;n-1>u;u++)if(i=i[s[u]],void 0===i)throw new ReferenceError([].slice.call(s,1,u).join(".")+" is not defined in this storage");if(e.isArray(s[u]))for(var c in s[u])delete i[s[u][c]];else delete i[s[u]];return o.setItem(a,JSON.stringify(r)),!0}function n(t,r){var n=a(t);for(var o in n)i(t,n[o]);if(r)for(var o in e.namespaceStorages)u(o)}function o(r){var i=arguments.length,n=arguments,s=(window[r],n[1]);if(1==i)return 0==a(r).length;if(e.isArray(s)){for(var u=0;ui)throw Error("Minimum 2 arguments must be given");if(e.isArray(o)){for(var a=0;a1?t.apply(this,o):n,a._cookie)for(var u in e.cookie())""!=u&&s.push(u.replace(a._prefix,""));else for(var f in a)s.push(f);return s}function u(t){if(!t||"string"!=typeof t)throw Error("First parameter must be a string");g?(window.localStorage.getItem(t)||window.localStorage.setItem(t,"{}"),window.sessionStorage.getItem(t)||window.sessionStorage.setItem(t,"{}")):(window.localCookieStorage.getItem(t)||window.localCookieStorage.setItem(t,"{}"),window.sessionCookieStorage.getItem(t)||window.sessionCookieStorage.setItem(t,"{}"));var r={localStorage:e.extend({},e.localStorage,{_ns:t}),sessionStorage:e.extend({},e.sessionStorage,{_ns:t})};return e.cookie&&(window.cookieStorage.getItem(t)||window.cookieStorage.setItem(t,"{}"),r.cookieStorage=e.extend({},e.cookieStorage,{_ns:t})),e.namespaceStorages[t]=r,r}function f(e){if(!window[e])return!1;var t="jsapi";try{return window[e].setItem(t,t),window[e].removeItem(t),!0}catch(r){return!1}}var c="ls_",m="ss_",g=f("localStorage"),h={_type:"",_ns:"",_callMethod:function(e,t){var r=[this._type],t=Array.prototype.slice.call(t),i=t[0];return this._ns&&r.push(this._ns),"string"==typeof i&&-1!==i.indexOf(".")&&(t.shift(),[].unshift.apply(t,i.split("."))),[].push.apply(r,t),e.apply(this,r)},get:function(){return this._callMethod(t,arguments)},set:function(){var t=arguments.length,i=arguments,n=i[0];if(1>t||!e.isPlainObject(n)&&2>t)throw Error("Minimum 2 arguments must be given or first parameter must be an object");if(e.isPlainObject(n)&&this._ns){for(var o in n)r(this._type,this._ns,o,n[o]);return n}var s=this._callMethod(r,i);return this._ns?s[n.split(".")[0]]:s},remove:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(i,arguments)},removeAll:function(e){return this._ns?(r(this._type,this._ns,{}),!0):n(this._type,e)},isEmpty:function(){return this._callMethod(o,arguments)},isSet:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(s,arguments)},keys:function(){return this._callMethod(a,arguments)}};if(e.cookie){window.name||(window.name=Math.floor(1e8*Math.random()));var l={_cookie:!0,_prefix:"",_expires:null,_path:null,_domain:null,setItem:function(t,r){e.cookie(this._prefix+t,r,{expires:this._expires,path:this._path,domain:this._domain})},getItem:function(t){return e.cookie(this._prefix+t)},removeItem:function(t){return e.removeCookie(this._prefix+t)},clear:function(){for(var t in e.cookie())""!=t&&(!this._prefix&&-1===t.indexOf(c)&&-1===t.indexOf(m)||this._prefix&&0===t.indexOf(this._prefix))&&e.removeCookie(t)},setExpires:function(e){return this._expires=e,this},setPath:function(e){return this._path=e,this},setDomain:function(e){return this._domain=e,this},setConf:function(e){return e.path&&(this._path=e.path),e.domain&&(this._domain=e.domain),e.expires&&(this._expires=e.expires),this},setDefaultConf:function(){this._path=this._domain=this._expires=null}};g||(window.localCookieStorage=e.extend({},l,{_prefix:c,_expires:3650}),window.sessionCookieStorage=e.extend({},l,{_prefix:m+window.name+"_"})),window.cookieStorage=e.extend({},l),e.cookieStorage=e.extend({},h,{_type:"cookieStorage",setExpires:function(e){return window.cookieStorage.setExpires(e),this},setPath:function(e){return window.cookieStorage.setPath(e),this},setDomain:function(e){return window.cookieStorage.setDomain(e),this},setConf:function(e){return window.cookieStorage.setConf(e),this},setDefaultConf:function(){return window.cookieStorage.setDefaultConf(),this}})}e.initNamespaceStorage=function(e){return u(e)},g?(e.localStorage=e.extend({},h,{_type:"localStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionStorage"})):(e.localStorage=e.extend({},h,{_type:"localCookieStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionCookieStorage"})),e.namespaceStorages={},e.removeAllStorages=function(t){e.localStorage.removeAll(t),e.sessionStorage.removeAll(t),e.cookieStorage&&e.cookieStorage.removeAll(t),t||(e.namespaceStorages={})}});
\ No newline at end of file
+!function(e){"function"==typeof define&&define.amd?define(["jquery", "jquery/jquery.cookie"],e):e("object"==typeof exports?require("jquery"):jQuery)}(function(e){function t(t){var r,i,n,o=arguments.length,s=window[t],a=arguments,u=a[1];if(2>o)throw Error("Minimum 2 arguments must be given");if(e.isArray(u)){i={};for(var f in u){r=u[f];try{i[r]=JSON.parse(s.getItem(r))}catch(c){i[r]=s.getItem(r)}}return i}if(2!=o){try{i=JSON.parse(s.getItem(u))}catch(c){throw new ReferenceError(u+" is not defined in this storage")}for(var f=2;o-1>f;f++)if(i=i[a[f]],void 0===i)throw new ReferenceError([].slice.call(a,1,f+1).join(".")+" is not defined in this storage");if(e.isArray(a[f])){n=i,i={};for(var m in a[f])i[a[f][m]]=n[a[f][m]];return i}return i[a[f]]}try{return JSON.parse(s.getItem(u))}catch(c){return s.getItem(u)}}function r(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1],u=s[2],f={};if(2>n||!e.isPlainObject(a)&&3>n)throw Error("Minimum 3 arguments must be given or second parameter must be an object");if(e.isPlainObject(a)){for(var c in a)r=a[c],e.isPlainObject(r)?o.setItem(c,JSON.stringify(r)):o.setItem(c,r);return a}if(3==n)return"object"==typeof u?o.setItem(a,JSON.stringify(u)):o.setItem(a,u),u;try{i=o.getItem(a),null!=i&&(f=JSON.parse(i))}catch(m){}i=f;for(var c=2;n-2>c;c++)r=s[c],i[r]&&e.isPlainObject(i[r])||(i[r]={}),i=i[r];return i[s[c]]=s[c+1],o.setItem(a,JSON.stringify(f)),f}function i(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1];if(2>n)throw Error("Minimum 2 arguments must be given");if(e.isArray(a)){for(var u in a)o.removeItem(a[u]);return!0}if(2==n)return o.removeItem(a),!0;try{r=i=JSON.parse(o.getItem(a))}catch(f){throw new ReferenceError(a+" is not defined in this storage")}for(var u=2;n-1>u;u++)if(i=i[s[u]],void 0===i)throw new ReferenceError([].slice.call(s,1,u).join(".")+" is not defined in this storage");if(e.isArray(s[u]))for(var c in s[u])delete i[s[u][c]];else delete i[s[u]];return o.setItem(a,JSON.stringify(r)),!0}function n(t,r){var n=a(t);for(var o in n)i(t,n[o]);if(r)for(var o in e.namespaceStorages)u(o)}function o(r){var i=arguments.length,n=arguments,s=(window[r],n[1]);if(1==i)return 0==a(r).length;if(e.isArray(s)){for(var u=0;ui)throw Error("Minimum 2 arguments must be given");if(e.isArray(o)){for(var a=0;a1?t.apply(this,o):n,a._cookie)for(var u in e.cookie())""!=u&&s.push(u.replace(a._prefix,""));else for(var f in a)s.push(f);return s}function u(t){if(!t||"string"!=typeof t)throw Error("First parameter must be a string");g?(window.localStorage.getItem(t)||window.localStorage.setItem(t,"{}"),window.sessionStorage.getItem(t)||window.sessionStorage.setItem(t,"{}")):(window.localCookieStorage.getItem(t)||window.localCookieStorage.setItem(t,"{}"),window.sessionCookieStorage.getItem(t)||window.sessionCookieStorage.setItem(t,"{}"));var r={localStorage:e.extend({},e.localStorage,{_ns:t}),sessionStorage:e.extend({},e.sessionStorage,{_ns:t})};return e.cookie&&(window.cookieStorage.getItem(t)||window.cookieStorage.setItem(t,"{}"),r.cookieStorage=e.extend({},e.cookieStorage,{_ns:t})),e.namespaceStorages[t]=r,r}function f(e){if(!window[e])return!1;var t="jsapi";try{return window[e].setItem(t,t),window[e].removeItem(t),!0}catch(r){return!1}}var c="ls_",m="ss_",g=f("localStorage"),h={_type:"",_ns:"",_callMethod:function(e,t){var r=[this._type],t=Array.prototype.slice.call(t),i=t[0];return this._ns&&r.push(this._ns),"string"==typeof i&&-1!==i.indexOf(".")&&(t.shift(),[].unshift.apply(t,i.split("."))),[].push.apply(r,t),e.apply(this,r)},get:function(){return this._callMethod(t,arguments)},set:function(){var t=arguments.length,i=arguments,n=i[0];if(1>t||!e.isPlainObject(n)&&2>t)throw Error("Minimum 2 arguments must be given or first parameter must be an object");if(e.isPlainObject(n)&&this._ns){for(var o in n)r(this._type,this._ns,o,n[o]);return n}var s=this._callMethod(r,i);return this._ns?s[n.split(".")[0]]:s},remove:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(i,arguments)},removeAll:function(e){return this._ns?(r(this._type,this._ns,{}),!0):n(this._type,e)},isEmpty:function(){return this._callMethod(o,arguments)},isSet:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(s,arguments)},keys:function(){return this._callMethod(a,arguments)}};if(e.cookie){window.name||(window.name=Math.floor(1e8*Math.random()));var l={_cookie:!0,_prefix:"",_expires:null,_path:null,_domain:null,setItem:function(t,r){e.cookie(this._prefix+t,r,{expires:this._expires,path:this._path,domain:this._domain})},getItem:function(t){return e.cookie(this._prefix+t)},removeItem:function(t){return e.removeCookie(this._prefix+t)},clear:function(){for(var t in e.cookie())""!=t&&(!this._prefix&&-1===t.indexOf(c)&&-1===t.indexOf(m)||this._prefix&&0===t.indexOf(this._prefix))&&e.removeCookie(t)},setExpires:function(e){return this._expires=e,this},setPath:function(e){return this._path=e,this},setDomain:function(e){return this._domain=e,this},setConf:function(e){return e.path&&(this._path=e.path),e.domain&&(this._domain=e.domain),e.expires&&(this._expires=e.expires),this},setDefaultConf:function(){this._path=this._domain=this._expires=null}};g||(window.localCookieStorage=e.extend({},l,{_prefix:c,_expires:3650}),window.sessionCookieStorage=e.extend({},l,{_prefix:m+window.name+"_"})),window.cookieStorage=e.extend({},l),e.cookieStorage=e.extend({},h,{_type:"cookieStorage",setExpires:function(e){return window.cookieStorage.setExpires(e),this},setPath:function(e){return window.cookieStorage.setPath(e),this},setDomain:function(e){return window.cookieStorage.setDomain(e),this},setConf:function(e){return window.cookieStorage.setConf(e),this},setDefaultConf:function(){return window.cookieStorage.setDefaultConf(),this}})}e.initNamespaceStorage=function(e){return u(e)},g?(e.localStorage=e.extend({},h,{_type:"localStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionStorage"})):(e.localStorage=e.extend({},h,{_type:"localCookieStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionCookieStorage"})),e.namespaceStorages={},e.removeAllStorages=function(t){e.localStorage.removeAll(t),e.sessionStorage.removeAll(t),e.cookieStorage&&e.cookieStorage.removeAll(t),t||(e.namespaceStorages={})}});