var self = this;
return Deferred(function (def) {
setTimeout(util.resolver(def, function () {
prefix = prefix || "";
var result = [];
for (var i = 0; i < self.storage.length; i++) {
var key = self.storage.key(i);
if (key.indexOf(self.prefix + prefix) === 0) {
var shortKey = key.substr(self.prefix.length);
if (excludePrefix) {
shortKey = shortKey.substr(prefix.length);
}
result.push(shortKey);
}
}
return result;
}));
});
},
toString: function () {
return '[storage for ' + this.name + ']';
}
});
var namePrefix = TogetherJS.config.get("storagePrefix");
TogetherJS.config.close("storagePrefix");
var storage = Storage('localStorage', localStorage, namePrefix + ".");
storage.settings = util.mixinEvents({
defaults: DEFAULT_SETTINGS,
get: function (name) {
assert(storage.settings.defaults.hasOwnProperty(name), "Unknown setting:", name);
return storage.get("settings." + name, storage.settings.defaults[name]);
},
set: function (name, value) {
assert(storage.settings.defaults.hasOwnProperty(name), "Unknown setting:", name);
return storage.set("settings." + name, value);
}
});
storage.tab = Storage('sessionStorage', sessionStorage, namePrefix + "-session.");
return storage;
});