2013-11-16 06:21:12 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
(function (module) {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
var
|
2014-08-21 23:08:34 +08:00
|
|
|
_ = require('../External/underscore.js'),
|
|
|
|
CookieDriver = require('./LocalStorages/CookieDriver.js'),
|
|
|
|
LocalStorageDriver = require('./LocalStorages/LocalStorageDriver.js')
|
2013-11-16 06:21:12 +08:00
|
|
|
;
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function LocalStorage()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
var
|
|
|
|
NextStorageDriver = _.find([LocalStorageDriver, CookieDriver], function (NextStorageDriver) {
|
|
|
|
return NextStorageDriver.supported();
|
|
|
|
})
|
|
|
|
;
|
|
|
|
|
|
|
|
if (NextStorageDriver)
|
|
|
|
{
|
|
|
|
NextStorageDriver = /** @type {?Function} */ NextStorageDriver;
|
|
|
|
this.oDriver = new NextStorageDriver();
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
LocalStorage.prototype.oDriver = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} iKey
|
|
|
|
* @param {*} mData
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
LocalStorage.prototype.set = function (iKey, mData)
|
|
|
|
{
|
|
|
|
return this.oDriver ? this.oDriver.set('p' + iKey, mData) : false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} iKey
|
|
|
|
* @return {*}
|
|
|
|
*/
|
|
|
|
LocalStorage.prototype.get = function (iKey)
|
|
|
|
{
|
|
|
|
return this.oDriver ? this.oDriver.get('p' + iKey) : null;
|
|
|
|
};
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
module.exports = new LocalStorage();
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
}(module));
|