Skip to content

Commit f3bbc2c

Browse files
author
Parashuram N
committed
Commit from Travis Build #10
Build - https://travis-ci.org/axemclion/jquery-indexeddb/builds/3352608 Branch : master@ 202e05c
2 parents c36f853 + 202e05c commit f3bbc2c

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

grunt.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ module.exports = function(grunt){
8686
// Default task.
8787
grunt.loadNpmTasks('grunt-saucelabs-qunit');
8888
grunt.registerTask('build', 'lint');
89+
grunt.registerTask("forever", function(){
90+
this.async();
91+
});
8992

9093
grunt.registerTask("publish", function(){
9194
var done = this.async();

jquery.indexeddb.js

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
33
var IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange;
44
var IDBCursor = window.IDBCursor || window.webkitIDBCursor;
5+
IDBCursor.PREV = IDBCursor.PREV || "prev";
6+
IDBCursor.NEXT = IDBCursor.PREV || "next";
57

68
/**
79
* Best to use the constant IDBTransaction since older version support numeric types while the latest spec
@@ -19,7 +21,7 @@
1921
result = mode;
2022
break;
2123
default:
22-
result = IDBTransaction.READ_WRITE;
24+
result = IDBTransaction.READ_WRITE || "readwrite";
2325
}
2426
return result;
2527
}
@@ -54,16 +56,16 @@
5456
try {
5557
var idbRequest = typeof req === "function" ? req(args) : req;
5658
idbRequest.onsuccess = function(e){
57-
//console.log"Success", idbRequest, e, this);
59+
console.log("Success", idbRequest, e, this);
5860
dfd.resolveWith(idbRequest, [idbRequest.result, e]);
5961
};
6062
idbRequest.onerror = function(e){
61-
//console.log"Error", idbRequest, e, this);
63+
console.log("Error", idbRequest, e, this);
6264
dfd.rejectWith(idbRequest, [idbRequest.error, e]);
6365
};
6466
if (typeof idbRequest.onblocked !== "undefined" && idbRequest.onblocked === null) {
6567
idbRequest.onblocked = function(e){
66-
//console.log"Blocked", idbRequest, e, this);
68+
console.log("Blocked", idbRequest, e, this);
6769
try {
6870
var res = idbRequest.result;
6971
} catch (e) {
@@ -74,7 +76,7 @@
7476
}
7577
if (typeof idbRequest.onupgradeneeded !== "undefined" && idbRequest.onupgradeneeded === null) {
7678
idbRequest.onupgradeneeded = function(e){
77-
//console.log"Upgrade", idbRequest, e, this);
79+
console.log("Upgrade", idbRequest, e, this);
7880
dfd.notifyWith(idbRequest, [idbRequest.result, e]);
7981
};
8082
}
@@ -181,10 +183,10 @@
181183
"cursor": function(idbCursor, callback){
182184
return $.Deferred(function(dfd){
183185
try {
184-
//console.log"Cursor request created", idbCursor);
186+
console.log("Cursor request created", idbCursor);
185187
var cursorReq = typeof idbCursor === "function" ? idbCursor() : idbCursor;
186188
cursorReq.onsuccess = function(e){
187-
//console.log"Cursor successful");
189+
console.log("Cursor successful");
188190
if (!cursorReq.result) {
189191
dfd.resolveWith(cursorReq, [null, e]);
190192
return;
@@ -207,10 +209,10 @@
207209
"key": cursorReq.result.key,
208210
"value": cursorReq.result.value
209211
};
210-
//console.log"Cursor in progress", elem, e);
212+
console.log("Cursor in progress", elem, e);
211213
dfd.notifyWith(cursorReq, [elem, e]);
212214
var result = callback.apply(cursorReq, [elem]);
213-
//console.log"Iteration function returned", result);
215+
console.log("Iteration function returned", result);
214216
try {
215217
if (result === false) {
216218
dfd.resolveWith(cursorReq, [null, e]);
@@ -221,16 +223,16 @@
221223
else cursorReq.result["continue"]();
222224
}
223225
} catch (e) {
224-
//console.log"Exception when trying to advance cursor", cursorReq, e);
226+
console.log("Exception when trying to advance cursor", cursorReq, e);
225227
dfd.rejectWith(cursorReq, [cursorReq.result, e]);
226228
}
227229
};
228230
cursorReq.onerror = function(e){
229-
//console.log"Cursor request errored out", e);
231+
console.log("Cursor request errored out", e);
230232
dfd.rejectWith(cursorReq, [cursorReq.result, e]);
231233
};
232234
} catch (e) {
233-
//console.log"An exception occured inside cursor", cursorReq, e)
235+
console.log("An exception occured inside cursor", cursorReq, e)
234236
e.type = "exception";
235237
dfd.rejectWith(cursorReq, [null, e]);
236238
}
@@ -329,13 +331,13 @@
329331
callback("onupgradeneeded", result, [event]);
330332
// Version transaction is now complete, to open ordinary transaction
331333
versionReq.result.db.close();
332-
//console.log"Database closed, and will try to open again, with same version");
334+
console.log("Database closed, and will try to open again, with same version");
333335
var newDbOpenReq = indexedDB.open(dbName);
334336
delete result.transaction;
335337
delete result.result;
336338

337339
newDbOpenReq.onsuccess = function(e){
338-
//console.log"DB Opened without version change", newDbOpenReq.result);
340+
console.log("DB Opened without version change", newDbOpenReq.result);
339341
copyReq(newDbOpenReq);
340342
callback("onsuccess", result, [e], function(){
341343
newDbOpenReq.result.close();
@@ -345,15 +347,15 @@
345347
newDbOpenReq.onerror = function(e){
346348
copyReq(newDbOpenReq);
347349
callback("onerror", result, [e], function(){
348-
//console.log"Closed database in newRequest on error", newDbOpenReq);
350+
console.log("Closed database in newRequest on error", newDbOpenReq);
349351
newDbOpenReq.result.close();
350352
});
351353
};
352354
newDbOpenReq.onblocked = function(e){
353-
//console.log"DB Blocked without version change", newDbOpenReq.result);
355+
console.log("DB Blocked without version change", newDbOpenReq.result);
354356
copyReq(newDbOpenReq);
355357
callback("onblocked", result, [e], function(){
356-
//console.log"Closed database in newRequest on blocked", newDbOpenReq);
358+
console.log("Closed database in newRequest on blocked", newDbOpenReq);
357359
newDbOpenReq.result.close();
358360
});
359361
};
@@ -364,7 +366,7 @@
364366
};
365367
versionReq.onblocked = function(e){
366368
// This always gets called, resulting the blocking the DB upgrade
367-
//console.log"Version transaction blocked, so calling the on blocked method");
369+
console.log("Version transaction blocked, so calling the on blocked method");
368370
callback("onblocked", result, [e]);
369371
};
370372
} else if (oldVersion === newVersion) {
@@ -380,7 +382,7 @@
380382
};
381383
dbOpenReq.onerror = function(e){
382384
copyReq();
383-
//console.log"Error", dbOpenReq);
385+
console.log("Error", dbOpenReq);
384386
callback("onerror", result, [e]);
385387
};
386388
dbOpenReq.onblocked = function(e){
@@ -403,11 +405,11 @@
403405

404406
// Start with opening the database
405407
var dbPromise = wrap.request(function(){
406-
//console.log"Trying to open DB with", version);
408+
console.log("Trying to open DB with", version);
407409
return version ? openReqShim(dbName, version) : openReqShim(dbName);
408410
});
409411
dbPromise.then(function(db, e){
410-
//console.log"DB opened at", db.version);
412+
console.log("DB opened at", db.version);
411413
db.onversionchange = function(){
412414
// Try to automatically close the database if there is a version change request
413415
if (!(config && config.onversionchange && config.onversionchange() !== false)) {
@@ -421,7 +423,7 @@
421423
if (e && e.type === "upgradeneeded") {
422424
if (config && config.schema) {
423425
// Assuming that version is always an integer
424-
//console.log"Upgrading DB to ", db.version);
426+
console.log("Upgrading DB to ", db.version);
425427
for (var i = e.oldVersion + 1; i <= e.newVersion; i++) {
426428
typeof config.schema[i] === "function" && config.schema[i].call(this, wrap.transaction(this.transaction));
427429
}
@@ -464,17 +466,17 @@
464466
return $.Deferred(function(dfd){
465467
dbPromise.then(function(db, e){
466468
try {
467-
//console.log"DB Opened, now trying to create a transaction", storeNames, mode);
469+
console.log("DB Opened, now trying to create a transaction", storeNames, mode);
468470
var idbTransaction = db.transaction(storeNames, mode);
469-
//console.log"Created a transaction", idbTransaction, mode, storeNames);
471+
console.log("Created a transaction", idbTransaction, mode, storeNames);
470472
idbTransaction.onabort = idbTransaction.onerror = function(e){
471473
dfd.rejectWith(idbTransaction, [e]);
472474
};
473475
idbTransaction.oncomplete = function(e){
474476
dfd.resolveWith(idbTransaction, [e]);
475477
};
476478
} catch (e) {
477-
//console.log"Creating a traction failed", e, storeNames, mode, this);
479+
console.log("Creating a traction failed", e, storeNames, mode, this);
478480
e.type = "exception";
479481
dfd.rejectWith(this, [e]);
480482
return;
@@ -488,7 +490,7 @@
488490
}, function(err, e){
489491
dfd.rejectWith(this, [e, err]);
490492
}, function(res, e){
491-
//console.log"Database open is blocked or upgrade needed", res, e.type);
493+
console.log("Database open is blocked or upgrade needed", res, e.type);
492494
//dfd.notifyWith(this, ["", e]);
493495
});
494496

@@ -501,70 +503,70 @@
501503
return $.Deferred(function(dfd){
502504
function onTransactionProgress(trans, callback){
503505
try {
504-
//console.log"Finally, returning the object store", trans);
506+
console.log("Finally, returning the object store", trans);
505507
callback(trans.objectStore(storeName)).then(function(result, e){
506508
dfd.resolveWith(this, [result, e]);
507509
}, function(err, e){
508510
dfd.rejectWith(this, [err, e]);
509511
});
510512
} catch (e) {
511-
//console.log"Duh, an exception occured", e);
513+
console.log("Duh, an exception occured", e);
512514
e.name = "exception";
513515
dfd.rejectWith(trans, [e, e]);
514516
}
515517
}
516518
me.transaction(storeName, getDefaultTransaction(mode)).then(function(){
517-
//console.log"Transaction completed");
519+
console.log("Transaction completed");
518520
// Nothing to do when transaction is complete
519521
}, function(err, e){
520522
// If transaction fails, CrudOp fails
521523
if (err.code === err.NOT_FOUND_ERR && (mode === true || typeof mode === "object")) {
522-
//console.log"Object Not found, so will try to create one now");
524+
console.log("Object Not found, so will try to create one now");
523525
var db = this.result;
524526
db.close();
525527
dbPromise = wrap.request(function(){
526-
//console.log"Now trying to open the database again", db.version);
528+
console.log("Now trying to open the database again", db.version);
527529
return openReqShim(dbName, (parseInt(db.version, 10) || 1) + 1);
528530
});
529531
dbPromise.then(function(db, e){
530-
//console.log"Database opened, tto open transaction", db.version);
532+
console.log("Database opened, tto open transaction", db.version);
531533
db.onversionchange = function(){
532534
// Try to automatically close the database if there is a version change request
533535
if (!(config && config.onversionchange && config.onversionchange() !== false)) {
534536
db.close();
535537
}
536538
};
537539
me.transaction(storeName, getDefaultTransaction(mode)).then(function(){
538-
//console.log"Transaction completed when trying to create object store");
540+
console.log("Transaction completed when trying to create object store");
539541
// Nothing much to do
540542
}, function(err, e){
541543
dfd.rejectWith(this, [err, e]);
542544
}, function(trans, e){
543-
//console.log"Transaction in progress, when object store was not found", this, trans, e);
545+
console.log("Transaction in progress, when object store was not found", this, trans, e);
544546
onTransactionProgress(trans, callback);
545547
});
546548
}, function(err, e){
547549
dfd.rejectWith(this, [err, e]);
548550
}, function(db, e){
549551
if (e.type === "upgradeneeded") {
550552
try {
551-
//console.log"Now trying to create an object store", e.type);
553+
console.log("Now trying to create an object store", e.type);
552554
db.createObjectStore(storeName, mode === true ? {
553555
"autoIncrement": true
554556
} : mode);
555-
//console.log"Object store created", storeName, db);
557+
console.log("Object store created", storeName, db);
556558
} catch (ex) {
557-
//console.log"Exception when trying ot create a new object store", ex)
559+
console.log("Exception when trying ot create a new object store", ex)
558560
dfd.rejectWith(this, [ex, e]);
559561
}
560562
}
561563
});
562564
} else {
563-
//console.log"Error in transaction inside object store", err);
565+
console.log("Error in transaction inside object store", err);
564566
dfd.rejectWith(this, [err, e]);
565567
}
566568
}, function(trans){
567-
//console.log"Transaction is in progress", trans);
569+
console.log("Transaction is in progress", trans);
568570
onTransactionProgress(trans, callback);
569571
});
570572
});

0 commit comments

Comments
 (0)