Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
54
gaia/apps/fl/js/db.js
Executable file
54
gaia/apps/fl/js/db.js
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
'use strict';
|
||||
/* global indexedDB */
|
||||
/* exported objectStore */
|
||||
|
||||
var objectStore = (function() {
|
||||
const DBNAME = 'LOCKEDCONTENT';
|
||||
const DBVERSION = 1;
|
||||
const STORENAMES = ['ringtones', 'wallpapers'];
|
||||
var db;
|
||||
|
||||
function getStore(access, storeName, callback) {
|
||||
if (STORENAMES.indexOf(storeName) === -1) {
|
||||
throw Error('unknown object store name:', storeName);
|
||||
}
|
||||
|
||||
if (db) {
|
||||
callback(db.transaction(storeName, access).objectStore(storeName));
|
||||
}
|
||||
else {
|
||||
initDB(function() { getStore(access, storeName, callback); });
|
||||
}
|
||||
}
|
||||
|
||||
function initDB(callback) {
|
||||
var open = indexedDB.open(DBNAME, DBVERSION);
|
||||
|
||||
open.onsuccess = function() {
|
||||
db = open.result;
|
||||
callback();
|
||||
};
|
||||
|
||||
open.onupgradeneeded = function() {
|
||||
STORENAMES.forEach(function(storeName) {
|
||||
open.result.createObjectStore(storeName, {
|
||||
autoIncrement: true,
|
||||
keyPath: 'id'
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
open.onerror = function() {
|
||||
console.error('can not open database:', open.error.name);
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
readonly: function readonly(storeName, callback) {
|
||||
getStore('readonly', storeName, callback);
|
||||
},
|
||||
readwrite: function readwrite(storeName, callback) {
|
||||
getStore('readwrite', storeName, callback);
|
||||
}
|
||||
};
|
||||
}());
|
||||
Loading…
Reference in a new issue