Skip to content

Commit

Permalink
Prend en compte la structure des nouveaux blocs Spoiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Situphen committed Mar 30, 2022
1 parent 1058529 commit d37d9db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions assets/js/spoiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(function($) {
'use strict'

function buildSpoilers($elem) {
function buildOldSpoilers($elem) {
$elem.each(function() {
const $this = $(this)
if (!$this.hasClass('spoiler-build')) {
Expand All @@ -31,13 +31,27 @@
})
}

function buildNewSpoilers() {
for (const spoiler of document.querySelectorAll('details.custom-block-spoiler')) {
if (spoiler.querySelector('summary') === null) {
const summary = document.createElement('summary')
summary.classList.add('custom-block-heading')
summary.textContent = 'Afficher/Masquer le contenu masqué'
const body = spoiler.querySelector('.custom-block-body')
spoiler.insertBefore(summary, body)
}
}
}

$(document).ready(function() {
const $content = $('#content')
$('div.spoiler').addClass('custom-block-spoiler') /* for compatibility */
buildSpoilers($content.find('.custom-block-spoiler'))
buildOldSpoilers($content.find('div.custom-block-spoiler'))
buildNewSpoilers()
$content.on('DOMNodeInserted', function(e) {
const $spoilers = $(e.target).find('.custom-block-spoiler')
return buildSpoilers($spoilers)
const $spoilers = $(e.target).find('div.custom-block-spoiler')
buildOldSpoilers($spoilers)
return buildNewSpoilers()
})
})
})(jQuery)
2 changes: 1 addition & 1 deletion assets/scss/base/_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ h6 {
}
}

.js .spoiler, .custom-block-spoiler {
.js .spoiler, div.custom-block-spoiler {
display: none;
}

Expand Down

0 comments on commit d37d9db

Please sign in to comment.