[ticket/578] Correctly assign classes upon moving modules up/down

B3P-578
This commit is contained in:
Marc Alexander
2015-06-06 21:39:18 +02:00
parent e5319bfbe3
commit 215a29c0ac

View File

@@ -13,33 +13,39 @@ phpbb.addAjaxCallback('b3p_move_module_up', function(res) {
return; return;
} }
var el = $(this).parents('tr:first'), var $bottomRow = $(this).parents('tr:first'),
trSwap = el.prev(), $topRow = $bottomRow.prev(),
elClass = trSwap.attr('class'), topRowClass = $topRow.attr('class'),
trSwapClass = el.attr('class'); bottomRowClass = $bottomRow.attr('class');
el.insertBefore(trSwap); $bottomRow.insertBefore($topRow);
el.attr('class', elClass); if (bottomRowClass !== 'row3' && topRowClass !== 'row3') {
trSwap.attr('class', trSwapClass); $bottomRow.attr('class', topRowClass);
$topRow.attr('class', bottomRowClass);
} else if (bottomRowClass === 'row3') {
$topRow.attr('class', (topRowClass === 'row1') ? 'row2' : 'row1');
} else if (topRowClass === 'row3') {
$bottomRow.attr('class', (bottomRowClass === 'row1') ? 'row2' : 'row1');
}
// Swap images if swap element is first row // Swap images if swap element is first row
var swapIsFirstRow = trSwap.find('img[src*="icon_up_disabled"]').parents('span:first').is(':visible'); var swapIsFirstRow = $topRow.find('img[src*="icon_up_disabled"]').parents('span:first').is(':visible');
if (swapIsFirstRow) { if (swapIsFirstRow) {
trSwap.find('img[src*="icon_up_disabled"]').parents('span:first').toggle(); $topRow.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_up."]').parents('span:first').toggle(); $topRow.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up."]').parents('span:first').toggle(); $bottomRow.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up_disabled"]').parents('span:first').toggle(); $bottomRow.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
} }
// Swap images if move element is last row // Swap images if move element is last row
var elIsLastRow = el.find('img[src*="icon_down_disabled"]').parents('span:first').is(':visible'); var elIsLastRow = $bottomRow.find('img[src*="icon_down_disabled"]').parents('span:first').is(':visible');
if (elIsLastRow) { if (elIsLastRow) {
trSwap.find('img[src*="icon_down_disabled"]').parents('span:first').toggle(); $topRow.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_down."]').parents('span:first').toggle(); $topRow.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down."]').parents('span:first').toggle(); $bottomRow.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down_disabled"]').parents('span:first').toggle(); $bottomRow.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
} }
}); });
@@ -48,33 +54,39 @@ phpbb.addAjaxCallback('b3p_move_module_down', function(res) {
return; return;
} }
var el = $(this).parents('tr:first'), var $topRow = $(this).parents('tr:first'),
trSwap = el.next(), $bottomRow = $topRow.next(),
elClass = trSwap.attr('class'), bottomRowClass = $bottomRow.attr('class'),
trSwapClass = el.attr('class'); topRowClass = $topRow.attr('class');
el.insertAfter(trSwap); $topRow.insertAfter($bottomRow);
el.attr('class', elClass); if (bottomRowClass !== 'row3' && topRowClass !== 'row3') {
trSwap.attr('class', trSwapClass); $bottomRow.attr('class', topRowClass);
$topRow.attr('class', bottomRowClass);
} else if (bottomRowClass === 'row3') {
$topRow.attr('class', (topRowClass === 'row1') ? 'row2' : 'row1');
} else if (topRowClass === 'row3') {
$bottomRow.attr('class', (bottomRowClass === 'row1') ? 'row2' : 'row1');
}
// Swap images if swap element is last row // Swap images if swap element is last row
var swapIsLastRow = trSwap.find('img[src*="icon_down_disabled"]').parents('span:first').is(':visible'); var swapIsLastRow = $bottomRow.find('img[src*="icon_down_disabled"]').parents('span:first').is(':visible');
if (swapIsLastRow) { if (swapIsLastRow) {
trSwap.find('img[src*="icon_down_disabled"]').parents('span:first').toggle(); $bottomRow.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_down."]').parents('span:first').toggle(); $bottomRow.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down."]').parents('span:first').toggle(); $topRow.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down_disabled"]').parents('span:first').toggle(); $topRow.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
} }
// Swap images if move element is first row // Swap images if move element is first row
var elIsFirstRow = el.find('img[src*="icon_up_disabled"]').parents('span:first').is(':visible'); var elIsFirstRow = $topRow.find('img[src*="icon_up_disabled"]').parents('span:first').is(':visible');
if (elIsFirstRow) { if (elIsFirstRow) {
trSwap.find('img[src*="icon_up_disabled"]').parents('span:first').toggle(); $bottomRow.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_up."]').parents('span:first').toggle(); $bottomRow.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up."]').parents('span:first').toggle(); $topRow.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up_disabled"]').parents('span:first').toggle(); $topRow.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
} }
}); });