From 95659ba92c01a3cf4c654568e9a59ba554558a7e Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sat, 22 Oct 2011 16:31:52 +0100 Subject: [PATCH] [ticket/10271] Reduced calls to $ in the AJAX JavaScript. PHPBB3-10271 --- phpBB/adm/style/ajax.js | 30 ++++++++++++++----------- phpBB/assets/javascript/core.js | 7 +++--- phpBB/styles/prosilver/template/ajax.js | 10 +++++---- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index 1c315eeeff..2fdabd2a80 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -8,32 +8,34 @@ * activates any up / down icons that require it (the ones at the top or bottom). */ phpbb.add_ajax_callback('forum_down', function(el) { - var tr = $(el).parents('tr'); + el = $(el); + var tr = el.parents('tr'); if (tr.is(':first-child')) { - $(el).parents('span').siblings('.up').html('Move up'); + el.parents('span').siblings('.up').html('Move up'); tr.next().find('.up').html('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')}, false, 'forum_up'); } tr.insertAfter(tr.next()); if (tr.is(':last-child')) { - $(el).html('Move down'); + el.html('Move down'); tr.prev().find('.down').html('Move down'); phpbb.ajaxify({selector: tr.prev().find('.down').children('a')}, false, 'forum_down'); } }).add_ajax_callback('forum_up', function(el) { - var tr = $(el).parents('tr'); + el = $(el); + var tr = el.parents('tr'); if (tr.is(':last-child')) { - $(el).parents('span').siblings('.down').html('Move down'); + el.parents('span').siblings('.down').html('Move down'); tr.prev().find('.down').html('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')}, false, 'forum_down'); } tr.insertBefore(tr.prev()); if (tr.is(':first-child')) { - $(el).html('Move up'); + el.html('Move up'); tr.next().find('.up').html('Move up'); phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); } @@ -45,8 +47,9 @@ phpbb.add_ajax_callback('forum_down', function(el) { * in the href with "deactivate", and vice versa. */ phpbb.add_ajax_callback('act_deact', function(el, res) { - $(el).text(res.text); - var new_href = $(el).attr('href'); + el = $(el); + el.text(res.text); + var new_href = el.attr('href'); if (new_href.indexOf('deactivate') !== -1) { new_href = new_href.replace('deactivate', 'activate') @@ -55,7 +58,7 @@ phpbb.add_ajax_callback('act_deact', function(el, res) { { new_href = new_href.replace('activate', 'deactivate') } - $(el).attr('href', new_href); + el.attr('href', new_href); }); /** @@ -70,8 +73,9 @@ phpbb.add_ajax_callback('row_delete', function(el) { $('[data-ajax]').each(function() { - var fn = ($(this).data('ajax') !== 'true') ? $(this).data('ajax') : null; - phpbb.ajaxify({selector: this}, $(this).data('refresh') !== undefined, fn); + var $this = $(this); + var fn = ($this.data('ajax') !== 'true') ? $this.data('ajax') : null; + phpbb.ajaxify({selector: this}, $this.data('refresh') !== undefined, fn); }); diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 09d7d1fa83..3d75cd291f 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -359,9 +359,10 @@ phpbb.add_ajax_callback = function(id, callback) * current text so that the process can be repeated. */ phpbb.add_ajax_callback('alt_text', function(el) { - var alt_text = $(el).data('alt-text'); - $(el).data('alt-text', $(el).text()); - $(el).text(el.title = alt_text); + el = $(el); + var alt_text = el.data('alt-text'); + el.data('alt-text', el.text()); + el.text(el[0].title = alt_text); }); diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js index 66b34f7726..4fd4cd32f5 100644 --- a/phpBB/styles/prosilver/template/ajax.js +++ b/phpBB/styles/prosilver/template/ajax.js @@ -35,16 +35,18 @@ phpbb.add_ajax_callback('row_delete', function(el) { // This handles friend / foe additions removals. phpbb.add_ajax_callback('zebra', function(el, res) { if (res.success) { - $('.zebra').html(res.MESSAGE_TEXT); - $($('.zebra').get(1)).remove(); + var zebra = $('.zebra'); + zebra.html(res.MESSAGE_TEXT); + $(zebra.get(1)).remove(); } });; $('[data-ajax]').each(function() { - var fn = ($(this).data('ajax') !== 'true') ? $(this).data('ajax') : null; - phpbb.ajaxify({selector: this}, $(this).data('refresh') !== undefined, fn); + var $this = $(this); + var fn = ($this.data('ajax') !== 'true') ? $this.data('ajax') : null; + phpbb.ajaxify({selector: this}, $this.data('refresh') !== undefined, fn); });