Current Path : /var/www/u0635749/data/www/hobbyclick.ru/public/bitrix/js/main/core/ |
Current File : /var/www/u0635749/data/www/hobbyclick.ru/public/bitrix/js/main/core/core_db_indexeddb.min.js |
(function(e){if(e.BX.indexedDB)return;var r=e.BX;r.indexedDB=function(o){var t=e.indexedDB||e.mozIndexedDB||e.webkitIndexedDB||e.msIndexedDB;e.IDBTransaction=e.IDBTransaction||e.webkitIDBTransaction||e.msIDBTransaction;e.IDBKeyRange=e.IDBKeyRange||e.webkitIDBKeyRange||e.msIDBKeyRange;o.version=parseInt(o.version);o.version=!o.version?1:o.version;var a=new r.Promise;var n={};if(typeof t=="undefined"||typeof e.IDBTransaction=="undefined"||typeof e.IDBKeyRange=="undefined"){n={errorCode:"bxNotSupported",errorName:"bxNotSupported",errorMessage:"IndexedDB is not supported in current browser."};if(typeof o.error=="function"){o.error(n)}a.reject(n);return a}if(typeof o!="object"||!o.name||!o.scheme){n={errorCode:"bxParamsError",errorName:"bxParamsError",errorMessage:"Required parameters not specified."};if(typeof o.error=="function"){o.error(n)}a.reject(n);return a}var s=t.open(o.name,o.version);if(!s){n={errorCode:"bxOpenError",errorName:"bxOpenError",errorMessage:"An error occurred while opening the database."};if(typeof o.error=="function"){o.error(n)}a.reject(n);return a}s.onsuccess=function(e){if(typeof o.success=="function"){o.success(e.target.result)}a.fulfill(e.target.result)};s.onerror=function(e){var r={errorCode:e.target.error.code,errorName:e.target.error.name,errorMessage:e.target.error.message};if(typeof o.error=="function"){o.error(r)}a.reject(r)};s.onupgradeneeded=function(e){if(typeof o.scheme!="undefined"){var r=e.target.result;var t=null;var a=null;var n=o.scheme.length;var s,i=null;for(s=0;s<n;s++){t=o.scheme[s];if(typeof t=="object"&&!r.objectStoreNames.contains(t.name)){a=r.createObjectStore(t.name,{keyPath:typeof t.keyPath!="undefined"&&t.keyPath?t.keyPath:undefined,autoIncrement:typeof t.autoIncrement!="undefined"&&!!t.autoIncrement});if(typeof t.indexes!="undefined"){for(i=0;i<t.indexes.length;i++){a.createIndex(t.indexes[i].name,t.indexes[i].keyPath,{unique:!!t.indexes[i].unique})}}}}var c=null;var u=r.objectStoreNames.length;for(s=0;s<u;s++){if(!r.objectStoreNames[s])continue;c=false;for(i=0;i<n;i++){t=o.scheme[i];if(t.name==r.objectStoreNames[s]){c=true;break}}if(!c){r.deleteObjectStore(r.objectStoreNames[s])}}}};return a};r.indexedDB.checkDatabaseObject=function(e){var r={error:null,result:false};if(!e||typeof e!="object"||!(e instanceof IDBDatabase)){r.error={errorCode:"bxDataBaseInvalidFormat",errorName:"bxDataBaseInvalidFormat",errorMessage:'The given "dataBase" object is invalid format for IndexedDB.'}}else{r.result=true}return r};r.indexedDB.getObjectStore=function(e,o,t){t=t||"readonly";var a={error:null,transaction:null};var n=r.indexedDB.checkDatabaseObject(e);if(n.error){return a}try{var s=e.transaction(o,t);s.onsuccess=function(e){};s.onerror=function(e){console.log("IndexedDB Transaction error",e)};a.transaction=s.objectStore(o);return a}catch(i){a.error={errorCode:i.code,errorName:i.name,errorMessage:i.message};return a}};r.indexedDB.addValue=function(e,o,t,a){a=a||{};var n=new r.Promise;var s=r.indexedDB.getObjectStore(e,o,"readwrite");if(s.error){s.error.params={dataBase:e,storeName:o,value:t};if(typeof a.error=="function"){a.error(s.error)}n.reject(s.error);return n}var i=null;try{i=s.transaction.add(t)}catch(c){var u={errorCode:c.code?c.code:c.name,errorName:c.name,errorMessage:c.message,params:{dataBase:e,storeName:o,value:t}};n.reject(u);return n}i.onerror=function(r){var s={errorCode:r.target.error.code,errorName:r.target.error.name,errorMessage:r.target.error.message,params:{dataBase:e,storeName:o,value:t}};if(typeof a.error=="function"){a.error(s)}n.reject(s)};i.onsuccess=function(e){if(typeof a.success=="function"){a.success(e.target.result)}n.fulfill(e.target.result)};return n};r.indexedDB.updateValue=function(e,o,t,a){a=a||{};var n=new r.Promise;var s=r.indexedDB.getObjectStore(e,o,"readwrite");if(s.error){s.error.params={dataBase:e,storeName:o,value:t};if(typeof a.error=="function"){a.error(s.error)}n.reject(s.error);return n}var i=null;try{i=s.transaction.put(t)}catch(c){var u={errorCode:c.code?c.code:c.name,errorName:c.name,errorMessage:c.message,params:{dataBase:e,storeName:o,value:t}};n.reject(u);return n}i.onerror=function(r){var s={errorCode:r.target.error.code,errorName:r.target.error.name,errorMessage:r.target.error.message,params:{dataBase:e,storeName:o,value:t}};if(typeof a.error=="function"){a.error(s)}n.reject(s)};i.onsuccess=function(e){if(typeof a.success=="function"){a.success(e.target.result)}n.fulfill(e.target.result)};return n};r.indexedDB.deleteValue=function(e,o,t,a){a=a||{};var n=new r.Promise;var s=r.indexedDB.getObjectStore(e,o,"readwrite");if(s.error){s.error.params={dataBase:e,storeName:o,primaryId:t};if(typeof a.error=="function"){a.error(s.error)}n.reject(s.error);return n}var i=null;try{i=s.transaction.delete(t)}catch(c){var u={errorCode:c.code?c.code:c.name,errorName:c.name,errorMessage:c.message,params:{dataBase:e,storeName:o,primaryId:t}};n.reject(u);return n}i.onerror=function(r){var s={errorCode:r.target.error.code,errorName:r.target.error.name,errorMessage:r.target.error.message,params:{dataBase:e,storeName:o,primaryId:t}};if(typeof a.error=="function"){a.error(s)}n.reject(s)};i.onsuccess=function(){if(typeof a.success=="function"){a.success(true)}n.fulfill(true)};return n};r.indexedDB.deleteValueByIndex=function(e,o,t,a,n){n=n||{};var s=new r.Promise;r.indexedDB.getValueByIndex(e,o,t,a).then(function(i){r.indexedDB.deleteValue(e,o,i.id).then(function(){if(typeof n.success=="function"){n.success(true)}s.fulfill(true)}).catch(function(r){r.params={dataBase:e,storeName:o,indexName:t,indexValue:a};if(typeof n.error=="function"){n.error(r)}s.reject(r)})}).catch(function(r){r.params={dataBase:e,storeName:o,indexName:t,indexValue:a};if(typeof n.error=="function"){n.error(r)}s.reject(r)});return s};r.indexedDB.getValue=function(e,o,t,a){a=a||{};var n=new r.Promise;var s=r.indexedDB.getObjectStore(e,o,"readwrite");if(s.error){s.error.params={dataBase:e,storeName:o,primaryId:t};if(typeof a.error=="function"){a.error(s.error)}n.reject(s.error);return n}var i=null;try{i=s.transaction.get(t)}catch(c){var u={errorCode:c.code?c.code:c.name,errorName:c.name,errorMessage:c.message,params:{dataBase:e,storeName:o,primaryId:t}};n.reject(u);return n}i.onerror=function(r){var s={errorCode:r.target.error.code,errorName:r.target.error.name,errorMessage:r.target.error.message,params:{dataBase:e,storeName:o,primaryId:t}};if(typeof a.error=="function"){a.error(s)}n.reject(s)};i.onsuccess=function(r){if(!r.target.result){var s={errorCode:"bxElementNotFound",errorName:"bxElementNotFound",errorMessage:"Element with id '"+t+"' not found",params:{dataBase:e,storeName:o,primaryId:t}};if(typeof a.error=="function"){a.error(s)}n.reject(s);return n}if(typeof a.success=="function"){a.success(r.target.result)}n.fulfill(r.target.result)};return n};r.indexedDB.getValueByIndex=function(e,o,t,a,n){n=n||{};var s=new r.Promise;var i=r.indexedDB.getObjectStore(e,o,"readwrite");if(i.error){i.error.params={dataBase:e,storeName:o,indexName:t,indexValue:a};if(typeof n.error=="function"){n.error(i.error)}s.reject(i.error);return s}var c=null;try{c=i.transaction.index(t).get(a)}catch(u){var f={errorCode:u.code?u.code:u.name,errorName:u.name,errorMessage:u.message,params:{dataBase:e,storeName:o,indexName:t,indexValue:a}};s.reject(f);return s}c.onerror=function(r){var i={errorCode:r.target.error.code,errorName:r.target.error.name,errorMessage:r.target.error.message,params:{dataBase:e,storeName:o,indexName:t,indexValue:a}};if(typeof n.error=="function"){n.error(i)}s.reject(i)};c.onsuccess=function(r){if(!r.target.result){var i={errorCode:"bxElementNotFound",errorName:"bxElementNotFound",errorMessage:"Element with indexName '"+t+"' and indexValue '"+a+"' not found",params:{dataBase:e,storeName:o,indexName:t,indexValue:a}};if(typeof n.error=="function"){n.error(i)}s.reject(i);return s}if(typeof n.success=="function"){n.success(r.target.result)}s.fulfill(r.target.result)};return s};r.indexedDB.openCursor=function(o,t,a,n){a=a||{};n=n||{};var s=new r.Promise;var i=null;var c=r.indexedDB.getObjectStore(o,t);if(c.error){if(typeof n.error=="function"){n.error(c.error)}s.reject(c.error);return s}if(typeof a.lower!="undefined"){if(typeof a.upper!="undefined"){i=e.IDBKeyRange.bound(a.lower,a.upper,!!a.lowerOpen,!!a.upperOpen)}else{i=e.IDBKeyRange.lowerBound(a.lower,!!a.lowerOpen)}}else if(typeof a.upper!="undefined"){i=e.IDBKeyRange.upperBound(a.upper,!!a.upperOpen)}if(typeof n.filter!="function"){n.filter=function(e,r){return"continue"}}var u=c.transaction.openCursor(i);u.onerror=function(e){var r={errorCode:e.target.error.code,errorName:e.target.error.name,errorMessage:e.target.error.message};if(typeof n.error=="function"){n.error(r)}s.reject(r);return s};var f=[];u.onsuccess=function(e){var r=e.target.result;if(r){var o="continue";if(typeof n.filter=="function"){o=n.filter(r.key,r.value)}if(o=="break"){if(typeof n.success=="function"){n.callback(f)}s.fulfill(f);return s}if(o!="skip"){f.push({key:r.key,value:r.value})}if(o=="stop"){if(typeof n.success=="function"){n.callback(f)}s.fulfill(f);return s}else{r["continue"]()}}else{if(typeof n.success=="function"){n.callback(f)}s.fulfill(f);return s}};return s};r.indexedDB.count=function(e,o,t){t=t||{};var a=new r.Promise;var n=r.indexedDB.getObjectStore(e,o);if(n.error){if(typeof t.error=="function"){t.error(n.error)}a.reject(n.error);return a}var s=n.transaction.count();s.onerror=function(e){var r={errorCode:e.target.error.code,errorName:e.target.error.name,errorMessage:e.target.error.message};if(typeof t.error=="function"){t.error(r)}a.reject(r)};s.onsuccess=function(e){if(typeof t.success=="function"){t.success(e.target.result)}a.fulfill(e.target.result)};return a};r.indexedDB.clearObjectStore=function(e,o,t){t=t||{};var a=new r.Promise;var n=r.indexedDB.getObjectStore(e,o,"readwrite");if(n.error){if(typeof t.error=="function"){t.error(n.error)}a.reject(n.error);return a}try{var s=n.transaction.clear()}catch(i){var c={errorCode:i.code,errorName:i.name,errorMessage:i.message};if(typeof t.error=="function"){t.error(c)}a.reject(c);return a}s.onerror=function(e){var r={errorCode:e.target.error.code,errorName:e.target.error.name,errorMessage:e.target.error.message};if(typeof t.error=="function"){t.error(r)}a.reject(r)};s.onsuccess=function(){if(typeof t.success=="function"){t.success(true)}a.fulfill(true)};return a};r.indexedDB.deleteDatabase=function(o,t,a){a=a||{};var n=new r.Promise;var s=e.indexedDB||e.mozIndexedDB||e.webkitIndexedDB||e.msIndexedDB;if(t!==null){var i=r.indexedDB.checkDatabaseObject(t);if(i.result){t.close();t=null}else{var c={errorCode:"bxDataBaseInvalidFormat",errorName:"bxDataBaseInvalidFormat",errorMessage:'The given "openedDataBase" object is invalid format for IndexedDB. You need specify link to opened DB for correct delete.'};if(typeof a.error=="function"){a.error(c)}n.reject(c);return n}}var u=s.deleteDatabase(o);u.onerror=function(e){var r={errorCode:e.target.error.code,errorName:e.target.error.name,errorMessage:e.target.error.message};if(typeof a.error=="function"){a.error(r)}n.reject(r)};u.onsuccess=function(){if(typeof a.success=="function"){a.success(true)}n.fulfill(true)};return n}})(window); //# sourceMappingURL=core_db_indexeddb.map.js