From 818d98916873945d7e0e7bf2855e982496c7fe35 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sat, 24 Sep 2011 17:41:58 +0100 Subject: [PATCH] [feature/ajax] Moved script.js into a few different files. Seperated it into: assets/javascript/core.js, styles/prosilver/template/ajax.js and adm/style/ajax.js. PHPBB3-10270 --- phpBB/adm/style/ajax.js | 61 ++++++++++ phpBB/adm/style/overall_footer.html | 3 +- .../script.js => assets/javascript/core.js} | 104 +----------------- phpBB/styles/prosilver/template/ajax.js | 66 +++++++++++ .../prosilver/template/overall_footer.html | 3 +- 5 files changed, 133 insertions(+), 104 deletions(-) create mode 100644 phpBB/adm/style/ajax.js rename phpBB/{styles/script.js => assets/javascript/core.js} (61%) create mode 100644 phpBB/styles/prosilver/template/ajax.js diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js new file mode 100644 index 0000000000..407ef92110 --- /dev/null +++ b/phpBB/adm/style/ajax.js @@ -0,0 +1,61 @@ +(function($) { // Avoid conflicts with other libraries + + + +phpbb.add_ajax_callback('forum_down', function(el) { + var tr = $(el).parents('tr'); + if (tr.is(':first-child')) + { + $(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'); + } + tr.insertAfter(tr.next()); + if (tr.is(':last-child')) + { + $(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'); + if (tr.is(':last-child')) + { + $(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'); + } + tr.insertBefore(tr.prev()); + if (tr.is(':first-child')) + { + $(el).html('Move up'); + tr.next().find('.up').html('Move up'); + phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); + } +}).add_ajax_callback('act_deact', function(el, res) { + $(el).text(res.text); + var new_href = $(el).attr('href'); + if (new_href.indexOf('deactivate') !== -1) + { + new_href = new_href.replace('deactivate', 'activate') + } + else + { + new_href = new_href.replace('activate', 'deactivate') + } + $(el).attr('href', new_href); +}).add_ajax_callback('row_delete', function(el) { + var tr = $(el).parents('tr'); + tr.remove(); +}); + + + +$('[data-ajax]').each(function() { + var fn = ($(this).data('ajax') !== 'true') ? $(this).data('ajax') : null; + phpbb.ajaxify({selector: this}, $(this).data('refresh') !== undefined, fn); +}); + + + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/adm/style/overall_footer.html b/phpBB/adm/style/overall_footer.html index ec3e6a30d3..b57f8261a3 100644 --- a/phpBB/adm/style/overall_footer.html +++ b/phpBB/adm/style/overall_footer.html @@ -27,7 +27,8 @@ - + + diff --git a/phpBB/styles/script.js b/phpBB/assets/javascript/core.js similarity index 61% rename from phpBB/styles/script.js rename to phpBB/assets/javascript/core.js index dd9d2532cc..7337a7fbc0 100644 --- a/phpBB/styles/script.js +++ b/phpBB/assets/javascript/core.js @@ -3,6 +3,7 @@ var phpbb = {}; (function($) { // Avoid conflicts with other libraries + var dark = $('#darkenwrapper'), loading_alert = $('#loadingalert'); @@ -295,106 +296,5 @@ phpbb.add_ajax_callback = function(id, callback) } -phpbb.add_ajax_callback('post_delete', function(el) { - if ($(this).data('refresh') === undefined) - { - var pid = el.href.split('&p=')[1]; - $(el).parents('div #p' + pid).fadeOut(function() { - $(this).remove(); - }); - } -}).add_ajax_callback('bookmark', function(el, res) { - var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); - text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; - $(el).text(el.title = text); -}).add_ajax_callback('topic_subscribe', function(el) { - $(el).text(el.title = 'Unsubscribe topic'); -}).add_ajax_callback('topic_unsubscribe', function(el) { - $(el).text(el.title = 'Subscribe forum'); -}).add_ajax_callback('forum_subscribe', function(el) { - $(el).text(el.title = 'Unsubscribe topic'); -}).add_ajax_callback('forum_unsubscribe', function(el) { - $(el).text(el.title = 'Subscribe forum'); -}).add_ajax_callback('post_approve', function(el, res, act) { - $(el).parents((act === 'approve') ? '.rules' : '.post').fadeOut(function() { - $(this).remove(); - }); -}).add_ajax_callback('qr-submit', function(el) { - $(el).parents('form').fadeOut(function() { - $(this).remove(); - }); -}).add_ajax_callback('forum_down', function(el) { - var tr = $(el).parents('tr'); - if (tr.is(':first-child')) - { - $(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'); - } - tr.insertAfter(tr.next()); - if (tr.is(':last-child')) - { - $(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'); - if (tr.is(':last-child')) - { - $(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'); - } - tr.insertBefore(tr.prev()); - if (tr.is(':first-child')) - { - $(el).html('Move up'); - tr.next().find('.up').html('Move up'); - phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); - } -}).add_ajax_callback('act_deact', function(el, res) { - $(el).text(res.text); - var new_href = $(el).attr('href'); - if (new_href.indexOf('deactivate') !== -1) - { - new_href = new_href.replace('deactivate', 'activate') - } - else - { - new_href = new_href.replace('activate', 'deactivate') - } - $(el).attr('href', new_href); -}).add_ajax_callback('row_delete', function(el) { - var tr = $(el).parents('tr'); - tr.remove(); -}).add_ajax_callback('zebra', function(el, res) { - if (res.success) { - $('.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); -}); - - - -phpbb.ajaxify({ - selector: '#quickmodform', - exception: function(el, act, data) { - var d = phpbb.parse_querystring(data).action; - if (d == 'make_normal') - { - return !(el.find('select option[value="make_global"]').length); - } - return !(d == 'lock' || d == 'unlock' || d == 'delete_topic' || d.slice(0, 5) == 'make_'); - } -}, true); - - -})(jQuery); // Avoid conflicts with other libraries +})(jQuery); // Avoid conflicts with other libraries \ No newline at end of file diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js new file mode 100644 index 0000000000..38233ad0e0 --- /dev/null +++ b/phpBB/styles/prosilver/template/ajax.js @@ -0,0 +1,66 @@ +(function($) { // Avoid conflicts with other libraries + + + +phpbb.add_ajax_callback('post_delete', function(el) { + if ($(this).data('refresh') === undefined) + { + var pid = el.href.split('&p=')[1]; + $(el).parents('div #p' + pid).fadeOut(function() { + $(this).remove(); + }); + } +}).add_ajax_callback('bookmark', function(el, res) { + var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); + text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; + $(el).text(el.title = text); +}).add_ajax_callback('topic_subscribe', function(el) { + $(el).text(el.title = 'Unsubscribe topic'); +}).add_ajax_callback('topic_unsubscribe', function(el) { + $(el).text(el.title = 'Subscribe forum'); +}).add_ajax_callback('forum_subscribe', function(el) { + $(el).text(el.title = 'Unsubscribe topic'); +}).add_ajax_callback('forum_unsubscribe', function(el) { + $(el).text(el.title = 'Subscribe forum'); +}).add_ajax_callback('post_approve', function(el, res, act) { + $(el).parents((act === 'approve') ? '.rules' : '.post').fadeOut(function() { + $(this).remove(); + }); +}).add_ajax_callback('qr-submit', function(el) { + $(el).parents('form').fadeOut(function() { + $(this).remove(); + }); +}).add_ajax_callback('row_delete', function(el) { + var tr = $(el).parents('tr'); + tr.remove(); +}).add_ajax_callback('zebra', function(el, res) { + if (res.success) { + $('.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); +}); + + + +phpbb.ajaxify({ + selector: '#quickmodform', + exception: function(el, act, data) { + var d = phpbb.parse_querystring(data).action; + if (d == 'make_normal') + { + return !(el.find('select option[value="make_global"]').length); + } + return !(d == 'lock' || d == 'unlock' || d == 'delete_topic' || d.slice(0, 5) == 'make_'); + } +}, true); + + + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index 20f6ee1f91..a89cd7f04e 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -40,7 +40,8 @@ - + +