geno/wp-content/plugins/cartflows/assets/min-js/rest-api.min.js

1 line
1.7 KiB
JavaScript
Raw Normal View History

2024-02-01 17:24:18 +05:30
!function(i){var s={timeout:3e5,data:{},remove(e){delete s.data[e]},exist(e){return!!s.data[e]&&(new Date).getTime()-s.data[e]._<s.timeout},get(e){return s.data[e].data},set(e,t,a){s.remove(e),s.data[e]={_:(new Date).getTime(),data:t},a&&"function"==typeof a&&a(t)}};i.ajaxPrefilter(function(a,e,t){if("cartflows"===a.author){const r=e.complete||i.noop,o=e.url;a.beforeSend=function(){var e;return!s.exist(o)||(e=s.get(o),CartFlowsAPI._api_cached_request(e),!1)},a.complete=function(e,t){t={args:a.args,items:e.responseText?JSON.parse(e.responseText):"",items_count:e.getResponseHeader("x-wp-total")||0,callback:a.callback,status:t,XHR:e};s.set(o,t,r)}}}),CartFlowsAPI={_log(e,t){CartFlowsImportVars.debug&&"table"!==t&&(new Date).toLocaleTimeString()},_api_url:CartFlowsImportVars.server_rest_url,_api_cached_request(e){CartFlowsAPI._log(s.data,"table"),CartFlowsAPI._log("Current time "+(new Date).getTime()),CartFlowsAPI._log("Cache expired in "+parseInt(s.timeout)/1e3+" seconds."),void 0!==e.args.trigger&&""!==e.args.trigger&&i(document).trigger(e.args.trigger,[e]),e.callback&&"function"==typeof e.callback&&e.callback(e)},_api_request(o,s){const a={url:CartFlowsAPI._api_url+o.slug,args:o,callback:s,headers:CartFlowsImportVars.headers,author:"cartflows"};i.ajax(a).done(function(e,t,a){var r;"success"===t&&a.getResponseHeader("x-wp-total")?(r={args:o,items:e,items_count:a.getResponseHeader("x-wp-total")||0,callback:s,status:t,XHR:a},void 0!==o.trigger&&""!==o.trigger&&i(document).trigger(o.trigger,[r])):i(document).trigger("cartflows-api-request-error"),s&&"function"==typeof s&&s(r)}).fail(function(e,t){i(document).trigger("cartflows-api-request-fail",[a,e,t])}).always(function(){i(document).trigger("cartflows-api-request-always")})}}}(jQuery);