snappymail/dev/Storage/LocalDriver/Cookie.js
RainLoop Team 06274c6a7c Code refactoring
Fixed owncloud password encoder/decoder (#291)
Fixed ckeditor in ownCloud iframe (Closes #302)
Release commit
2014-09-06 01:44:29 +04:00

100 lines
No EOL
1.6 KiB
JavaScript

/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function () {
'use strict';
var
$ = require('$'),
JSON = require('JSON'),
Consts = require('Common/Consts'),
Utils = require('Common/Utils')
;
/**
* @constructor
*/
function CookieLocalDriver()
{
}
/**
* @static
* @return {boolean}
*/
CookieLocalDriver.supported = function ()
{
return !!(window.navigator && window.navigator.cookieEnabled);
};
/**
* @param {string} sKey
* @param {*} mData
* @return {boolean}
*/
CookieLocalDriver.prototype.set = function (sKey, mData)
{
var
mStorageValue = $.cookie(Consts.Values.ClientSideStorageIndexName),
bResult = false,
mResult = null
;
try
{
mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
}
catch (oException) {}
if (!mResult)
{
mResult = {};
}
mResult[sKey] = mData;
try
{
$.cookie(Consts.Values.ClientSideStorageIndexName, JSON.stringify(mResult), {
'expires': 30
});
bResult = true;
}
catch (oException) {}
return bResult;
};
/**
* @param {string} sKey
* @return {*}
*/
CookieLocalDriver.prototype.get = function (sKey)
{
var
mStorageValue = $.cookie(Consts.Values.ClientSideStorageIndexName),
mResult = null
;
try
{
mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (mResult && !Utils.isUnd(mResult[sKey]))
{
mResult = mResult[sKey];
}
else
{
mResult = null;
}
}
catch (oException) {}
return mResult;
};
module.exports = CookieLocalDriver;
}());