Add capability guards for the database functionality.

This commit is contained in:
Jeremy Wall (zaphar) 2013-04-27 15:13:20 -04:00
parent 65736aa278
commit a8ceb3b194
2 changed files with 5 additions and 2 deletions

View File

@ -24,6 +24,9 @@ define(
} }
} }
}, },
Capable: function() {
return typeof indexedDB != "undefined";
},
// Turn on/off debug logging. // Turn on/off debug logging.
ToggleDebug: function() { ToggleDebug: function() {
this.debug = !this.debug; this.debug = !this.debug;

View File

@ -12,7 +12,7 @@ define(
// callbacks.error is expected to be a function that takes // callbacks.error is expected to be a function that takes
// an IDBRequest as an argument. // an IDBRequest as an argument.
UpdateTags: function(ref, tags, callbacks) { UpdateTags: function(ref, tags, callbacks) {
db.Transaction( db.Capable() && db.Transaction(
[tagStore], function(trans) { [tagStore], function(trans) {
db.Update( db.Update(
'tags', ref.toString(), 'tags', ref.toString(),
@ -27,7 +27,7 @@ define(
// callbacks.error is expected to be a function that takes // callbacks.error is expected to be a function that takes
// an IDBRequest as an argument. // an IDBRequest as an argument.
GetTags: function(ref, callbacks) { GetTags: function(ref, callbacks) {
db.Get(tagStore, ref.toString(), db.Capable() && db.Get(tagStore, ref.toString(),
{success: function(req) { {success: function(req) {
var data = req.target.result; var data = req.target.result;
// TODO suppport book and chapter indexes for // TODO suppport book and chapter indexes for