Skip to content

Instantly share code, notes, and snippets.

@korniux
Last active April 5, 2018 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save korniux/d7908710cd586d8152d5ad010c31787d to your computer and use it in GitHub Desktop.
Save korniux/d7908710cd586d8152d5ad010c31787d to your computer and use it in GitHub Desktop.
Toggle multiple spoilers
.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;
}
// 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">&darr;</span>' +
'<span class="button" data-type="hide">&uarr;</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