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