mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
ES2015 first look / babeljs
This commit is contained in:
parent
5dcceaaca5
commit
445cd155e5
123 changed files with 3214 additions and 3680 deletions
72
dev/Common/ClientStorageDriver/Cookie.jsx
Normal file
72
dev/Common/ClientStorageDriver/Cookie.jsx
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
|
||||
import {window, JSON, $} from 'common';
|
||||
import Utils from 'Common/Utils';
|
||||
import {CLIENT_SIDE_STORAGE_INDEX_NAME} from 'Common/Consts';
|
||||
|
||||
class CookieDriver
|
||||
{
|
||||
/**
|
||||
* @param {string} key
|
||||
* @param {*} data
|
||||
* @return {boolean}
|
||||
*/
|
||||
set(key, data) {
|
||||
|
||||
let
|
||||
result = false,
|
||||
storageResult = null
|
||||
;
|
||||
|
||||
try
|
||||
{
|
||||
const storageValue = $.cookie(CLIENT_SIDE_STORAGE_INDEX_NAME);
|
||||
storageResult = null === storageValue ? null : JSON.parse(storageValue);
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
(storageResult || (storageResult = {}))[key] = data;
|
||||
|
||||
try
|
||||
{
|
||||
$.cookie(CLIENT_SIDE_STORAGE_INDEX_NAME, JSON.stringify(storageResult), {
|
||||
'expires': 30
|
||||
});
|
||||
|
||||
result = true;
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} key
|
||||
* @return {*}
|
||||
*/
|
||||
get(sKey) {
|
||||
|
||||
let result = null;
|
||||
|
||||
try
|
||||
{
|
||||
const
|
||||
storageValue = $.cookie(CLIENT_SIDE_STORAGE_INDEX_NAME),
|
||||
storageResult = null === storageValue ? null : JSON.parse(storageValue)
|
||||
;
|
||||
|
||||
result = (storageResult && !Utils.isUnd(storageResult[key])) ? storageResult[key] : null;
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
return mResult;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
static supported() {
|
||||
return !!(window.navigator && window.navigator.cookieEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
export {CookieDriver, CookieDriver as default};
|
||||
Loading…
Add table
Add a link
Reference in a new issue