2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
(function () {
|
2014-08-25 23:49:01 +08:00
|
|
|
|
|
|
|
'use strict';
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
2015-01-27 05:06:00 +08:00
|
|
|
function ClientStorage()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
var
|
2014-09-02 08:15:31 +08:00
|
|
|
NextStorageDriver = require('_').find([
|
2015-01-27 05:06:00 +08:00
|
|
|
require('Common/ClientStorageDriver/LocalStorage'),
|
|
|
|
require('Common/ClientStorageDriver/Cookie')
|
2014-08-27 23:59:44 +08:00
|
|
|
], function (NextStorageDriver) {
|
2014-09-02 08:15:31 +08:00
|
|
|
return NextStorageDriver && NextStorageDriver.supported();
|
2014-08-20 23:03:12 +08:00
|
|
|
})
|
|
|
|
;
|
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
this.oDriver = null;
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
if (NextStorageDriver)
|
|
|
|
{
|
|
|
|
this.oDriver = new NextStorageDriver();
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-09-02 19:34:17 +08:00
|
|
|
/**
|
|
|
|
* @type {LocalStorageDriver|CookieDriver|null}
|
|
|
|
*/
|
2015-01-27 05:06:00 +08:00
|
|
|
ClientStorage.prototype.oDriver = null;
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} iKey
|
|
|
|
* @param {*} mData
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2015-01-27 05:06:00 +08:00
|
|
|
ClientStorage.prototype.set = function (iKey, mData)
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
return this.oDriver ? this.oDriver.set('p' + iKey, mData) : false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} iKey
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2015-01-27 05:06:00 +08:00
|
|
|
ClientStorage.prototype.get = function (iKey)
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
return this.oDriver ? this.oDriver.get('p' + iKey) : null;
|
|
|
|
};
|
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
module.exports = new ClientStorage();
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|