Files
phpbb_board3-portal_tlw/adm/style/portal/ajax.js
Marc Alexander c603e32b19 [ticket/102] Ajaxify moving modules up and down
The complete moving process for moving a module up or down now works with
AJAX. Images are properly changing as one would expect.

B3P-102
2014-04-08 12:38:40 +02:00

82 lines
2.9 KiB
JavaScript

(function($) { // Avoid conflicts with other libraries
"use strict";
/**
* The following callbacks are for reording items. row_down
* is triggered when an item is moved down, and row_up is triggered when
* an item is moved up. It moves the row up or down, and deactivates /
* activates any up / down icons that require it (the ones at the top or bottom).
*/
phpbb.addAjaxCallback('b3p_move_module_up', function(res) {
if (typeof res.success === 'undefined' || !res.success) {
return;
}
var el = $(this).parents('tr:first'),
trSwap = el.prev(),
elClass = trSwap.attr('class'),
trSwapClass = el.attr('class');
el.insertBefore(trSwap);
el.attr('class', elClass);
trSwap.attr('class', trSwapClass);
// Swap images if swap element is first row
var swapIsFirstRow = trSwap.find('img[src*="icon_up_disabled"]').parents('span:first').is(':visible');
if (swapIsFirstRow) {
trSwap.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
}
// Swap images if move element is last row
var elIsLastRow = el.find('img[src*="icon_down_disabled"]').parents('span:first').is(':visible');
if (elIsLastRow) {
trSwap.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
}
});
phpbb.addAjaxCallback('b3p_move_module_down', function(res) {
if (typeof res.success === 'undefined' || !res.success) {
return;
}
var el = $(this).parents('tr:first'),
trSwap = el.next(),
elClass = trSwap.attr('class'),
trSwapClass = el.attr('class');
el.insertAfter(trSwap);
el.attr('class', elClass);
trSwap.attr('class', trSwapClass);
// Swap images if swap element is last row
var swapIsLastRow = trSwap.find('img[src*="icon_down_disabled"]').parents('span:first').is(':visible');
if (swapIsLastRow) {
trSwap.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
}
// Swap images if move element is first row
var elIsFirstRow = el.find('img[src*="icon_up_disabled"]').parents('span:first').is(':visible');
if (elIsFirstRow) {
trSwap.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
}
});
})(jQuery); // Avoid conflicts with other libraries