var bongo;!function(a){var b=function(){function b(b,c){"undefined"==typeof c&&(c=function(){}),this.ensured=!1,this.objectStores=[];var d,e,b,f;if(b.objectStores=b.objectStores||b.collections||[],this.name=b.name,b.objectStores instanceof Array)for(var g=0;gd))throw e.webkitErrorMessage||e.error.name;setTimeout(function(){f(),d++},250)}.bind(c),e.onerror=function(){throw e.webkitErrorMessage||e.error.name}.bind(c)};this.get(function(a){a.close(),f()})},b.prototype.get=function(b){var c=this,d=500,e=function(){if(!c.ensured)return a.debug&&console.log("Database not ensured yet"),d--,d>0&&setTimeout(function(){e()},200),void 0;a.debug&&console.log("Database is ensured");var f=a.indexedDB.open(c.name);f.onupgradeneeded=function(){a.debug&&console.debug("onupgradeneeded"),f.result},f.onsuccess=function(c){a.debug&&console.debug("onsuccess"),b(c.target.result)},f.onblocked=function(){throw console.log(c.version,f),console.log("onblocked"),f.webkitErrorMessage||f.error.name},f.onerror=function(){throw console.log("onerror"),f.webkitErrorMessage||f.error.name},f.onfailure=f.onerror};e()},b.prototype.ensure=function(b){"undefined"==typeof b&&(b=function(){});var c=this;a.debug&&console.debug("Ensuring "+this.name),a.getStoredSignature(this.name,function(d){return a.debug&&console.debug("Signature found: "+JSON.stringify(d)),a.equals(d,c.signature())?(a.getStoredVersion(c.name,function(a){c.version=a,b()}),c.ensured=!0,void 0):(a.getStoredVersion(c.name,function(e){a.debug&&console.debug("Version found: "+e),c.version=e+1;var f=a.indexedDB.open(c.name,c.version);f.onblocked=function(){console.log("blocked",f.error.name)},f.onupgradeneeded=function(e){a.debug&&console.debug("onupgradeneeded in ensure, version "+c.version);for(var g=e.currentTarget.transaction,h=f.result,i=0;i2&&h.close(),setTimeout(function(){b()},1),c.ensured=!0}}),void 0)})},b}();a.Database=b}(bongo||(bongo={}));var bongo;!function(a){function b(){var a=Math.floor((new Date).valueOf()/1e3).toString(16);this.key_m||(this.key_m=Math.floor(16777216*Math.random()).toString(16)),this.key_p||(this.key_p=Math.floor(32767*Math.random()).toString(16)),"undefined"==typeof this.key_i?this.key_i=0:this.key_i>16777215&&(this.key_i=0),this.key_i=Number(this.key_i),this.key_i++;var b=this.key_i.toString(16),c="00000000".substr(0,6-a.length)+a+"000000".substr(0,6-this.key_m.length)+this.key_m+"0000".substr(0,4-this.key_p.length)+this.key_p+"000000".substr(0,6-b.length)+b;return c}var c=function(){function b(a,b){this.database=a,this.name=b.name,this.keyPath=b.keyPath||"_id",this.autoIncrement=!!b.autoIncrement,this.indexes=b.indexes||{}}return b.prototype.filter=function(b){var c=new a.Query(this.database,[this.name]);return c.filter(b)},b.prototype.find=function(b,c){"undefined"==typeof c&&(c=null);var d=new a.Query(this.database,[this.name]);return d.find(b,c)},b.prototype.findOne=function(b,c){var d=new a.Query(this.database,[this.name]);return d.findOne(b,c)},b.prototype.count=function(a,b){var c=this;"undefined"==typeof b&&"function"==typeof a&&(b=[a,a=null][0]);var d,e=function(a){b(a.target.result)};this.database.get(function(a){var b=a.transaction([c.name],"readonly"),f=b.objectStore(c.name);d=f.count(),d.onsuccess=e}.bind(this))},b.prototype.ensureObjectStore=function(b,c,d){var b,e,f=null;a.debug&&console.debug("ensureObjectStore"),d.objectStoreNames&&d.objectStoreNames.contains(this.name)?d.objectStoreNames&&d.objectStoreNames.contains(this.name)&&(e=b.objectStore(this.name)):(a.debug&&console.debug("Creating "+this.name),e=d.createObjectStore(this.name,{keyPath:"_id",autoIncrement:!1}));for(var g=0;g0?f--:d&&o.push(d.value),d&&(!b.limit||o.length0?f--:d&&o.push(d.value);return!b.limit||o.length=a[e][c])return!1}else if("$lte"===c){if(b[e]>a[e][c])return!1}else if("$ne"===c){if(b[e]==a[e][c])return!1}else if("$in"===c&&a[e][c]instanceof Array){if(-1===a[e][c].indexOf(b[e]))return!1}else if("$nin"===c&&a[e][c]instanceof Array){if(-1!==a[e][c].indexOf(b[e]))return!1}else{if(!("$all"===c&&b[e]instanceof Array&&a[e][c]instanceof Array))return!1;for(d=0;d0?d._skip--:(d.keys.length&&(f=b(f,d.keys)),g.push(f)))}else d._skip>0?d._skip--:(d.keys.length&&(f=b(f,d.keys)),g.push(f));return g.length