[feature/ajax] Make phpbb.ajaxify signature use single object (more explicit)

PHPBB3-10270
This commit is contained in:
Igor Wiedler 2012-02-08 19:56:25 +01:00
parent 1fc26eb1d5
commit 7ed2cbef75
3 changed files with 35 additions and 11 deletions

View file

@ -16,14 +16,20 @@ phpbb.add_ajax_callback('forum_down', function() {
{ {
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>');
tr.next().find('.up').html('<img src="./images/icon_up_disabled.gif" alt="Move up" title="Move up" />'); tr.next().find('.up').html('<img src="./images/icon_up_disabled.gif" alt="Move up" title="Move up" />');
phpbb.ajaxify({selector: el.parents('span').siblings('.up').children('a')}, false, 'forum_up'); phpbb.ajaxify({
selector: el.parents('span').siblings('.up').children('a'),
callback: 'forum_up'
});
} }
tr.insertAfter(tr.next()); tr.insertAfter(tr.next());
if (tr.is(':last-child')) if (tr.is(':last-child'))
{ {
el.html('<img src="./images/icon_down_disabled.gif" alt="Move down" title="Move down" />'); el.html('<img src="./images/icon_down_disabled.gif" alt="Move down" title="Move down" />');
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'),
callback: 'forum_down'
});
} }
}); });
@ -35,14 +41,20 @@ phpbb.add_ajax_callback('forum_up', function() {
{ {
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>');
tr.prev().find('.down').html('<img src="./images/icon_down_disabled.gif" alt="Move down" title="Move down" />'); tr.prev().find('.down').html('<img src="./images/icon_down_disabled.gif" alt="Move down" title="Move down" />');
phpbb.ajaxify({selector: el.parents('span').siblings('.down').children('a')}, false, 'forum_down'); phpbb.ajaxify({
selector: el.parents('span').siblings('.down').children('a'),
callback: 'forum_down'
});
} }
tr.insertBefore(tr.prev()); tr.insertBefore(tr.prev());
if (tr.is(':first-child')) if (tr.is(':first-child'))
{ {
el.html('<img src="./images/icon_up_disabled.gif" alt="Move up" title="Move up" />'); el.html('<img src="./images/icon_up_disabled.gif" alt="Move up" title="Move up" />');
tr.next().find('.up').html('<a href="' + tr.attr('data-up') + '"><img src="./images/icon_up.gif" alt="Move up" title="Move up" /></a>'); tr.next().find('.up').html('<a href="' + tr.attr('data-up') + '"><img src="./images/icon_up.gif" alt="Move up" title="Move up" /></a>');
phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); phpbb.ajaxify({
selector: tr.next().find('.up').children('a'),
callback: 'forum_up'
});
} }
}); });
@ -84,7 +96,11 @@ $('[data-ajax]').each(function() {
if (ajax !== 'false') if (ajax !== 'false')
{ {
fn = (ajax !== 'true') ? ajax : null; fn = (ajax !== 'true') ? ajax : null;
phpbb.ajaxify({selector: this}, $this.attr('data-refresh') !== undefined, fn); phpbb.ajaxify({
selector: this,
refresh: $this.attr('data-refresh') !== undefined,
callback: fn
});
} }
}); });

View file

@ -241,9 +241,12 @@ phpbb.parse_querystring = function(string) {
* three parameters: the element that the event was evoked from, the JSON * three parameters: the element that the event was evoked from, the JSON
* that was returned and (if it is a form) the form action. * that was returned and (if it is a form) the form action.
*/ */
phpbb.ajaxify = function(options, refresh, callback) { phpbb.ajaxify = function(options) {
var elements = $(options.selector); var elements = $(options.selector),
var is_form = elements.is('form'); refresh = options.refresh,
callback = options.callback,
is_form = elements.is('form');
if (is_form) if (is_form)
{ {
elements = elements.find('input:submit'); elements = elements.find('input:submit');

View file

@ -56,7 +56,11 @@ $('[data-ajax]').each(function() {
if (ajax !== 'false') if (ajax !== 'false')
{ {
fn = (ajax !== 'true') ? ajax : null; fn = (ajax !== 'true') ? ajax : null;
phpbb.ajaxify({selector: this}, $this.attr('data-refresh') !== undefined, fn); phpbb.ajaxify({
selector: this,
refresh: $this.attr('data-refresh') !== undefined,
callback: fn
});
} }
}); });
@ -86,8 +90,9 @@ phpbb.ajaxify({
} }
return true; return true;
} },
}, true); refresh: true
});