mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
|
/*global define */
|
||
|
define(['lib/stapes'], function (Stapes) {
|
||
|
'use strict';
|
||
|
return Stapes.subclass(/** @lends LocalStorage.prototype */{
|
||
|
|
||
|
/**
|
||
|
* @class LocalStorage
|
||
|
* @classdesc LocalStorage handler using HTML5 localStorage
|
||
|
* @constructs
|
||
|
*
|
||
|
* @fires got
|
||
|
* @fires error
|
||
|
* @fires set
|
||
|
*/
|
||
|
constructor: function () {
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Gets stored data
|
||
|
*/
|
||
|
get: function () {
|
||
|
var data;
|
||
|
|
||
|
if (!window.localStorage) {
|
||
|
this.emit('error', 'Local Storage not supported');
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (localStorage.data) {
|
||
|
data = JSON.parse(localStorage.data);
|
||
|
this.emit('got', data);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Stores settings
|
||
|
* @param {object} data - Data object to store
|
||
|
*/
|
||
|
set: function (data) {
|
||
|
if (!window.localStorage) {
|
||
|
this.emit('error', 'Local Storage not supported');
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
localStorage.data = JSON.stringify(data);
|
||
|
this.emit('set');
|
||
|
}
|
||
|
});
|
||
|
});
|