Add ObjectStorage module.

This commit is contained in:
Kevin Dungs
2014-08-03 23:04:46 +02:00
committed by Tadej Novak
parent d2fd856b18
commit 014c84239a
+25
View File
@@ -0,0 +1,25 @@
'use strict';
/** Allows to save objects to HTML5 local storage.
* However, it can only save properties, not functions.
*/
var ObjectStorage = (function() {
try {
var _s = localStorage;
return {
save: function(key, item) {
_s.setItem(key, JSON.stringify(item));
},
load: function(key) {
return JSON.parse(_s.getItem(key));
}
};
} catch (e) {
alert('There is no local storage for you.'
+ ' If you refresh the page, all progress will be lost');
return {
save: function(key, item) {},
load: function(key) { return null; }
};
};
});