2014-03-11 16:52:02 +01:00
|
|
|
window.fakeStorage = {
|
2014-03-12 13:35:42 +01:00
|
|
|
_data: {},
|
|
|
|
|
|
|
|
setItem: function (id, val) {
|
2014-03-11 16:52:02 +01:00
|
|
|
return this._data[id] = String(val);
|
|
|
|
},
|
2014-03-12 13:35:42 +01:00
|
|
|
|
|
|
|
getItem: function (id) {
|
2014-03-11 16:52:02 +01:00
|
|
|
return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
|
|
|
|
},
|
2014-03-12 13:35:42 +01:00
|
|
|
|
|
|
|
removeItem: function (id) {
|
|
|
|
return delete this._data[id];
|
|
|
|
},
|
|
|
|
|
|
|
|
clear: function () {
|
|
|
|
return this._data = {};
|
|
|
|
}
|
2014-03-11 16:52:02 +01:00
|
|
|
};
|
|
|
|
|
2014-03-14 02:25:26 +01:00
|
|
|
function isLocalStorageNameSupported()
|
|
|
|
{
|
|
|
|
var testKey = 'test', storage = window.localStorage;
|
|
|
|
try {
|
|
|
|
storage.setItem(testKey, '1');
|
|
|
|
storage.removeItem(testKey);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-03-12 12:15:57 +01:00
|
|
|
|
2014-03-14 02:25:26 +01:00
|
|
|
function LocalScoreManager() {
|
|
|
|
var localSupported = isLocalStorageNameSupported();
|
2014-03-12 12:15:57 +01:00
|
|
|
this.key = "bestScore";
|
|
|
|
this.storage = localSupported ? window.localStorage : window.fakeStorage;
|
2014-03-10 21:02:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LocalScoreManager.prototype.get = function () {
|
2014-03-12 13:30:50 +01:00
|
|
|
return this.storage.getItem(this.key) || 0;
|
2014-03-10 21:02:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
LocalScoreManager.prototype.set = function (score) {
|
2014-03-11 16:52:02 +01:00
|
|
|
this.storage.setItem(this.key, score);
|
2014-03-10 21:02:16 +01:00
|
|
|
};
|
|
|
|
|