snappymail/dev/Storage/LocalDriver/LocalStorage.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

98 lines
No EOL
1.6 KiB
JavaScript

/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function () {
'use strict';
var
window = require('window'),
JSON = require('JSON'),
Consts = require('Common/Consts'),
Utils = require('Common/Utils')
;
/**
* @constructor
*/
function LocalStorageLocalDriver()
{
}
/**
* @static
* @return {boolean}
*/
LocalStorageLocalDriver.supported = function ()
{
return !!window.localStorage;
};
/**
* @param {string} sKey
* @param {*} mData
* @return {boolean}
*/
LocalStorageLocalDriver.prototype.set = function (sKey, mData)
{
var
mStorageValue = window.localStorage[Consts.Values.ClientSideStorageIndexName] || null,
bResult = false,
mResult = null
;
try
{
mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
}
catch (oException) {}
if (!mResult)
{
mResult = {};
}
mResult[sKey] = mData;
try
{
window.localStorage[Consts.Values.ClientSideStorageIndexName] = JSON.stringify(mResult);
bResult = true;
}
catch (oException) {}
return bResult;
};
/**
* @param {string} sKey
* @return {*}
*/
LocalStorageLocalDriver.prototype.get = function (sKey)
{
var
mStorageValue = window.localStorage[Consts.Values.ClientSideStorageIndexName] || null,
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 = LocalStorageLocalDriver;
}());