Created
February 23, 2012 19:19
-
-
Save juanriaza/1894463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Data = { | |
_ownKeys: [], | |
_similar: [], | |
_appKey: 'listenAnywhere', | |
set: function(key, value) | |
{ | |
var existingValue = localStorage.getItem(this._appKey); | |
if (null === existingValue) { | |
existingValue = {}; | |
} else { | |
existingValue = JSON.parse(existingValue); | |
} | |
existingValue[key] = value; | |
try { | |
localStorage.setItem(this._appKey, JSON.stringify(existingValue)); | |
} catch (e) { | |
if (e == QUOTA_EXCEEDED_ERR) { | |
localStorage.removeItem(this._appKey); | |
var temp = {}; | |
temp[key] = value; | |
localStorage.setItem(this._appKey, temp); | |
this._ownKeys = []; | |
} | |
} | |
this._ownKeys.push(key); | |
}, | |
get: function(key) | |
{ | |
return JSON.parse(localStorage.getItem(this._appKey))[key]; | |
}, | |
has: function(key) | |
{ | |
return contains(this._ownKeys, key); | |
}, | |
// keep similar live and in localStorage | |
setSimilar: function(key, value) { | |
this._similar = value; | |
this.set(key, value); | |
}, | |
hasSimilar: function(uri) { | |
return contains(this._similar, uri); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment