Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bloque le chargement automatique des iframes #6610

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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