[feature/ajax] Stylistic JavaScript adjustments

PHPBB3-10270
This commit is contained in:
Igor Wiedler 2012-02-08 19:02:16 +01:00
parent b100bb9a69
commit 628074bf70
3 changed files with 35 additions and 17 deletions

View file

@ -8,8 +8,9 @@
* activates any up / down icons that require it (the ones at the top or bottom). * activates any up / down icons that require it (the ones at the top or bottom).
*/ */
phpbb.add_ajax_callback('forum_down', function() { phpbb.add_ajax_callback('forum_down', function() {
el = $(this); var el = $(this),
var tr = el.parents('tr'); tr = el.parents('tr');
if (tr.is(':first-child')) if (tr.is(':first-child'))
{ {
el.parents('span').siblings('.up').html('<a href="' + tr.attr('data-up') + '"><img src="./images/icon_up.gif" alt="Move up" title="Move up" /></a>'); el.parents('span').siblings('.up').html('<a href="' + tr.attr('data-up') + '"><img src="./images/icon_up.gif" alt="Move up" title="Move up" /></a>');
@ -23,9 +24,12 @@ phpbb.add_ajax_callback('forum_down', function() {
tr.prev().find('.down').html('<a href="' + tr.attr('data-down') + '"><img src="./images/icon_down.gif" alt="Move down" title="Move down" /></a>'); tr.prev().find('.down').html('<a href="' + tr.attr('data-down') + '"><img src="./images/icon_down.gif" alt="Move down" title="Move down" /></a>');
phpbb.ajaxify({selector: tr.prev().find('.down').children('a')}, false, 'forum_down'); phpbb.ajaxify({selector: tr.prev().find('.down').children('a')}, false, 'forum_down');
} }
}).add_ajax_callback('forum_up', function() { });
el = $(this);
var tr = el.parents('tr'); phpbb.add_ajax_callback('forum_up', function() {
var el = $(this),
tr = el.parents('tr');
if (tr.is(':last-child')) if (tr.is(':last-child'))
{ {
el.parents('span').siblings('.down').html('<a href="' + tr.attr('data-down') + '"><img src="./images/icon_down.gif" alt="Move down" title="Move down" /></a>'); el.parents('span').siblings('.down').html('<a href="' + tr.attr('data-down') + '"><img src="./images/icon_down.gif" alt="Move down" title="Move down" /></a>');
@ -47,9 +51,9 @@ phpbb.add_ajax_callback('forum_down', function() {
* in the href with "deactivate", and vice versa. * in the href with "deactivate", and vice versa.
*/ */
phpbb.add_ajax_callback('activate_deactivate', function(res) { phpbb.add_ajax_callback('activate_deactivate', function(res) {
el = $(this); var el = $(this),
new_href = el.attr('href');
el.text(res.text); el.text(res.text);
var new_href = el.attr('href');
if (new_href.indexOf('deactivate') !== -1) if (new_href.indexOf('deactivate') !== -1)
{ {
new_href = new_href.replace('deactivate', 'activate') new_href = new_href.replace('deactivate', 'activate')
@ -72,10 +76,13 @@ phpbb.add_ajax_callback('row_delete', function() {
$('[data-ajax]').each(function() { $('[data-ajax]').each(function() {
var $this = $(this), ajax = $this.attr('data-ajax'); var $this = $(this),
ajax = $this.attr('data-ajax'),
fn;
if (ajax !== 'false') if (ajax !== 'false')
{ {
var fn = (ajax !== 'true') ? ajax : null; fn = (ajax !== 'true') ? ajax : null;
phpbb.ajaxify({selector: this}, $this.attr('data-refresh') !== undefined, fn); phpbb.ajaxify({selector: this}, $this.attr('data-refresh') !== undefined, fn);
} }
}); });

View file

@ -61,8 +61,10 @@ phpbb.alert = function(title, msg, fadedark) {
e.stopPropagation(); e.stopPropagation();
}); });
dark.one('click', function(e) { dark.one('click', function(e) {
var fade;
div.find('.alert_close').unbind('click'); div.find('.alert_close').unbind('click');
var fade = (typeof fadedark !== 'undefined' && !fadedark) ? div : dark; fade = (typeof fadedark !== 'undefined' && !fadedark) ? div : dark;
fade.fadeOut(phpbb.alert_time, function() { fade.fadeOut(phpbb.alert_time, function() {
div.hide(); div.hide();
}); });
@ -261,6 +263,8 @@ phpbb.ajaxify = function(options, refresh, callback) {
*/ */
function return_handler(res) function return_handler(res)
{ {
var alert;
// Is a confirmation required? // Is a confirmation required?
if (typeof res.S_CONFIRM_ACTION === 'undefined') if (typeof res.S_CONFIRM_ACTION === 'undefined')
{ {
@ -268,7 +272,7 @@ phpbb.ajaxify = function(options, refresh, callback) {
// callbacks. // callbacks.
if (typeof res.MESSAGE_TITLE !== 'undefined') if (typeof res.MESSAGE_TITLE !== 'undefined')
{ {
var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
} }
else else
{ {

View file

@ -3,10 +3,12 @@
// This callback finds the post from the delete link, and removes it. // This callback finds the post from the delete link, and removes it.
phpbb.add_ajax_callback('post_delete', function() { phpbb.add_ajax_callback('post_delete', function() {
var el = $(this); var el = $(this),
post_id;
if (el.attr('data-refresh') === undefined) if (el.attr('data-refresh') === undefined)
{ {
var post_id = el[0].href.split('&p=')[1]; post_id = el[0].href.split('&p=')[1];
el.parents('#p' + post_id).fadeOut(function() { el.parents('#p' + post_id).fadeOut(function() {
$(this).remove(); $(this).remove();
}); });
@ -34,20 +36,25 @@ phpbb.add_ajax_callback('row_delete', function() {
// This handles friend / foe additions removals. // This handles friend / foe additions removals.
phpbb.add_ajax_callback('zebra', function(res) { phpbb.add_ajax_callback('zebra', function(res) {
var zebra;
if (res.success) { if (res.success) {
var zebra = $('.zebra'); zebra = $('.zebra');
zebra.html(res.MESSAGE_TEXT); zebra.html(res.MESSAGE_TEXT);
$(zebra.get(1)).remove(); $(zebra.get(1)).remove();
} }
});; });
$('[data-ajax]').each(function() { $('[data-ajax]').each(function() {
var $this = $(this), ajax = $this.attr('data-ajax'); var $this = $(this),
ajax = $this.attr('data-ajax'),
fn;
if (ajax !== 'false') if (ajax !== 'false')
{ {
var fn = (ajax !== 'true') ? ajax : null; fn = (ajax !== 'true') ? ajax : null;
phpbb.ajaxify({selector: this}, $this.attr('data-refresh') !== undefined, fn); phpbb.ajaxify({selector: this}, $this.attr('data-refresh') !== undefined, fn);
} }
}); });