Added SharedObject to HTML5

This commit is contained in:
Skyler Lehmkuhl 2012-02-09 10:52:54 -05:00
parent 596c69f9cf
commit 63401df118
1 changed files with 44 additions and 0 deletions

44
base.js
View File

@ -877,6 +877,50 @@ function TextFormat () {
this.url = null this.url = null
} }
function SharedObject () {
this.data = {}
this.flush = function () {
localStorage.setItem(this._name, this.data)
}
this.clear = function () {
localStorage.removeItem(this._name)
for (i in this) {
this[i] = undefined
}
}
this.getSize = function () {
//This may not be byte-exact, but it should be close enough.
return JSON.stringify(this.data).length
}
this.setFps = function () {
//TODO: first understand this. Then, implement it!
}
Object.defineProperty(this, 'flush', {enumerable:false})
Object.defineProperty(this, 'clear', {enumerable:false})
Object.defineProperty(this, '_name', {enumerable:false})
Object.defineProperty(this, 'getSize', {enumerable:false})
Object.defineProperty(this, 'setFps', {enumerable:false})
}
SharedObject.list = {}
for (var i in localStorage) {
SharedObject.list[i] = new SharedObject()
SharedObject.list[i]._name = i
SharedObject.list[i].data = localStorage[i]
}
//TODO: Remote shared objects
SharedObject.getLocal = function (name, localPath, secure) {
if (name in SharedObject.list) {
return SharedObject.list[name]
}
else {
var so = new SharedObject()
so._name = name
SharedObject.list[name] = so
return so
}
//TODO: localPath should allow changing domain access; secure should force HTTPS.
}
//TODO: ContextMenu //TODO: ContextMenu