1 /** 2 * Module for simplifying Indexed DB access 3 */ 4 (function() { 5 "use strict"; 6 7 var db = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB, 8 indexedDB = {}; 9 10 /** 11 * Module for simplifying Indexed DB access 12 * 13 * @namespace 14 * @name indexedDB 15 * @memberOf $_ 16 */ 17 indexedDB = { 18 current_db: null, 19 /** 20 * Connects to an indexedDB database 21 * 22 * @memberOf $_.indexedDB 23 * @name connect 24 * @function 25 * @param string dbname 26 * @param [int] version 27 * @param [function] onupgradeneeded 28 */ 29 connect: function(dbname, version, onupgradeneeded) 30 { 31 var request = {}; 32 33 version = version || 0; 34 35 // Ask for permission to use db 36 request = db.open(dbname, version); 37 38 // Assign onupgradeneeded callback 39 if(typeof onupgradeneeded !== "undefined") 40 { 41 request.onupgradeneeded = onupgradeneeded; 42 } 43 44 /** 45 * @private 46 */ 47 request.onerror = function(event) 48 { 49 console.log("IndexedDB disallowed."); 50 }; 51 52 /** 53 * @private 54 */ 55 request.onsuccess = function(event) 56 { 57 // Connect to the specified db 58 indexedDB.current_db = request.result; 59 }; 60 } 61 }; 62 63 $_.ext('indexedDB', indexedDB); 64 65 }());