You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
6.5 KiB
1 lines
6.5 KiB
(function(n){"use strict";function u(n){var t=null;switch(n){case 0:case 1:case"readwrite":case"readonly":t=n;break;default:t=r.READ_WRITE||"readwrite"}return t}var t=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,f=window.IDBKeyRange||window.webkitIDBKeyRange,i=window.IDBCursor||window.webkitIDBCursor||{},r;typeof i.PREV=="undefined"&&(i.PREV="prev");typeof i.NEXT=="undefined"&&(i.NEXT="next");r=window.IDBTransaction||window.webkitIDBTransaction;n.extend({indexedDB:function(i,r){var s,h,c,e,o;if(r&&(typeof r=="number"&&(r={version:r}),s=r.version,r.schema&&!s)){h=-1;for(c in r.schema)h=h>c?h:c;s=r.version||h}return e={request:function(t,i){return n.Deferred(function(n){try{var r=typeof t=="function"?t(i):t;r.onsuccess=function(t){n.resolveWith(r,[r.result,t])};r.onerror=function(t){n.rejectWith(r,[r.error,t])};typeof r.onblocked!="undefined"&&r.onblocked===null&&(r.onblocked=function(t){var i;try{i=r.result}catch(t){i=null}n.notifyWith(r,[i,t])});typeof r.onupgradeneeded!="undefined"&&r.onupgradeneeded===null&&(r.onupgradeneeded=function(t){n.notifyWith(r,[r.result,t])})}catch(u){u.name="exception";n.rejectWith(r,["exception",u])}})},transaction:function(n){return{objectStore:function(t){try{return e.objectStore(n.objectStore(t))}catch(i){return n.readyState!==n.DONE&&n.abort(),e.objectStore(null)}},createObjectStore:function(t,i){try{return e.objectStore(n.db.createObjectStore(t,i))}catch(r){n.readyState!==n.DONE&&n.abort()}},deleteObjectStore:function(t){try{n.db.deleteObjectStore(t)}catch(i){n.readyState!==n.DONE&&n.abort()}},abort:function(){n.abort()}}},objectStore:function(n){for(var t={},r=["add","put","get","delete","clear","count"],i=0;i<r.length;i++)t[r[i]]=function(t){return function(){return e.request(function(i){return n[t].apply(n,i)},arguments)}}(r[i]);return t.each=function(t,i,r){return e.cursor(function(){return r?n.openCursor(e.range(i),r):n.openCursor(e.range(i))},t)},t.index=function(t){return e.index(function(){return n.index(t)})},t.createIndex=function(t,i,r){return arguments.length===2&&typeof i=="string"&&(r=arguments[1],i=null),r||(r=t),e.index(function(){return n.createIndex(r,t,i)})},t.deleteIndex=function(t){return n.deleteIndex(t)},t},range:function(t){return n.isArray(t)?t.length===1?f.only(t[0]):f.bound(t[0],t[1],typeof t[2]=="undefined"?!1:t[2],typeof t[3]=="undefined"?!1:t[3]):typeof t=="undefined"?null:t},cursor:function(t,i){return n.Deferred(function(n){try{var r=typeof t=="function"?t():t;r.onsuccess=function(t){var u,f;if(!r.result){n.resolveWith(r,[null,t]);return}u={"delete":function(){return e.request(function(){return r.result["delete"]()})},update:function(n){return e.request(function(){return r.result.update(n)})},next:function(n){this.data=n},key:r.result.key,value:r.result.value};n.notifyWith(r,[u,t]);f=i.apply(r,[u]);try{f===!1?n.resolveWith(r,[null,t]):typeof f=="number"?r.result.advance.apply(r.result,[f]):u.data?r.result["continue"].apply(r.result,[u.data]):r.result["continue"]()}catch(t){n.rejectWith(r,[r.result,t])}};r.onerror=function(t){n.rejectWith(r,[r.result,t])}}catch(u){u.type="exception";n.rejectWith(r,[null,u])}})},index:function(n){try{var t=typeof n=="function"?n():n}catch(i){t=null}return{each:function(n,i,r){return e.cursor(function(){return r?t.openCursor(e.range(i),r):t.openCursor(e.range(i))},n)},eachKey:function(n,i,r){return e.cursor(function(){return r?t.openKeyCursor(e.range(i),r):t.openKeyCursor(e.range(i))},n)},get:function(n){return typeof t.get=="function"?e.request(t.get(n)):t.openCursor(e.range(n))},count:function(){if(typeof t.count=="function")return e.request(t.count());throw"Count not implemented for cursors";},getKey:function(n){return typeof t.getKey=="function"?e.request(t.getKey(n)):t.openKeyCursor(e.range(n))}}}},o=e.request(function(){return s?t.open(i,parseInt(s)):t.open(i)}),o.then(function(n){n.onversionchange=function(){r&&r.onversionchange&&r.onversionchange()!==!1||n.close()}},function(){},function(n,t){if(t&&t.type==="upgradeneeded"){if(r&&r.schema)for(var i=t.oldVersion+1;i<=t.newVersion;i++)typeof r.schema[i]=="function"&&r.schema[i].call(this,e.transaction(this.transaction));r&&typeof r.upgrade=="function"&&r.upgrade.call(this,e.transaction(this.transaction))}}),n.extend(o,{cmp:function(n,i){return t.cmp(n,i)},deleteDatabase:function(){return n.Deferred(function(n){o.then(function(r){r.close();e.request(function(){return t.deleteDatabase(i)}).then(function(t,i){n.resolveWith(this,[t,i])},function(t,i){n.rejectWith(this,[t,i])},function(t,i){n.notifyWith(this,[t,i])})},function(t,i){n.rejectWith(this,[t,i])},function(t,i){n.notifyWith(this,[t,i])})})},transaction:function(t,i){return n.isArray(t)||(t=[t]),i=u(i),n.Deferred(function(n){o.then(function(r,u){var f;try{f=r.transaction(t,i);f.onabort=f.onerror=function(t){n.rejectWith(f,[t])};f.oncomplete=function(t){n.resolveWith(f,[t])}}catch(u){u.type="exception";n.rejectWith(this,[u]);return}try{n.notifyWith(f,[e.transaction(f)])}catch(u){u.type="exception";n.rejectWith(this,[u])}},function(t,i){n.rejectWith(this,[i,t])},function(){})})},objectStore:function(f,s){function y(h){return n.Deferred(function(n){function c(t,i){try{i(t.objectStore(f)).then(function(t,i){n.resolveWith(this,[t,i])},function(t,i){n.rejectWith(this,[t,i])})}catch(r){r.name="exception";n.rejectWith(t,[r,r])}}v.transaction(f,u(s)).then(function(){},function(l,a){if(l.code===l.NOT_FOUND_ERR&&(s===!0||typeof s=="object")){var y=this.result;y.close();o=e.request(function(){return t.open(i,(parseInt(y.version,10)||1)+1)});o.then(function(t){t.onversionchange=function(){r&&r.onversionchange&&r.onversionchange()!==!1||t.close()};v.transaction(f,u(s)).then(function(){},function(t,i){n.rejectWith(this,[t,i])},function(n){c(n,h)})},function(t,i){n.rejectWith(this,[t,i])},function(t,i){if(i.type==="upgradeneeded")try{t.createObjectStore(f,s===!0?{autoIncrement:!0}:s)}catch(r){n.rejectWith(this,[r,i])}})}else n.rejectWith(this,[l,a])},function(n){c(n,h)})})}function p(n,t){return y(function(i){return i[n].apply(i,t)})}function h(n,t,i){return y(function(r){var u=r.index(t);return u[n].apply(u[n],i)})}for(var v=this,l={},a=["add","delete","get","put","clear","count","each"],c=0;c<a.length;c++)l[a[c]]=function(n){return function(){return p(n,arguments)}}(a[c]);return l.index=function(n){return{each:function(t,i,r){return h("each",n,[t,i,r])},eachKey:function(t,i,r){return h("eachKey",n,[t,i,r])},get:function(t){return h("get",n,[t])},count:function(){return h("count",n,[])},getKey:function(t){return h("getKey",n,[t])}}},l}})}});n.indexedDB.IDBCursor=i;n.indexedDB.IDBTransaction=r;n.idb=n.indexedDB})(jQuery);
|