mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 17:21:39 +09:00
Merge pull request #2570 from kijin/pr/async-ajax
Rhymix.ajax()에서 callback 방식과 Promise 방식을 동시 지원 #2565
This commit is contained in:
commit
10677c1945
4 changed files with 227 additions and 184 deletions
|
|
@ -757,13 +757,20 @@ class HTMLDisplayHandler
|
|||
'plugins/cookie/js.cookie.min.js',
|
||||
'plugins/blankshield/blankshield.min.js',
|
||||
'plugins/uri/URI.min.js',
|
||||
'x.js',
|
||||
'common.js',
|
||||
'js_app.js',
|
||||
'xml_handler.js',
|
||||
'xml_js_filter.js',
|
||||
);
|
||||
|
||||
if (str_contains($_SERVER['HTTP_USER_AGENT'] ?? '', 'Trident/'))
|
||||
{
|
||||
$original_file_list[] = 'polyfills/formdata.min.js';
|
||||
$original_file_list[] = 'polyfills/promise.min.js';
|
||||
}
|
||||
|
||||
$original_file_list[] = 'x.js';
|
||||
$original_file_list[] = 'common.js';
|
||||
$original_file_list[] = 'js_app.js';
|
||||
$original_file_list[] = 'xml_handler.js';
|
||||
$original_file_list[] = 'xml_js_filter.js';
|
||||
|
||||
if(config('view.minify_scripts') === 'none')
|
||||
{
|
||||
Context::loadFile(array('./common/js/jquery-' . $jquery_version . '.js', 'head', '', -1800000000), true);
|
||||
|
|
|
|||
|
|
@ -262,14 +262,37 @@ Rhymix.isSameHost = function(url) {
|
|||
* Redirect to a URL, but reload instead if the target is the same as the current page
|
||||
*
|
||||
* @param string url
|
||||
* @param int delay
|
||||
* @return void
|
||||
*/
|
||||
Rhymix.redirectToUrl = function(url) {
|
||||
if (this.isCurrentUrl(url)) {
|
||||
window.location.href = url;
|
||||
window.location.reload();
|
||||
Rhymix.redirectToUrl = function(url, delay) {
|
||||
const callback = function() {
|
||||
if (Rhymix.isCurrentUrl(url)) {
|
||||
window.location.href = url;
|
||||
window.location.reload();
|
||||
} else {
|
||||
window.location.href = url;
|
||||
}
|
||||
};
|
||||
if (delay) {
|
||||
this.pendingRedirect = setTimeout(callback, delay);
|
||||
} else {
|
||||
window.location.href = url;
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Cancel any pending redirect
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
Rhymix.cancelPendingRedirect = function() {
|
||||
if (this.pendingRedirect) {
|
||||
clearTimeout(this.pendingRedirect);
|
||||
this.pendingRedirect = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -398,16 +421,26 @@ Rhymix.modal.close = function(id) {
|
|||
*
|
||||
* @param string action
|
||||
* @param object params
|
||||
* @param function success
|
||||
* @param function error
|
||||
* @return void
|
||||
* @param function callback_success
|
||||
* @param function callback_error
|
||||
* @return Promise
|
||||
*/
|
||||
Rhymix.ajax = function(action, params, success, error) {
|
||||
Rhymix.ajax = function(action, params, callback_success, callback_error) {
|
||||
|
||||
// Extract module and act
|
||||
let isFormData = params instanceof FormData;
|
||||
let module, act;
|
||||
if (!action) {
|
||||
let module, act, url, promise;
|
||||
if (action) {
|
||||
if (typeof action === 'string' && action.match(/^[a-z0-9_]+\.[a-z0-9_]+$/i)) {
|
||||
let parts = action.split('.');
|
||||
params = params || {};
|
||||
params.module = module = parts[0];
|
||||
params.act = act = parts[1];
|
||||
} else {
|
||||
url = action;
|
||||
action = null;
|
||||
}
|
||||
} else {
|
||||
if (isFormData) {
|
||||
module = params.get('module');
|
||||
act = params.get('act');
|
||||
|
|
@ -421,26 +454,22 @@ Rhymix.ajax = function(action, params, success, error) {
|
|||
} else {
|
||||
action = null;
|
||||
}
|
||||
} else {
|
||||
action = action.split('.');
|
||||
params = params || {};
|
||||
params.module = module = action[0];
|
||||
params.act = act = action[1];
|
||||
action = action.join('.');
|
||||
}
|
||||
|
||||
// Add action to URL if the current rewrite level supports it
|
||||
let url = this.URI(window.request_uri).pathname() + 'index.php';
|
||||
if (act) {
|
||||
url = url + '?act=' + act;
|
||||
if (!url) {
|
||||
url = this.URI(window.request_uri).pathname() + 'index.php';
|
||||
if (act) {
|
||||
url = url + '?act=' + act;
|
||||
}
|
||||
/*
|
||||
if (this.getRewriteLevel() >= 2 && action !== null) {
|
||||
url = url + '_' + action.replace('.', '/');
|
||||
} else {
|
||||
url = url + 'index.php';
|
||||
}
|
||||
*/
|
||||
}
|
||||
/*
|
||||
if (this.getRewriteLevel() >= 2 && action !== null) {
|
||||
url = url + action.replace('.', '/');
|
||||
} else {
|
||||
url = url + 'index.php';
|
||||
}
|
||||
*/
|
||||
|
||||
// Add a CSRF token to the header, and remove it from the parameters
|
||||
const headers = {
|
||||
|
|
@ -453,175 +482,137 @@ Rhymix.ajax = function(action, params, success, error) {
|
|||
delete params._rx_csrf_token;
|
||||
}
|
||||
|
||||
// Generate AJAX parameters
|
||||
const args = {
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
url: url,
|
||||
data: isFormData ? params : JSON.stringify(params),
|
||||
contentType: isFormData ? false : 'application/json; charset=UTF-8',
|
||||
processData: false,
|
||||
headers: headers,
|
||||
success: function(data, textStatus, xhr) {
|
||||
Rhymix._ajaxSuccessHandler(xhr, textStatus, action, data, params, success, error);
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Rhymix._ajaxErrorHandler(xhr, textStatus, action, url, params, success, error);
|
||||
}
|
||||
};
|
||||
// Create and return a Promise for this AJAX request
|
||||
return promise = new Promise(function(resolve, reject) {
|
||||
|
||||
// Send the AJAX request
|
||||
try {
|
||||
$.ajax(args);
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
}
|
||||
};
|
||||
// Define the success wrapper.
|
||||
const successWrapper = function(data, textStatus, xhr) {
|
||||
|
||||
/**
|
||||
* Default success handler for AJAX requests
|
||||
*
|
||||
* @param object xhr
|
||||
* @param string textStatus
|
||||
* @param string action
|
||||
* @param object data
|
||||
* @param object params
|
||||
* @param function success
|
||||
* @param function errror
|
||||
* @return void
|
||||
*/
|
||||
Rhymix._ajaxSuccessHandler = function(xhr, textStatus, action, data, params, success, error) {
|
||||
|
||||
// Add debug information.
|
||||
if (data._rx_debug) {
|
||||
data._rx_debug.page_title = "AJAX : " + action;
|
||||
if (this.addDebugData) {
|
||||
this.addDebugData(data._rx_debug);
|
||||
} else {
|
||||
this.pendingDebugData.push(data._rx_debug);
|
||||
}
|
||||
}
|
||||
|
||||
// If the response contains a Rhymix error code, display the error message.
|
||||
if (typeof data.error !== 'undefined' && data.error != 0) {
|
||||
|
||||
// If an error callback is defined, call it. Abort if it returns false.
|
||||
if ($.isFunction(error) && error(data, xhr) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If an error message was supplied, display it.
|
||||
if (data.message) {
|
||||
let msg = data.message.replace(/\\n/g, "\n");
|
||||
if (data.errorDetail) {
|
||||
msg += "\n\n" + data.errorDetail;
|
||||
// Add debug information.
|
||||
if (data._rx_debug) {
|
||||
data._rx_debug.page_title = "AJAX : " + action;
|
||||
if (Rhymix.addDebugData) {
|
||||
Rhymix.addDebugData(data._rx_debug);
|
||||
} else {
|
||||
Rhymix.pendingDebugData.push(data._rx_debug);
|
||||
}
|
||||
}
|
||||
alert(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
// Rhymix should never return an error code without a message, but if someone does, we handle it here.
|
||||
let msg = 'AJAX error: ' + (action || 'form submission') + "\n\n" + xhr.responseText;
|
||||
if (msg.length > 1000) {
|
||||
msg = msg.substring(0, 1000) + '...';
|
||||
}
|
||||
console.error(msg.trim().replace(/\n+/g, "\n"));
|
||||
if (this.showAjaxErrors.indexOf('ALL') >= 0 || this.showAjaxErrors.indexOf(xhr.status) >= 0) {
|
||||
alert(msg.trim());
|
||||
}
|
||||
return;
|
||||
}
|
||||
// If the response contains a Rhymix error code, display the error message.
|
||||
if (typeof data.error !== 'undefined' && data.error != 0) {
|
||||
return errorWrapper(data, textStatus, xhr);
|
||||
}
|
||||
|
||||
// If a success callback was defined, call it.
|
||||
if ($.isFunction(success)) {
|
||||
success(data, xhr);
|
||||
return;
|
||||
}
|
||||
// If a success callback was defined, call it.
|
||||
if (typeof callback_success === 'function') {
|
||||
callback_success(data, xhr);
|
||||
resolve(data);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the response contains a redirect URL, follow the redirect.
|
||||
if (data.redirect_url) {
|
||||
this.redirectToUrl(data.redirect_url.replace(/&/g, '&'));
|
||||
return;
|
||||
}
|
||||
};
|
||||
// If the response contains a redirect URL, follow the redirect.
|
||||
// This can be canceled by Rhymix.cancelPendingRedirect() within 100 milliseconds.
|
||||
if (data.redirect_url) {
|
||||
Rhymix.redirectToUrl(data.redirect_url.replace(/&/g, '&'), 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default error handler for AJAX requests
|
||||
*
|
||||
* @param object xhr
|
||||
* @param string textStatus
|
||||
* @param string action
|
||||
* @param string url
|
||||
* @param object params
|
||||
* @param function success
|
||||
* @param function errror
|
||||
* @return void
|
||||
*/
|
||||
Rhymix._ajaxErrorHandler = function(xhr, textStatus, action, url, params, success, error) {
|
||||
// Resolve the promise with the response data.
|
||||
resolve(data);
|
||||
};
|
||||
|
||||
// If the user is navigating away, don't do anything.
|
||||
if (xhr.status == 0 && this.unloading) {
|
||||
return;
|
||||
}
|
||||
// Define the error wrapper.
|
||||
const errorWrapper = function(data, textStatus, xhr) {
|
||||
|
||||
// If the response contains valid JSON, call the success callback instead.
|
||||
if (xhr.status >= 400 && xhr.responseText) {
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(xhr.responseText);
|
||||
} catch (e) { }
|
||||
if (data && typeof data.error !== 'undefined') {
|
||||
this._ajaxSuccessHandler(xhr, textStatus, action, data, params, success, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// If an error callback is defined, call it.
|
||||
// The promise will still be rejected, but silently.
|
||||
if (typeof callback_error === 'function') {
|
||||
callback_error(data, xhr);
|
||||
promise.catch(function(dummy) { });
|
||||
let dummy = new Error('Rhymix.ajax() error already handled by callback function');
|
||||
dummy._rx_ajax_error = true;
|
||||
dummy.cause = data;
|
||||
dummy.details = '';
|
||||
dummy.xhr = xhr;
|
||||
reject(dummy);
|
||||
return;
|
||||
}
|
||||
|
||||
// If an error callback is defined, call it. Abort if it returns false.
|
||||
if ($.isFunction(error)) {
|
||||
let fakedata = { error: -3, message: textStatus };
|
||||
if (error(fakedata, xhr) === false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Otherwise, generate a generic error message.
|
||||
let error_message = 'AJAX error: ' + (action || 'form submission');
|
||||
let error_details = '';
|
||||
if (data.error != 0 && data.message) {
|
||||
error_message = data.message.replace(/\\n/g, "\n");
|
||||
if (data.errorDetail) {
|
||||
error_details = data.errorDetail;
|
||||
}
|
||||
} else if (xhr.status == 0) {
|
||||
error_details = 'Connection failed: ' + url + "\n\n" + (xhr.responseText || '');
|
||||
} else {
|
||||
error_details = (xhr.responseText || '');
|
||||
}
|
||||
if (error_details.length > 1000) {
|
||||
error_details = error_details.substring(0, 1000) + '...';
|
||||
}
|
||||
|
||||
// Otherwise, generate a simple error message.
|
||||
let error_info, msg;
|
||||
if (xhr.status == 0) {
|
||||
error_info = 'Connection failed: ' + url + "\n\n" + (xhr.responseText || '');
|
||||
} else {
|
||||
error_info = 'Response code: ' + xhr.status + "\n\n" + (xhr.responseText || '');
|
||||
}
|
||||
msg = 'AJAX error: ' + (action || 'form submission') + "\n\n" + error_info;
|
||||
if (msg.length > 1000) {
|
||||
msg = msg.substring(0, 1000) + '...';
|
||||
}
|
||||
// Reject the promise with an error object.
|
||||
// If uncaught, this will be handled by the 'unhandledrejection' event listener.
|
||||
const err = new Error(error_message);
|
||||
err._rx_ajax_error = true;
|
||||
err.cause = data;
|
||||
err.details = error_details;
|
||||
err.xhr = xhr;
|
||||
reject(err);
|
||||
};
|
||||
|
||||
// Print the error message.
|
||||
console.error(msg.trim().replace(/\n+/g, "\n"));
|
||||
if (this.showAjaxErrors.indexOf('ALL') >= 0 || this.showAjaxErrors.indexOf(xhr.status) >= 0) {
|
||||
alert(msg.trim());
|
||||
}
|
||||
// Pass off to jQuery with another wrapper around the success and error wrappers.
|
||||
// This allows us to handle HTTP 400+ error codes with valid JSON responses.
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
url: url,
|
||||
data: isFormData ? params : JSON.stringify(params),
|
||||
contentType: isFormData ? false : 'application/json; charset=UTF-8',
|
||||
processData: false,
|
||||
headers: headers,
|
||||
success: successWrapper,
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
if (xhr.status == 0 && Rhymix.unloading) {
|
||||
return;
|
||||
}
|
||||
if (xhr.status >= 400 && xhr.responseText) {
|
||||
try {
|
||||
let data = JSON.parse(xhr.responseText);
|
||||
if (data) {
|
||||
successWrapper(data, textStatus, xhr);
|
||||
return;
|
||||
}
|
||||
} catch (e) { }
|
||||
}
|
||||
errorWrapper({ error: 0, message: textStatus }, textStatus, xhr);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Submit a form using AJAX instead of navigating away
|
||||
*
|
||||
* @param HTMLElement form
|
||||
* @param function success
|
||||
* @param function error
|
||||
* @param function callback_success
|
||||
* @param function callback_error
|
||||
* @return void
|
||||
*/
|
||||
Rhymix.ajaxForm = function(form, success, error) {
|
||||
Rhymix.ajaxForm = function(form, callback_success, callback_error) {
|
||||
const $form = $(form);
|
||||
// Get success and error callback functions.
|
||||
if (typeof success === 'undefined') {
|
||||
success = $form.data('callbackSuccess');
|
||||
if (success && $.isFunction(success)) {
|
||||
if (typeof callback_success === 'undefined') {
|
||||
callback_success = $form.data('callbackSuccess');
|
||||
if (callback_success && typeof callback_success === 'function') {
|
||||
// no-op
|
||||
} else if (success && window[success] && $.isFunction(window[success])) {
|
||||
success = window[success];
|
||||
} else if (callback_success && window[callback_success] && typeof window[callback_success] === 'function') {
|
||||
callback_success = window[callback_success];
|
||||
} else {
|
||||
success = function(data) {
|
||||
callback_success = function(data) {
|
||||
if (data.message && data.message !== 'success') {
|
||||
alert(data.message);
|
||||
}
|
||||
|
|
@ -631,17 +622,17 @@ Rhymix.ajaxForm = function(form, success, error) {
|
|||
};
|
||||
}
|
||||
}
|
||||
if (typeof error === 'undefined') {
|
||||
error = $form.data('callbackError');
|
||||
if (error && $.isFunction(error)) {
|
||||
if (typeof callback_error === 'undefined') {
|
||||
callback_error = $form.data('callbackError');
|
||||
if (callback_error && typeof callback_error === 'function') {
|
||||
// no-op
|
||||
} else if (error && window[error] && $.isFunction(window[error])) {
|
||||
error = window[error];
|
||||
} else if (callback_error && window[callback_error] && typeof window[callback_error] === 'function') {
|
||||
callback_error = window[callback_error];
|
||||
} else {
|
||||
error = null;
|
||||
callback_error = null;
|
||||
}
|
||||
}
|
||||
this.ajax(null, new FormData($form[0]), success, error);
|
||||
this.ajax(null, new FormData($form[0]), callback_success, callback_error);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1101,6 +1092,20 @@ window.addEventListener('beforeunload', function() {
|
|||
Rhymix.unloading = true;
|
||||
});
|
||||
|
||||
// General handler for unhandled Promise rejections
|
||||
window.addEventListener('unhandledrejection', function(event) {
|
||||
if (event.reason && typeof event.reason['_rx_ajax_error'] === 'boolean') {
|
||||
event.preventDefault();
|
||||
const error_message = event.reason.message.trim();
|
||||
const error_details = event.reason.details || '';
|
||||
const error_xhr = event.reason.xhr || {};
|
||||
console.error(error_message.replace(/\n+/g, "\n" + error_details));
|
||||
if (Rhymix.showAjaxErrors.indexOf('ALL') >= 0 || Rhymix.showAjaxErrors.indexOf(error_xhr.status) >= 0) {
|
||||
alert(error_message.trim() + (error_details ? ("\n\n" + error_details) : ''));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// General handler for popstate events
|
||||
window.addEventListener('popstate', function(event) {
|
||||
// Close modal if it is open
|
||||
|
|
@ -1122,6 +1127,15 @@ window.addEventListener('popstate', function(event) {
|
|||
}
|
||||
});
|
||||
|
||||
// Fix for browsers that don't support the unhandledrejection event
|
||||
if (typeof Promise._unhandledRejectionFn !== 'undefined') {
|
||||
Promise._unhandledRejectionFn = function(error) {
|
||||
if (error['_rx_ajax_error']) {
|
||||
alert(error.message.trim());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* =================
|
||||
* jQuery extensions
|
||||
|
|
|
|||
21
common/js/polyfills/formdata.min.js
vendored
Normal file
21
common/js/polyfills/formdata.min.js
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/*! formdata-polyfill. MIT License. Jimmy W?rting <https://jimmy.warting.se/opensource> */
|
||||
;(function(){var h;function l(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}}var m="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a};
|
||||
function n(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var q=n(this);function r(a,b){if(b)a:{var c=q;a=a.split(".");for(var d=0;d<a.length-1;d++){var e=a[d];if(!(e in c))break a;c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&m(c,a,{configurable:!0,writable:!0,value:b})}}
|
||||
r("Symbol",function(a){function b(f){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new c(d+(f||"")+"_"+e++,f)}function c(f,g){this.A=f;m(this,"description",{configurable:!0,writable:!0,value:g})}if(a)return a;c.prototype.toString=function(){return this.A};var d="jscomp_symbol_"+(1E9*Math.random()>>>0)+"_",e=0;return b});
|
||||
r("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;c<b.length;c++){var d=q[b[c]];"function"===typeof d&&"function"!=typeof d.prototype[a]&&m(d.prototype,a,{configurable:!0,writable:!0,value:function(){return u(l(this))}})}return a});function u(a){a={next:a};a[Symbol.iterator]=function(){return this};return a}
|
||||
function v(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):{next:l(a)}}var w;if("function"==typeof Object.setPrototypeOf)w=Object.setPrototypeOf;else{var y;a:{var z={a:!0},A={};try{A.__proto__=z;y=A.a;break a}catch(a){}y=!1}w=y?function(a,b){a.__proto__=b;if(a.__proto__!==b)throw new TypeError(a+" is not extensible");return a}:null}var B=w;function C(){this.m=!1;this.j=null;this.v=void 0;this.h=1;this.u=this.C=0;this.l=null}
|
||||
function D(a){if(a.m)throw new TypeError("Generator is already running");a.m=!0}C.prototype.o=function(a){this.v=a};C.prototype.s=function(a){this.l={D:a,F:!0};this.h=this.C||this.u};C.prototype.return=function(a){this.l={return:a};this.h=this.u};function E(a,b){a.h=3;return{value:b}}function F(a){this.g=new C;this.G=a}F.prototype.o=function(a){D(this.g);if(this.g.j)return G(this,this.g.j.next,a,this.g.o);this.g.o(a);return H(this)};
|
||||
function I(a,b){D(a.g);var c=a.g.j;if(c)return G(a,"return"in c?c["return"]:function(d){return{value:d,done:!0}},b,a.g.return);a.g.return(b);return H(a)}F.prototype.s=function(a){D(this.g);if(this.g.j)return G(this,this.g.j["throw"],a,this.g.o);this.g.s(a);return H(this)};
|
||||
function G(a,b,c,d){try{var e=b.call(a.g.j,c);if(!(e instanceof Object))throw new TypeError("Iterator result "+e+" is not an object");if(!e.done)return a.g.m=!1,e;var f=e.value}catch(g){return a.g.j=null,a.g.s(g),H(a)}a.g.j=null;d.call(a.g,f);return H(a)}function H(a){for(;a.g.h;)try{var b=a.G(a.g);if(b)return a.g.m=!1,{value:b.value,done:!1}}catch(c){a.g.v=void 0,a.g.s(c)}a.g.m=!1;if(a.g.l){b=a.g.l;a.g.l=null;if(b.F)throw b.D;return{value:b.return,done:!0}}return{value:void 0,done:!0}}
|
||||
function J(a){this.next=function(b){return a.o(b)};this.throw=function(b){return a.s(b)};this.return=function(b){return I(a,b)};this[Symbol.iterator]=function(){return this}}function K(a,b){b=new J(new F(b));B&&a.prototype&&B(b,a.prototype);return b}function L(a,b){a instanceof String&&(a+="");var c=0,d=!1,e={next:function(){if(!d&&c<a.length){var f=c++;return{value:b(f,a[f]),done:!1}}d=!0;return{done:!0,value:void 0}}};e[Symbol.iterator]=function(){return e};return e}
|
||||
r("Array.prototype.entries",function(a){return a?a:function(){return L(this,function(b,c){return[b,c]})}});
|
||||
if("undefined"!==typeof Blob&&("undefined"===typeof FormData||!FormData.prototype.keys)){var M=function(a,b){for(var c=0;c<a.length;c++)b(a[c])},N=function(a){return a.replace(/\r?\n|\r/g,"\r\n")},O=function(a,b,c){if(b instanceof Blob){c=void 0!==c?String(c+""):"string"===typeof b.name?b.name:"blob";if(b.name!==c||"[object Blob]"===Object.prototype.toString.call(b))b=new File([b],c);return[String(a),b]}return[String(a),String(b)]},P=function(a,b){if(a.length<b)throw new TypeError(b+" argument required, but only "+
|
||||
a.length+" present.");},Q="object"===typeof globalThis?globalThis:"object"===typeof window?window:"object"===typeof self?self:this,R=Q.FormData,S=Q.XMLHttpRequest&&Q.XMLHttpRequest.prototype.send,T=Q.Request&&Q.fetch,U=Q.navigator&&Q.navigator.sendBeacon,V=Q.Element&&Q.Element.prototype,W=Q.Symbol&&Symbol.toStringTag;W&&(Blob.prototype[W]||(Blob.prototype[W]="Blob"),"File"in Q&&!File.prototype[W]&&(File.prototype[W]="File"));try{new File([],"")}catch(a){Q.File=function(b,c,d){b=new Blob(b,d||{});
|
||||
Object.defineProperties(b,{name:{value:c},lastModified:{value:+(d&&void 0!==d.lastModified?new Date(d.lastModified):new Date)},toString:{value:function(){return"[object File]"}}});W&&Object.defineProperty(b,W,{value:"File"});return b}}var escape=function(a){return a.replace(/\n/g,"%0A").replace(/\r/g,"%0D").replace(/"/g,"%22")},X=function(a){this.i=[];var b=this;a&&M(a.elements,function(c){if(c.name&&!c.disabled&&"submit"!==c.type&&"button"!==c.type&&!c.matches("form fieldset[disabled] *"))if("file"===
|
||||
c.type){var d=c.files&&c.files.length?c.files:[new File([],"",{type:"application/octet-stream"})];M(d,function(e){b.append(c.name,e)})}else"select-multiple"===c.type||"select-one"===c.type?M(c.options,function(e){!e.disabled&&e.selected&&b.append(c.name,e.value)}):"checkbox"===c.type||"radio"===c.type?c.checked&&b.append(c.name,c.value):(d="textarea"===c.type?N(c.value):c.value,b.append(c.name,d))})};h=X.prototype;h.append=function(a,b,c){P(arguments,2);this.i.push(O(a,b,c))};h.delete=function(a){P(arguments,
|
||||
1);var b=[];a=String(a);M(this.i,function(c){c[0]!==a&&b.push(c)});this.i=b};h.entries=function b(){var c,d=this;return K(b,function(e){1==e.h&&(c=0);if(3!=e.h)return c<d.i.length?e=E(e,d.i[c]):(e.h=0,e=void 0),e;c++;e.h=2})};h.forEach=function(b,c){P(arguments,1);for(var d=v(this),e=d.next();!e.done;e=d.next()){var f=v(e.value);e=f.next().value;f=f.next().value;b.call(c,f,e,this)}};h.get=function(b){P(arguments,1);var c=this.i;b=String(b);for(var d=0;d<c.length;d++)if(c[d][0]===b)return c[d][1];
|
||||
return null};h.getAll=function(b){P(arguments,1);var c=[];b=String(b);M(this.i,function(d){d[0]===b&&c.push(d[1])});return c};h.has=function(b){P(arguments,1);b=String(b);for(var c=0;c<this.i.length;c++)if(this.i[c][0]===b)return!0;return!1};h.keys=function c(){var d=this,e,f,g,k,p;return K(c,function(t){1==t.h&&(e=v(d),f=e.next());if(3!=t.h){if(f.done){t.h=0;return}g=f.value;k=v(g);p=k.next().value;return E(t,p)}f=e.next();t.h=2})};h.set=function(c,d,e){P(arguments,2);c=String(c);var f=[],g=O(c,
|
||||
d,e),k=!0;M(this.i,function(p){p[0]===c?k&&(k=!f.push(g)):f.push(p)});k&&f.push(g);this.i=f};h.values=function d(){var e=this,f,g,k,p,t;return K(d,function(x){1==x.h&&(f=v(e),g=f.next());if(3!=x.h){if(g.done){x.h=0;return}k=g.value;p=v(k);p.next();t=p.next().value;return E(x,t)}g=f.next();x.h=2})};X.prototype._asNative=function(){for(var d=new R,e=v(this),f=e.next();!f.done;f=e.next()){var g=v(f.value);f=g.next().value;g=g.next().value;d.append(f,g)}return d};X.prototype._blob=function(){var d="----formdata-polyfill-"+
|
||||
Math.random(),e=[],f="--"+d+'\r\nContent-Disposition: form-data; name="';this.forEach(function(g,k){return"string"==typeof g?e.push(f+escape(N(k))+('"\r\n\r\n'+N(g)+"\r\n")):e.push(f+escape(N(k))+('"; filename="'+escape(g.name)+'"\r\nContent-Type: '+(g.type||"application/octet-stream")+"\r\n\r\n"),g,"\r\n")});e.push("--"+d+"--");return new Blob(e,{type:"multipart/form-data; boundary="+d})};X.prototype[Symbol.iterator]=function(){return this.entries()};X.prototype.toString=function(){return"[object FormData]"};
|
||||
V&&!V.matches&&(V.matches=V.matchesSelector||V.mozMatchesSelector||V.msMatchesSelector||V.oMatchesSelector||V.webkitMatchesSelector||function(d){d=(this.document||this.ownerDocument).querySelectorAll(d);for(var e=d.length;0<=--e&&d.item(e)!==this;);return-1<e});W&&(X.prototype[W]="FormData");if(S){var Y=Q.XMLHttpRequest.prototype.setRequestHeader;Q.XMLHttpRequest.prototype.setRequestHeader=function(d,e){Y.call(this,d,e);"content-type"===d.toLowerCase()&&(this.B=!0)};Q.XMLHttpRequest.prototype.send=
|
||||
function(d){d instanceof X?(d=d._blob(),this.B||this.setRequestHeader("Content-Type",d.type),S.call(this,d)):S.call(this,d)}}T&&(Q.fetch=function(d,e){e&&e.body&&e.body instanceof X&&(e.body=e.body._blob());return T.call(this,d,e)});U&&(Q.navigator.sendBeacon=function(d,e){e instanceof X&&(e=e._asNative());return U.call(this,d,e)});Q.FormData=X};})();
|
||||
1
common/js/polyfills/promise.min.js
vendored
Normal file
1
common/js/polyfills/promise.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";function e(e){var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){return t.reject(n)})})}function t(e){return new this(function(t,n){function r(e,n){if(n&&("object"==typeof n||"function"==typeof n)){var f=n.then;if("function"==typeof f)return void f.call(n,function(t){r(e,t)},function(n){o[e]={status:"rejected",reason:n},0==--i&&t(o)})}o[e]={status:"fulfilled",value:n},0==--i&&t(o)}if(!e||"undefined"==typeof e.length)return n(new TypeError(typeof e+" "+e+" is not iterable(cannot read property Symbol(Symbol.iterator))"));var o=Array.prototype.slice.call(e);if(0===o.length)return t([]);for(var i=o.length,f=0;o.length>f;f++)r(f,o[f])})}function n(e,t){this.name="AggregateError",this.errors=e,this.message=t||""}function r(e){var t=this;return new t(function(r,o){if(!e||"undefined"==typeof e.length)return o(new TypeError("Promise.any accepts an array"));var i=Array.prototype.slice.call(e);if(0===i.length)return o();for(var f=[],u=0;i.length>u;u++)try{t.resolve(i[u]).then(r)["catch"](function(e){f.push(e),f.length===i.length&&o(new n(f,"All promises were rejected"))})}catch(c){o(c)}})}function o(e){return!(!e||"undefined"==typeof e.length)}function i(){}function f(e){if(!(this instanceof f))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=undefined,this._deferreds=[],s(e,this)}function u(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,f._immediateFn(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var r;try{r=n(e._value)}catch(o){return void a(t.promise,o)}c(t.promise,r)}else(1===e._state?c:a)(t.promise,e._value)})):e._deferreds.push(t)}function c(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof f)return e._state=3,e._value=t,void l(e);if("function"==typeof n)return void s(function(e,t){return function(){e.apply(t,arguments)}}(n,t),e)}e._state=1,e._value=t,l(e)}catch(r){a(e,r)}}function a(e,t){e._state=2,e._value=t,l(e)}function l(e){2===e._state&&0===e._deferreds.length&&f._immediateFn(function(){e._handled||f._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;n>t;t++)u(e,e._deferreds[t]);e._deferreds=null}function s(e,t){var n=!1;try{e(function(e){n||(n=!0,c(t,e))},function(e){n||(n=!0,a(t,e))})}catch(r){if(n)return;n=!0,a(t,r)}}n.prototype=Error.prototype;var d=setTimeout;f.prototype["catch"]=function(e){return this.then(null,e)},f.prototype.then=function(e,t){var n=new this.constructor(i);return u(this,new function(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}(e,t,n)),n},f.prototype["finally"]=e,f.all=function(e){return new f(function(t,n){function r(e,o){try{if(o&&("object"==typeof o||"function"==typeof o)){var u=o.then;if("function"==typeof u)return void u.call(o,function(t){r(e,t)},n)}i[e]=o,0==--f&&t(i)}catch(c){n(c)}}if(!o(e))return n(new TypeError("Promise.all accepts an array"));var i=Array.prototype.slice.call(e);if(0===i.length)return t([]);for(var f=i.length,u=0;i.length>u;u++)r(u,i[u])})},f.any=r,f.allSettled=t,f.resolve=function(e){return e&&"object"==typeof e&&e.constructor===f?e:new f(function(t){t(e)})},f.reject=function(e){return new f(function(t,n){n(e)})},f.race=function(e){return new f(function(t,n){if(!o(e))return n(new TypeError("Promise.race accepts an array"));for(var r=0,i=e.length;i>r;r++)f.resolve(e[r]).then(t,n)})},f._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){d(e,0)},f._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var p=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();"function"!=typeof p.Promise?p.Promise=f:(p.Promise.prototype["finally"]||(p.Promise.prototype["finally"]=e),p.Promise.allSettled||(p.Promise.allSettled=t),p.Promise.any||(p.Promise.any=r))});
|
||||
Loading…
Add table
Add a link
Reference in a new issue