-
-
Save korniux/d7908710cd586d8152d5ad010c31787d to your computer and use it in GitHub Desktop.
Toggle multiple spoilers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.js-items-spoilers { | |
position: relative; | |
} | |
.js-items-spoilers .js-items-controls { | |
position: absolute; | |
top: 10px; | |
left: 0; | |
right: 0; | |
} | |
.js-items-spoilers .js-items-buttons { | |
position: absolute; | |
right: 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Toggle multiple spoilers | |
// Special for ru.fallout.wikia.com | |
// Code: @korniux | |
// 2018 | |
if ($('.js-items-spoilers').length) { | |
// Controls row HTML | |
var controls = '<tr colspan="2" class="js-items-controls"><td><div class="js-items-buttons">' + | |
'<span class="button" data-type="show">↓</span>' + | |
'<span class="button" data-type="hide">↑</span>' + | |
'</div></td></tr>'; | |
// Adding controls row | |
$('.js-items-spoilers').prepend(controls); | |
// Initialize click event | |
$('.js-items-controls .button').click(function() { | |
var $jsItemsParent = $(this).closest('.js-items-spoilers'), | |
toggleType = $(this).data('type'); | |
// For each show/hide actions | |
$jsItemsParent.find('.t_show_hide').each(function() { | |
var $btnIndex = $(this).find('a').attr('id').replace(/\D/g, ''), | |
$tableBody = $('#collapsibleTable' + $btnIndex + '>tbody>tr:last-child'); | |
if ((toggleType === 'show' && $tableBody.attr('style')) | |
|| (toggleType === 'hide' && !$tableBody.attr('style')) | |
) { | |
collapseTable($btnIndex); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment