Advertisement
Guest User

Untitled

a guest
Aug 30th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. idxdDB.open = function () {
  2. var version = 1;
  3. var request = indexedDB.open("db_undo", version);
  4.  
  5. // We can only create Object stores in a versionchange transaction.
  6. request.onupgradeneeded = function (e) {
  7. var db = e.target.result;
  8.  
  9. // A versionchange transaction is started automatically.
  10. e.target.transaction.onerror = function (e) {
  11. console.log("Error", e);
  12. };
  13.  
  14. if (db.objectStoreNames.contains("undo_point")) {
  15. db.deleteObjectStore("undo_point");
  16. }
  17.  
  18. var store = db.createObjectStore("undo_point");
  19. };
  20.  
  21. request.onsuccess = function (e) {
  22. idxdDB.db = e.target.result;
  23.  
  24. // Clear the store
  25. var trans = idxdDB.db.transaction(["undo_point"], "readwrite");
  26. var store = trans.objectStore("undo_point");
  27.  
  28. var req = store.clear();
  29. req.onsuccess = function(evt) {
  30. console.log("Store cleared");
  31. getQuota();
  32. listAllStore(store);
  33. };
  34.  
  35. };
  36.  
  37. request.onerror = function (e) {
  38. console.log("Error!", e);
  39. };
  40. };
  41.  
  42. function getQuota () {
  43. if (window.webkitStorageInfo && window.webkitStorageInfo.queryUsageAndQuota) {
  44. window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY,
  45. function (used, remaining) {
  46. console.log("Used quota: " + used + ", remaining quota: " + remaining);
  47. }, function (e) {
  48. console.log('Error', e);
  49. });
  50. }
  51. }
  52.  
  53.  
  54. function listAllStore (store) {
  55. store.openCursor().onsuccess = function(event) {
  56. var cursor = event.target.result;
  57. // if there is still another cursor to go, keep runing this code
  58. if(cursor) {
  59. console.log (cursor);
  60.  
  61. // continue on to the next item in the cursor
  62. cursor.continue();
  63.  
  64. // if there are no more cursor items to iterate through, say so, and exit the function
  65. } else {
  66. console.log ("Cursor finished");
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement