/*! IndexedDBShim - v0.1.2 - 2014-09-08 */ "use strict";var idbModules={},cleanInterface=!1;!function(){var a={test:!0};if(Object.defineProperty)try{Object.defineProperty(a,"test",{enumerable:!1}),a.test&&(cleanInterface=!0)}catch(b){}}(),function(a){function b(a,b,c,d){c.target=b,"function"==typeof b[a]&&b[a].apply(b,[c]),"function"==typeof d&&d()}function c(b,c,d){var e=new DOMException.prototype.constructor(0,c);throw e.name=b,e.message=c,a.DEBUG&&(console.log(b,c,d,e),console.trace&&console.trace()),e}var d=function(){this.length=0,this._items=[],cleanInterface&&Object.defineProperty(this,"_items",{enumerable:!1})};if(d.prototype={contains:function(a){return-1!==this._items.indexOf(a)},item:function(a){return this._items[a]},indexOf:function(a){return this._items.indexOf(a)},push:function(a){this._items.push(a),this.length+=1;for(var b=0;bh;++h)g[h]=d.charCodeAt(h);return new Blob([g.buffer],{type:b})}function rez(value){var i,item,name,path;if(value&&"object"==typeof value)if("[object Array]"===Object.prototype.toString.apply(value))for(i=0;i":" >= ")+" ?"),j.push(a.Key.encode(h.__range.lower))),h.__range.lower!==b&&h.__range.upper!==b&&i.push("AND"),h.__range.upper!==b&&(i.push(h.__keyColumnName+(h.__range.upperOpen?" < ":" <= ")+" ?"),j.push(a.Key.encode(h.__range.upper)))),"undefined"!=typeof c&&(h.__lastKeyContinued=c,h.__offset=0),h.__lastKeyContinued!==b&&(i.push("AND "+h.__keyColumnName+" >= ?"),j.push(a.Key.encode(h.__lastKeyContinued))),i.push("ORDER BY ",h.__keyColumnName),i.push("LIMIT "+g+" OFFSET "+h.__offset),a.DEBUG&&console.log(i.join(" "),j),h.__prefetchedData=null,d.executeSql(i.join(" "),j,function(c,d){d.rows.length>1?(h.__prefetchedData=d.rows,h.__prefetchedIndex=0,a.DEBUG&&console.log("Preloaded "+h.__prefetchedData.length+" records for cursor"),h.__decode(d.rows.item(0),e)):1===d.rows.length?h.__decode(d.rows.item(0),e):(a.DEBUG&&console.log("Reached end of cursors"),e(b,b))},function(b,c){a.DEBUG&&console.log("Could not execute Cursor.continue"),f(c)})},c.prototype.__decode=function(b,c){var d=a.Key.decode(b[this.__keyColumnName]),e=this.__valueDecoder.decode(b[this.__valueColumnName]),f=a.Key.decode(b.key);c(d,e,f)},c.prototype["continue"]=function(c){var d=a.cursorPreloadPackSize||100,e=this;this.__idbObjectStore.transaction.__addToTransactionQueue(function(a,f,g,h){e.__offset++;var i=function(a,c,d){e.key=a,e.value=c,e.primaryKey=d,g("undefined"!=typeof e.key?e:b,e.__req)};return e.__prefetchedData&&(e.__prefetchedIndex++,e.__prefetchedIndex=c&&a.util.throwDOMException("Type Error - Count is invalid - 0 or negative",c);var d=this;this.__idbObjectStore.transaction.__addToTransactionQueue(function(a,e,f,g){d.__offset+=c,d.__find(b,a,function(a,c){d.key=a,d.value=c,f("undefined"!=typeof d.key?d:b,d.__req)},g)})},c.prototype.update=function(c){var d=this,e=this.__idbObjectStore.transaction.__createRequest(function(){});return a.Sca.encode(c,function(f){d.__idbObjectStore.transaction.__pushToQueue(e,function(e,g,h,i){d.__find(b,e,function(b,g,j){var k=d.__idbObjectStore,l=d.__idbObjectStore.transaction.db.__storeProperties,m=[f],n="UPDATE "+a.util.quote(k.name)+" SET value = ?",o=l[k.name]&&l[k.name].indexList;if(o)for(var p in o){var q=o[p];n+=", "+p+" = ?",m.push(a.Key.encode(c[q.keyPath]))}n+=" WHERE key = ?",m.push(a.Key.encode(j)),a.DEBUG&&console.log(n,f,b,j),e.executeSql(n,m,function(a,c){d.__prefetchedData=null,1===c.rowsAffected?h(b):i("No rows with key found"+b)},function(a,b){i(b)})},i)})}),e},c.prototype["delete"]=function(){var c=this;return this.__idbObjectStore.transaction.__addToTransactionQueue(function(d,e,f,g){c.__find(b,d,function(e,h,i){var j="DELETE FROM "+a.util.quote(c.__idbObjectStore.name)+" WHERE key = ?";a.DEBUG&&console.log(j,e,i),d.executeSql(j,[a.Key.encode(i)],function(a,d){c.__prefetchedData=null,1===d.rowsAffected?(c.__offset--,f(b)):g("No rows with key found"+e)},function(a,b){g(b)})},g)})},a.IDBCursor=c}(idbModules),function(idbModules,undefined){function IDBIndex(a,b){this.indexName=this.name=a,this.__idbObjectStore=this.objectStore=this.source=b;var c=b.transaction.db.__storeProperties[b.name],d=c&&c.indexList;this.keyPath=d&&d[a]&&d[a].keyPath||a,["multiEntry","unique"].forEach(function(b){this[b]=!!(d&&d[a]&&d[a].optionalParams&&d[a].optionalParams[b])},this)}IDBIndex.prototype.__createIndex=function(indexName,keyPath,optionalParameters){var me=this,transaction=me.__idbObjectStore.transaction;transaction.__addToTransactionQueue(function(tx,args,success,failure){me.__idbObjectStore.__getStoreProps(tx,function(){function error(){idbModules.util.throwDOMException(0,"Could not create new index",arguments)}2!==transaction.mode&&idbModules.util.throwDOMException(0,"Invalid State error, not a version transaction",me.transaction);var idxList=JSON.parse(me.__idbObjectStore.__storeProps.indexList);"undefined"!=typeof idxList[indexName]&&idbModules.util.throwDOMException(0,"Index already exists on store",idxList);var columnName=indexName;idxList[indexName]={columnName:columnName,keyPath:keyPath,optionalParams:optionalParameters},me.__idbObjectStore.__storeProps.indexList=JSON.stringify(idxList);var sql=["ALTER TABLE",idbModules.util.quote(me.__idbObjectStore.name),"ADD",columnName,"BLOB"].join(" ");idbModules.DEBUG&&console.log(sql),tx.executeSql(sql,[],function(tx,data){tx.executeSql("SELECT * FROM "+idbModules.util.quote(me.__idbObjectStore.name),[],function(tx,data){!function initIndexForRow(i){if(i=b.__requests.length?(b.__active=!1,void(b.__requests=[])):(g=b.__requests[h],void g.op(c,g.args,d,e))}b.__tx=c;var g=null,h=0;try{f()}catch(i){a.DEBUG&&console.log("An exception occured in transaction",arguments),"function"==typeof b.onerror&&b.onerror()}},function(){a.DEBUG&&console.log("An error in transaction",arguments),"function"==typeof b.onerror&&b.onerror()},function(){a.DEBUG&&console.log("Transaction completed",arguments),"function"==typeof b.oncomplete&&b.oncomplete()})},1)},e.prototype.__addToTransactionQueue=function(b,c){this.__active||this.mode===d||a.util.throwDOMException(0,"A request was placed against a transaction which is currently not active, or which is finished.",this.__mode);var e=this.__createRequest();return this.__pushToQueue(e,b,c),e},e.prototype.__createRequest=function(){var b=new a.IDBRequest;return b.source=this.db,b.transaction=this,b},e.prototype.__pushToQueue=function(a,b,c){this.__requests.push({op:b,args:c,req:a}),this.__executeRequests()},e.prototype.objectStore=function(b){return new a.IDBObjectStore(b,this)},e.prototype.abort=function(){!this.__active&&a.util.throwDOMException(0,"A request was placed against a transaction which is currently not active, or which is finished",this.__active)},e.prototype.READ_ONLY=0,e.prototype.READ_WRITE=1,e.prototype.VERSION_CHANGE=2,a.IDBTransaction=e}(idbModules),function(a){var b=function(b,c,d,e){this.__db=b,this.version=d,this.objectStoreNames=new a.util.StringList;for(var f=0;f0&&d.executeSql("DROP TABLE "+a.util.quote(b),[],function(){d.executeSql("DELETE FROM __sys__ WHERE name = ?",[b],function(){},c)},c)})})})},b.prototype.close=function(){},b.prototype.transaction=function(b,c){var d=new a.IDBTransaction(b,c||1,this);return d},a.IDBDatabase=b}(idbModules),function(a){var b=4194304;if(window.openDatabase){var c=window.openDatabase("__sysdb__",1,"System Database",b);c.transaction(function(a){a.executeSql("CREATE TABLE IF NOT EXISTS dbVersions (name VARCHAR(255), version INT);",[])},function(){a.DEBUG&&console.log("Error in sysdb transaction - when creating dbVersions",arguments)});var d={open:function(d,e){function f(){if(!i){var b=a.Event("error",arguments);h.readyState="done",h.error="DOMError",a.util.callback("onerror",h,b),i=!0}}function g(g){var i=window.openDatabase(d,1,d,b);h.readyState="done","undefined"==typeof e&&(e=g||1),(0>=e||g>e)&&a.util.throwDOMException(0,"An attempt was made to open a database using a lower version than the existing version.",e),i.transaction(function(b){b.executeSql("CREATE TABLE IF NOT EXISTS __sys__ (name VARCHAR(255), keyPath VARCHAR(255), autoInc BOOLEAN, indexList BLOB)",[],function(){b.executeSql("SELECT * FROM __sys__",[],function(b,j){var k=a.Event("success");h.source=h.result=new a.IDBDatabase(i,d,e,j),e>g?c.transaction(function(b){b.executeSql("UPDATE dbVersions set version = ? where name = ?",[e,d],function(){var b=a.Event("upgradeneeded");b.oldVersion=g,b.newVersion=e,h.transaction=h.result.__versionTransaction=new a.IDBTransaction([],2,h.source),a.util.callback("onupgradeneeded",h,b,function(){var b=a.Event("success");a.util.callback("onsuccess",h,b)})},f)},f):a.util.callback("onsuccess",h,k)},f)},f)},f)}var h=new a.IDBOpenRequest,i=!1;return c.transaction(function(a){a.executeSql("SELECT * FROM dbVersions where name = ?",[d],function(a,b){0===b.rows.length?a.executeSql("INSERT INTO dbVersions VALUES (?,?)",[d,e||1],function(){g(0)},f):g(b.rows.item(0).version)},f)},f),h},deleteDatabase:function(d){function e(b){if(!h){g.readyState="done",g.error="DOMError";var c=a.Event("error");c.message=b,c.debug=arguments,a.util.callback("onerror",g,c),h=!0}}function f(){c.transaction(function(b){b.executeSql("DELETE FROM dbVersions where name = ? ",[d],function(){g.result=void 0;var b=a.Event("success");b.newVersion=null,b.oldVersion=i,a.util.callback("onsuccess",g,b)},e)},e)}var g=new a.IDBOpenRequest,h=!1,i=null;return c.transaction(function(c){c.executeSql("SELECT * FROM dbVersions where name = ?",[d],function(c,h){if(0===h.rows.length){g.result=void 0;var j=a.Event("success");return j.newVersion=null,j.oldVersion=i,void a.util.callback("onsuccess",g,j)}i=h.rows.item(0).version;var k=window.openDatabase(d,1,d,b);k.transaction(function(b){b.executeSql("SELECT * FROM __sys__",[],function(b,c){var d=c.rows;!function g(c){c>=d.length?b.executeSql("DROP TABLE __sys__",[],function(){f()},e):b.executeSql("DROP TABLE "+a.util.quote(d.item(c).name),[],function(){g(c+1)},function(){g(c+1)})}(0)},function(){f()})},e)})},e),g},cmp:function(b,c){return a.Key.encode(b)>a.Key.encode(c)?1:b===c?0:-1}};a.shimIndexedDB=d}}(idbModules),function(a,b){"undefined"!=typeof a.openDatabase&&(a.shimIndexedDB=b.shimIndexedDB,a.shimIndexedDB&&(a.shimIndexedDB.__useShim=function(){a.indexedDB=b.shimIndexedDB,a.IDBDatabase=b.IDBDatabase,a.IDBTransaction=b.IDBTransaction,a.IDBCursor=b.IDBCursor,a.IDBKeyRange=b.IDBKeyRange,a.indexedDB!==b.shimIndexedDB&&Object.defineProperty&&Object.defineProperty(a,"indexedDB",{value:b.shimIndexedDB})},a.shimIndexedDB.__debug=function(a){b.DEBUG=a})),"indexedDB"in a||(a.indexedDB=a.indexedDB||a.webkitIndexedDB||a.mozIndexedDB||a.oIndexedDB||a.msIndexedDB);var c=!1;if((navigator.userAgent.match(/Android 2/)||navigator.userAgent.match(/Android 3/)||navigator.userAgent.match(/Android 4\.[0-3]/))&&(navigator.userAgent.match(/Chrome/)||(c=!0)),"undefined"!=typeof a.indexedDB&&!c||"undefined"==typeof a.openDatabase){a.IDBDatabase=a.IDBDatabase||a.webkitIDBDatabase,a.IDBTransaction=a.IDBTransaction||a.webkitIDBTransaction,a.IDBCursor=a.IDBCursor||a.webkitIDBCursor,a.IDBKeyRange=a.IDBKeyRange||a.webkitIDBKeyRange,a.IDBTransaction||(a.IDBTransaction={});try{a.IDBTransaction.READ_ONLY=a.IDBTransaction.READ_ONLY||"readonly",a.IDBTransaction.READ_WRITE=a.IDBTransaction.READ_WRITE||"readwrite"}catch(d){}}else a.shimIndexedDB.__useShim()}(window,idbModules); //# sourceMappingURL=IndexedDBShim.min.js.map