mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-12 22:38:52 +00:00
[ticket/10271] Cleaned up phpbb.ajaxify.
Reduced a lot of duplicate code and made it more efficient. PHPBB3-10271
This commit is contained in:
parent
bcb824a9f2
commit
f85faf435d
1 changed files with 25 additions and 45 deletions
|
@ -174,32 +174,6 @@ phpbb.parse_querystring = function(string) {
|
||||||
* @param function callback Callback.
|
* @param function callback Callback.
|
||||||
*/
|
*/
|
||||||
phpbb.ajaxify = function(options, refresh, callback) {
|
phpbb.ajaxify = function(options, refresh, callback) {
|
||||||
|
|
||||||
// Private function to handle refreshes
|
|
||||||
function handle_refresh(data, refresh, div)
|
|
||||||
{
|
|
||||||
if (!data)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
refresh = ((typeof refresh === 'function') ? refresh(data.url) :
|
|
||||||
(typeof refresh === 'boolean') && refresh);
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
if (refresh)
|
|
||||||
{
|
|
||||||
window.location = data.url;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dark.fadeOut(function() {
|
|
||||||
div.remove();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, data.time * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
var selector = (typeof options === 'string') ? options : options.selector;
|
var selector = (typeof options === 'string') ? options : options.selector;
|
||||||
var is_form = $(selector).is('form');
|
var is_form = $(selector).is('form');
|
||||||
if (is_form && typeof selector === 'object')
|
if (is_form && typeof selector === 'object')
|
||||||
|
@ -237,7 +211,29 @@ phpbb.ajaxify = function(options, refresh, callback) {
|
||||||
{
|
{
|
||||||
phpbb.ajax_callbacks[callback](that, res, (is_form) ? act : null);
|
phpbb.ajax_callbacks[callback](that, res, (is_form) ? act : null);
|
||||||
}
|
}
|
||||||
handle_refresh(res.REFRESH_DATA, refresh, alert);
|
|
||||||
|
if (res.REFRESH_DATA)
|
||||||
|
{
|
||||||
|
if (typeof refresh === 'function')
|
||||||
|
{
|
||||||
|
refresh = refresh(res.REFRESH_DATA.url);
|
||||||
|
}
|
||||||
|
else if (typeof refresh !== 'boolean')
|
||||||
|
{
|
||||||
|
refresh = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
if (refresh)
|
||||||
|
{
|
||||||
|
window.location = res.REFRESH_DATA.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
dark.fadeOut(function() {
|
||||||
|
alert.remove();
|
||||||
|
});
|
||||||
|
}, res.REFRESH_DATA.time * 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -245,25 +241,9 @@ phpbb.ajaxify = function(options, refresh, callback) {
|
||||||
phpbb.confirm(res.MESSAGE_TEXT, function(del) {
|
phpbb.confirm(res.MESSAGE_TEXT, function(del) {
|
||||||
if (del)
|
if (del)
|
||||||
{
|
{
|
||||||
data = $('<form>' + res.S_HIDDEN_FIELDS + '</form>').serialize();
|
|
||||||
path = res.S_CONFIRM_ACTION;
|
|
||||||
phpbb.loading_alert();
|
phpbb.loading_alert();
|
||||||
$.post(path, data + '&confirm=' + res.YES_VALUE, function(res) {
|
data = $('<form>' + res.S_HIDDEN_FIELDS + '</form>').serialize();
|
||||||
if (typeof res.MESSAGE_TITLE !== 'undefined')
|
$.post(res.S_CONFIRM_ACTION, data + '&confirm=' + res.YES_VALUE, return_handler);
|
||||||
{
|
|
||||||
var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dark.fadeOut();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof phpbb.ajax_callbacks[callback] === 'function')
|
|
||||||
{
|
|
||||||
phpbb.ajax_callbacks[callback](that, res, (is_form) ? act : null);
|
|
||||||
}
|
|
||||||
handle_refresh(res.REFRESH_DATA, refresh, alert);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue