mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51:40 +09:00
Move Rhymix.ajaxForm() to common.js
This commit is contained in:
parent
94b4c1bd2b
commit
a0606dcf60
2 changed files with 34 additions and 29 deletions
|
|
@ -577,6 +577,40 @@ Rhymix.ajaxErrorHandler = function(xhr, textStatus, action, url, params, success
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Submit a form using AJAX instead of navigating away
|
||||
*
|
||||
* @param HTMLElement form
|
||||
* @param function success
|
||||
* @param function error
|
||||
* @return void
|
||||
*/
|
||||
Rhymix.ajaxForm = function(form, success, error) {
|
||||
const $form = $(form);
|
||||
// Get success and error callback functions.
|
||||
if (typeof success === 'undefined') {
|
||||
success = $form.data('callbackSuccess');
|
||||
if (success && $.isFunction(success)) {
|
||||
// no-op
|
||||
} else if (success && window[success] && $.isFunction(window[success])) {
|
||||
success = window[success];
|
||||
} else {
|
||||
success = null;
|
||||
}
|
||||
}
|
||||
if (typeof error === 'undefined') {
|
||||
error = $form.data('callbackError');
|
||||
if (error && $.isFunction(error)) {
|
||||
// no-op
|
||||
} else if (error && window[error] && $.isFunction(window[error])) {
|
||||
error = window[error];
|
||||
} else {
|
||||
error = null;
|
||||
}
|
||||
}
|
||||
this.ajax(null, new FormData($form[0]), success, error);
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle all checkboxes that have the same name
|
||||
*
|
||||
|
|
|
|||
|
|
@ -372,35 +372,6 @@
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Function for AJAX submission of arbitrary forms.
|
||||
*/
|
||||
Rhymix.ajaxForm = function(form, callback_success, callback_error) {
|
||||
const $form = $(form);
|
||||
// Get success and error callback functions.
|
||||
if (typeof callback_success === 'undefined') {
|
||||
callback_success = $form.data('callbackSuccess');
|
||||
if (callback_success && $.isFunction(callback_success)) {
|
||||
// no-op
|
||||
} else if (callback_success && window[callback_success] && $.isFunction(window[callback_success])) {
|
||||
callback_success = window[callback_success];
|
||||
} else {
|
||||
callback_success = null;
|
||||
}
|
||||
}
|
||||
if (typeof callback_error === 'undefined') {
|
||||
callback_error = $form.data('callbackError');
|
||||
if (callback_error && $.isFunction(callback_error)) {
|
||||
// no-op
|
||||
} else if (callback_error && window[callback_error] && $.isFunction(window[callback_error])) {
|
||||
callback_error = window[callback_error];
|
||||
} else {
|
||||
callback_error = null;
|
||||
}
|
||||
}
|
||||
Rhymix.ajax(null, new FormData($form[0]), callback_success, callback_error);
|
||||
};
|
||||
|
||||
/**
|
||||
* Empty placeholder for beforeUnload handler.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue