mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[ticket/13018] Remove duplicate logic in confirm box and alert box handling.
This ensures a more consistent handling of the various closing/opening actions and fixes some bugs where certain event handlers are not turned off in certain instances. PHPBB3-13018
This commit is contained in:
parent
a45df1d840
commit
6d80770ba4
1 changed files with 78 additions and 90 deletions
|
@ -79,41 +79,39 @@ phpbb.alert = function(title, msg, fadedark) {
|
||||||
$alert.find('.alert_title').html(title);
|
$alert.find('.alert_title').html(title);
|
||||||
$alert.find('.alert_text').html(msg);
|
$alert.find('.alert_text').html(msg);
|
||||||
|
|
||||||
if (!$dark.is(':visible')) {
|
$(document).on('keydown.phpbb.alert', function(e) {
|
||||||
$dark.fadeIn(phpbb.alertTime);
|
if (e.keyCode === keymap.ENTER || e.keyCode === keymap.ESC) {
|
||||||
}
|
closeBox(true, e, true);
|
||||||
|
|
||||||
$alert.on('click', function(e) {
|
|
||||||
e.stopPropagation();
|
|
||||||
});
|
|
||||||
$dark.one('click', function(e) {
|
|
||||||
var fade;
|
|
||||||
|
|
||||||
$alert.find('.alert_close').off('click');
|
|
||||||
fade = (typeof fadedark !== 'undefined' && !fadedark) ? $alert : $dark;
|
|
||||||
fade.fadeOut(phpbb.alertTime, function() {
|
|
||||||
$alert.hide();
|
|
||||||
});
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).keydown(function(e) {
|
|
||||||
if ((e.keyCode === keymap.ENTER || e.keyCode === keymap.ESC) && $dark.is(':visible')) {
|
|
||||||
$dark.trigger('click');
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$alert.find('.alert_close').one('click', function(e) {
|
$dark.one('click', function(e) {
|
||||||
$dark.trigger('click');
|
closeBox(true, e, true);
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$alert.find('.alert_close').one('click', function(e) {
|
||||||
|
closeBox(true, e, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
var closeBox = function(fadedark, event, stopPropagation) {
|
||||||
|
phpbb.alert.close($alert, fadedark, event, stopPropagation);
|
||||||
|
};
|
||||||
|
|
||||||
|
phpbb.alert.open($alert);
|
||||||
|
|
||||||
|
return $alert;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for opening an alert box.
|
||||||
|
*
|
||||||
|
* @param jQuery $alert jQuery object.
|
||||||
|
*/
|
||||||
|
phpbb.alert.open = function($alert) {
|
||||||
|
if (!$dark.is(':visible')) {
|
||||||
|
$dark.fadeIn(phpbb.alertTime);
|
||||||
|
}
|
||||||
|
|
||||||
if ($loadingIndicator.is(':visible')) {
|
if ($loadingIndicator.is(':visible')) {
|
||||||
$loadingIndicator.fadeOut(phpbb.alertTime, function() {
|
$loadingIndicator.fadeOut(phpbb.alertTime, function() {
|
||||||
$dark.append($alert);
|
$dark.append($alert);
|
||||||
|
@ -128,7 +126,35 @@ phpbb.alert = function(title, msg, fadedark) {
|
||||||
$dark.fadeIn(phpbb.alertTime);
|
$dark.fadeIn(phpbb.alertTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $alert;
|
$alert.on('click', function(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for closing an alert box.
|
||||||
|
*
|
||||||
|
* @param jQuery $alert jQuery object.
|
||||||
|
* @param bool fadedark Whether to remove dark background.
|
||||||
|
* @param object event Event object.
|
||||||
|
* @param bool stopPropagation Whether to stop event's propagation.
|
||||||
|
*/
|
||||||
|
phpbb.alert.close = function($alert, fadedark, event, stopPropagation) {
|
||||||
|
var $fade = (fadedark) ? $dark : $alert;
|
||||||
|
|
||||||
|
$fade.fadeOut(phpbb.alertTime, function() {
|
||||||
|
$alert.hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
$alert.find('.alert_close').off('click');
|
||||||
|
$(document).off('keydown.phpbb.alert');
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (stopPropagation) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,77 +173,39 @@ phpbb.alert = function(title, msg, fadedark) {
|
||||||
phpbb.confirm = function(msg, callback, fadedark) {
|
phpbb.confirm = function(msg, callback, fadedark) {
|
||||||
var $confirmDiv = $('#phpbb_confirm');
|
var $confirmDiv = $('#phpbb_confirm');
|
||||||
$confirmDiv.find('.alert_text').html(msg);
|
$confirmDiv.find('.alert_text').html(msg);
|
||||||
|
fadedark = (typeof fadedark === 'undefined') ? true : fadedark;
|
||||||
|
|
||||||
if (!$dark.is(':visible')) {
|
$(document).on('keydown.phpbb.alert', function(e) {
|
||||||
$dark.fadeIn(phpbb.alertTime);
|
if (e.keyCode === keymap.ENTER || e.keyCode === keymap.ESC) {
|
||||||
}
|
var name = (e.keyCode === keymap.ENTER) ? 'confirm' : 'cancel';
|
||||||
|
|
||||||
$confirmDiv.on('click', function(e) {
|
$('input[name="' + name + '"]').trigger('click');
|
||||||
e.stopPropagation();
|
|
||||||
});
|
|
||||||
|
|
||||||
var clickHandler = function(e) {
|
|
||||||
var res = this.name === 'confirm';
|
|
||||||
var $fade = (typeof fadedark !== 'undefined' && !fadedark && res) ? $confirmDiv : $dark;
|
|
||||||
$fade.fadeOut(phpbb.alertTime, function() {
|
|
||||||
$confirmDiv.hide();
|
|
||||||
});
|
|
||||||
$confirmDiv.find('input[type="button"]').off('click', clickHandler);
|
|
||||||
callback(res);
|
|
||||||
|
|
||||||
if (e) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
$confirmDiv.find('input[type="button"]').one('click', clickHandler);
|
|
||||||
|
$confirmDiv.find('input[type="button"]').one('click.phpbb.confirmbox', function(e) {
|
||||||
|
var confirmed = this.name === 'confirm',
|
||||||
|
fadedark = fadedark || !confirmed;
|
||||||
|
closeBox(fadedark, confirmed, e, true);
|
||||||
|
});
|
||||||
|
|
||||||
$dark.one('click', function(e) {
|
$dark.one('click', function(e) {
|
||||||
$confirmDiv.find('.alert_close').off('click');
|
closeBox(true, false, e, true);
|
||||||
$dark.fadeOut(phpbb.alertTime, function() {
|
|
||||||
$confirmDiv.hide();
|
|
||||||
});
|
|
||||||
callback(false);
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('keydown', function(e) {
|
|
||||||
if (e.keyCode === keymap.ENTER) {
|
|
||||||
$('input[name="confirm"]').trigger('click');
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
} else if (e.keyCode === keymap.ESC) {
|
|
||||||
$('input[name="cancel"]').trigger('click');
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$confirmDiv.find('.alert_close').one('click', function(e) {
|
$confirmDiv.find('.alert_close').one('click', function(e) {
|
||||||
var $fade = (typeof fadedark !== 'undefined' && fadedark) ? $confirmDiv : $dark;
|
closeBox(true, false, e, false);
|
||||||
$fade.fadeOut(phpbb.alertTime, function() {
|
|
||||||
$confirmDiv.hide();
|
|
||||||
});
|
|
||||||
callback(false);
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($loadingIndicator.is(':visible')) {
|
var closeBox = function(fadedark, confirmed, event, stopPropagation) {
|
||||||
$loadingIndicator.fadeOut(phpbb.alertTime, function() {
|
$confirmDiv.find('input[type="button"]').off('click.phpbb.confirmbox');
|
||||||
$dark.append($confirmDiv);
|
callback(confirmed);
|
||||||
$confirmDiv.fadeIn(phpbb.alertTime);
|
phpbb.alert.close($confirmDiv, fadedark, event, stopPropagation);
|
||||||
});
|
};
|
||||||
} else if ($dark.is(':visible')) {
|
|
||||||
$dark.append($confirmDiv);
|
phpbb.alert.open($confirmDiv);
|
||||||
$confirmDiv.fadeIn(phpbb.alertTime);
|
|
||||||
} else {
|
|
||||||
$dark.append($confirmDiv);
|
|
||||||
$confirmDiv.show();
|
|
||||||
$dark.fadeIn(phpbb.alertTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $confirmDiv;
|
return $confirmDiv;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue