Skip to content

Commit

Permalink
Bloque le chargement automatique des iframes
Browse files Browse the repository at this point in the history
  • Loading branch information
Situphen committed Apr 23, 2024
1 parent 7b70da3 commit 44637fc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
19 changes: 19 additions & 0 deletions assets/js/iframe-consent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(function() {
// Part of this script is hard-coded into the HTML code for performance reasons.
// It can be found at the bottom of template/base.html

for (const placeholder of document.querySelectorAll('.iframe-placeholder')) {
const message = document.createElement('p')
message.innerHTML = "Attention, ce contenu provient d'une source externe !"
const button = document.createElement('button')
button.innerHTML = 'Charger le contenu'
button.addEventListener('click', function(e) {
const placeholder = e.target.parentElement
const index = placeholder.dataset.iframeIndex
placeholder.outerHTML = window.iframeStash[index]
})

placeholder.appendChild(message)
placeholder.appendChild(button)
}
})()
13 changes: 13 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@ <h2 class="subtitle" {% if schema %}itemprop="description"{% endif %}>{{ headlin


{# Javascript stuff start #}
<script>
// This script is hard-coded into the HTML code for performance reasons.
// The rest of the code can be found in assets/js/iframe-consent.js
window.iframeStash = []
for (const [index, iframe] of document.querySelectorAll('iframe').entries()) {
window.iframeStash.push(iframe.outerHTML)
const placeholder = document.createElement('div')
placeholder.classList.add('iframe-placeholder')
placeholder.dataset.iframeIndex = index
iframe.parentElement.replaceChild(placeholder, iframe)
}
</script>

<script src="{% static "js/jquery.min.js" %}"></script>
{% block extra_js %}
{% endblock %}
Expand Down

0 comments on commit 44637fc

Please sign in to comment.