Skip to content

Commit

Permalink
Youtube consent - front-end (#183)
Browse files Browse the repository at this point in the history
* Youtube consent front-end
* Focus into video after accepting tcs and cs so screenreaders can play the video
* Don't focus on video unless you've just given consent, sort focus state, fix cookie in safari
* update docs
  • Loading branch information
helenb authored Mar 27, 2024
1 parent 3e9730e commit 87de571
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 126 deletions.
7 changes: 7 additions & 0 deletions docs/front-end/lite-youtube.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Lite youtube

We use the https://www.npmjs.com/package/lite-youtube-embed package to avoid setting youtube cookies, along with https://theorangeone.net/projects/wagtail-lite-youtube-embed/

When youtube videos are first loaded the user must accept the youtube Ts and Cs. They can opt not to show them again - this sets a cookie to hide the consent message in future.

This functionality is controlled by `tbx/static_src/javascript/components/youtube-embed.js`.
2 changes: 2 additions & 0 deletions docs/front-end/sustainability.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ We use dark mode by default.
All images should be renedered in the template file as webp format using the `format-webp` attribute - see https://docs.wagtail.org/en/v5.2.2/advanced_topics/images/image_file_formats.html.

We have a custom saturation filter that allows us to apply a slight desaturation to all images using `saturation-0.6` - this makes the file size of images smaller overall, as well as creating a cohesive look for photographic images.

Youtube videos are not loaded by default. Instead they show a placeholder image and a play button, and only load when the user clicks 'play'.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ nav:
- front-end/placeholder-images.md
- front-end/utility-classes.md
- 'Markdown block and codehilite': 'front-end/markdown-codehilite.md'
- front-end/lite-youtube.md
- 'Navigation': 'navigation.md'
- 'Custom features':
- 'Migration-friendly StreamFields': 'custom-features/migration-friendly-streamfields.md'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@
<path d="M23.23 93.268 9.994 91.731l.206-1.774 13.236 1.538-.206 1.773ZM11.28 94.625 9.68 94.44l.499-4.291 1.602.186-.499 4.291ZM26.774 73.615a4.794 4.794 0 0 1-1.83 2.213c-.835.541-1.818.84-2.95.898-1.144.053-2.36-.188-3.65-.722-1.288-.534-2.315-1.215-3.08-2.044-.76-.842-1.238-1.746-1.433-2.713a4.676 4.676 0 0 1 .256-2.825 4.736 4.736 0 0 1 1.83-2.213c.823-.547 1.798-.843 2.925-.888 1.132-.058 2.349.183 3.65.722 1.288.533 2.319 1.223 3.09 2.07.765.829 1.251 1.73 1.458 2.702.2.956.111 1.889-.266 2.8Zm-1.593-.619c.27-.65.327-1.291.173-1.923-.16-.649-.537-1.262-1.13-1.84-.591-.577-1.408-1.082-2.448-1.513-1.041-.43-1.969-.649-2.784-.654-.827-.01-1.521.16-2.082.51-.572.345-.993.842-1.262 1.493a3.023 3.023 0 0 0-.156 1.93c.15.644.52 1.255 1.112 1.832.585.561 1.398 1.057 2.439 1.488 1.04.431 1.972.658 2.794.68.827.01 1.527-.158 2.099-.503.56-.35.975-.85 1.245-1.5ZM36.92 53.4a4.794 4.794 0 0 1-2.424 1.543c-.96.259-1.988.241-3.083-.053-1.104-.301-2.188-.905-3.25-1.81-1.062-.904-1.83-1.868-2.302-2.893-.464-1.034-.64-2.042-.528-3.022a4.675 4.675 0 0 1 1.112-2.609 4.736 4.736 0 0 1 2.423-1.542c.95-.267 1.969-.25 3.055.054 1.095.294 2.179.897 3.25 1.81 1.063.905 1.831 1.878 2.305 2.92.473 1.025.658 2.032.555 3.02a4.662 4.662 0 0 1-1.114 2.583Zm-1.327-1.078c.457-.536.709-1.128.757-1.777.046-.666-.123-1.366-.509-2.098-.385-.731-1.007-1.462-1.864-2.193-.858-.73-1.674-1.223-2.448-1.479-.784-.264-1.496-.316-2.137-.155a3.052 3.052 0 0 0-1.66 1.032 3.022 3.022 0 0 0-.743 1.789c-.056.658.109 1.353.494 2.085.384.714 1.005 1.436 1.863 2.166.857.73 1.674 1.232 2.45 1.506.783.264 1.5.32 2.151.168.641-.16 1.19-.508 1.646-1.044ZM48.306 39.842l.23-15.827 1.484-.922-.23 15.827-1.484.922Zm6.74-3.96a2.62 2.62 0 0 1-1.35.41c-.477.01-.923-.09-1.339-.3a2.656 2.656 0 0 1-1.04-.981 2.52 2.52 0 0 1-.398-1.334 2.76 2.76 0 0 1 .315-1.349A2.62 2.62 0 0 1 52.2 31.3a2.62 2.62 0 0 1 1.35-.409c.488-.016.943.086 1.365.305a2.52 2.52 0 0 1 1.019.95c.27.435.41.89.42 1.366.002.466-.106.91-.326 1.333-.22.422-.547.769-.982 1.039Zm-.72-1.157c.327-.203.53-.472.608-.807.071-.345.002-.687-.207-1.024-.203-.326-.477-.525-.822-.597a1.217 1.217 0 0 0-.986.16 1.217 1.217 0 0 0-.58.813c-.079.335-.017.665.186.991.21.337.485.55.826.64.335.078.66.02.976-.176Zm-8.217-3.08c-.413.257-.857.39-1.334.4a2.76 2.76 0 0 1-1.348-.316 2.619 2.619 0 0 1-1.03-.965 2.665 2.665 0 0 1-.425-1.341c-.002-.465.106-.91.326-1.332.22-.423.541-.766.966-1.03.435-.27.89-.409 1.366-.418.477-.01.923.09 1.339.299.416.209.759.53 1.029.965.263.424.4.875.409 1.35.01.477-.096.927-.315 1.35-.21.415-.537.762-.983 1.038Zm-.718-1.158c.326-.202.528-.47.606-.806.072-.346.003-.687-.206-1.024-.21-.337-.487-.542-.833-.613a1.25 1.25 0 0 0-.975.176 1.249 1.249 0 0 0-.59.796c-.068.328.003.66.212.998.21.337.48.554.81.65.335.078.66.02.976-.177ZM83.173 23.584l-.565-13.313 1.803-.076.565 13.313-1.803.076Zm1.228-.052-.07-1.65 7.634-.324.07 1.65-7.634.324Zm-.256-6.023-.067-1.573 7.002-.298.067 1.573-7.002.298Zm-.24-5.64-.07-1.65 7.54-.32.07 1.65-7.54.32ZM104.267 22.54l3.68-12.806 1.218.35 2.864 10.471-.83-.238 7.986-7.354 1.218.35-3.68 12.806-1.735-.498 2.805-9.762.374.228-6.301 5.8-1.218-.35-2.261-8.26h.419l-2.804 9.762-1.735-.499ZM132.697 26.615l.889-1.3 2.995 2.048c.412.282.835.446 1.267.494.443.055.86-.01 1.249-.193.399-.177.744-.476 1.033-.899.289-.422.443-.852.462-1.288.03-.43-.061-.84-.273-1.234a2.772 2.772 0 0 0-.921-1.001l-2.995-2.048.888-1.3 3.091 2.113c.676.463 1.185 1.012 1.525 1.648.351.643.507 1.323.466 2.04-.022.713-.268 1.413-.738 2.1-.462.676-1.025 1.16-1.689 1.45a3.92 3.92 0 0 1-2.07.306c-.716-.086-1.412-.36-2.088-.823l-3.091-2.113Zm-3.924 3.597 7.52-11 1.49 1.018-7.52 11-1.49-1.018ZM145.927 42.276l10.269-8.491 1.15 1.39-10.269 8.491-1.15-1.39Zm.783.946 1.272-1.052 4.552 5.505-1.273 1.052-4.551-5.505ZM160.825 63.116a6.735 6.735 0 0 1-.515-2.65 6.77 6.77 0 0 1 .562-2.548 7.078 7.078 0 0 1 1.505-2.165 7.118 7.118 0 0 1 2.286-1.465 7.017 7.017 0 0 1 2.66-.54 7.024 7.024 0 0 1 2.563.494c.812.334 1.53.81 2.153 1.427a6.75 6.75 0 0 1 1.476 2.26 6.61 6.61 0 0 1-.037 5.174 6.846 6.846 0 0 1-1.487 2.157 6.943 6.943 0 0 1-2.296 1.49 6.887 6.887 0 0 1-5.238.01 6.57 6.57 0 0 1-2.171-1.419 6.56 6.56 0 0 1-1.461-2.225Zm1.587-.685c.361.89.877 1.585 1.55 2.086a4.83 4.83 0 0 0 2.34.916c.882.098 1.786-.04 2.711-.416a5.482 5.482 0 0 0 1.749-1.102c.49-.462.866-.98 1.13-1.557a4.404 4.404 0 0 0 .401-1.82 4.85 4.85 0 0 0-.38-1.96c-.355-.877-.872-1.572-1.55-2.085a4.732 4.732 0 0 0-2.314-.905c-.866-.091-1.761.05-2.687.426a6.065 6.065 0 0 0-1.791 1.1c-.49.46-.869.973-1.138 1.538a4.78 4.78 0 0 0-.401 1.82 4.945 4.945 0 0 0 .38 1.96ZM173.291 84.251l7.55-5.749.137 2.089-6.179 4.639-.062-.94 6.735 3.81.134 2.05-8.239-4.75-.076-1.149Zm-5.423.048 6.591-.433.118 1.801-6.59.433-.119-1.8ZM168.819 102.522l12.972 3.043-.412 1.757-12.973-3.043.413-1.757Zm-.281 1.196 1.608.377-1.746 7.44-1.607-.377 1.745-7.44Zm5.869 1.377 1.533.36-1.6 6.822-1.533-.359 1.6-6.823Zm5.496 1.289 1.608.377-1.724 7.347-1.607-.378 1.723-7.346ZM163.788 123.12l11.547 6.65-.901 1.564-11.546-6.65.9-1.564Zm-.613 1.065 1.431.824-3.814 6.622-1.431-.824 3.814-6.622Zm5.224 3.009 1.365.785-3.498 6.073-1.364-.786 3.497-6.072Zm4.892 2.817 1.431.824-3.766 6.539-1.431-.825 3.766-6.538ZM156.123 143.864l1.142 1.166-4.515 4.418-1.142-1.167 4.515-4.417ZM134.603 157.036a6.744 6.744 0 0 1 2.591-.759 6.79 6.79 0 0 1 2.59.323c.84.285 1.605.718 2.294 1.297a7.119 7.119 0 0 1 1.672 2.14c.441.852.703 1.719.785 2.599a7.029 7.029 0 0 1-.254 2.597 6.577 6.577 0 0 1-1.221 2.276 6.743 6.743 0 0 1-2.114 1.68 6.6 6.6 0 0 1-2.574.75 6.536 6.536 0 0 1-2.58-.306 6.853 6.853 0 0 1-2.286-1.28 6.929 6.929 0 0 1-1.697-2.148 6.883 6.883 0 0 1-.497-5.214 6.543 6.543 0 0 1 1.212-2.293 6.551 6.551 0 0 1 2.079-1.662Zm.83 1.516c-.853.442-1.497 1.021-1.933 1.737a4.836 4.836 0 0 0-.695 2.415c-.015.888.206 1.775.666 2.661a5.506 5.506 0 0 0 1.26 1.639 4.962 4.962 0 0 0 1.655.981 4.412 4.412 0 0 0 1.85.23 4.846 4.846 0 0 0 1.915-.56c.841-.436 1.485-1.015 1.933-1.737a4.74 4.74 0 0 0 .686-2.389c.01-.87-.214-1.749-.674-2.635a6.066 6.066 0 0 0-1.261-1.682 5.11 5.11 0 0 0-1.637-.989 4.754 4.754 0 0 0-1.85-.231c-.652.05-1.29.236-1.915.56ZM114.728 166.472l5.817 12.755-1.793.201-4.647-10.413.515-.058-2.165 11.178-1.297.146-4.589-10.42.496-.056-2.222 11.185-1.775.199 2.826-13.726 1.278-.143 4.607 10.399-.497.056 2.167-11.16 1.279-.143ZM89.517 168.761l-3.24 12.925-1.23-.309-.012-2.16 2.732-10.895 1.75.439Zm-8.939-2.241 5.277 12.585-.807 2.272-5.3-12.572.83-2.285Zm0 0 .04 2.048-2.759 11.007-1.75-.439 3.24-12.925 1.23.309ZM66.214 162.497l-7.029 11.32-1.533-.952 7.028-11.32 1.534.952Zm-1.044-.648-.871 1.402-6.492-4.03.87-1.403 6.493 4.031Zm-3.18 5.121-.83 1.338-5.955-3.697.83-1.337 5.955 3.696Zm-2.978 4.796-.87 1.403-6.411-3.98.87-1.403 6.411 3.98ZM47.858 150.838l-1.25 1.079-2.423-2.803c-.644-.746-1.369-1.262-2.174-1.547a4.544 4.544 0 0 0-2.48-.14c-.849.174-1.645.584-2.39 1.228-.737.636-1.252 1.361-1.548 2.174a4.546 4.546 0 0 0-.194 2.477c.166.838.567 1.625 1.203 2.361l2.41 2.789-1.248 1.08-2.436-2.818c-.636-.736-1.096-1.523-1.38-2.36a6.324 6.324 0 0 1-.346-2.544 6.272 6.272 0 0 1 .67-2.456c.383-.789.939-1.497 1.665-2.125a6.747 6.747 0 0 1 2.344-1.34 6.305 6.305 0 0 1 4.981.39 7.028 7.028 0 0 1 2.122 1.693l2.474 2.862Zm.778.9-10.082 8.713-1.18-1.365 10.082-8.713 1.18 1.365Z"/>
</g>
</symbol>

<symbol id="youtube" viewBox="409.289 277.787 512 114.301">
<g class="style-scope yt-icon"><g class="style-scope yt-icon"><path fill="red" d="M569.154 295.637a20.447 20.447 0 0 0-14.436-14.436c-12.728-3.414-63.79-3.414-63.79-3.414s-51.061 0-63.79 3.414a20.447 20.447 0 0 0-14.435 14.436c-3.414 12.728-3.414 39.3-3.414 39.3s0 26.573 3.414 39.302a20.446 20.446 0 0 0 14.435 14.435c12.729 3.414 63.79 3.414 63.79 3.414s51.062 0 63.79-3.414a20.446 20.446 0 0 0 14.436-14.435c3.414-12.729 3.414-39.301 3.414-39.301s-.014-26.573-3.414-39.301Z" class="style-scope yt-icon"/><path fill="#fff" d="m474.585 359.429 42.42-24.49-42.42-24.488v48.978Z" class="style-scope yt-icon"/></g><g class="style-scope yt-icon"><g class="style-scope yt-icon"><path d="M34.602 13.004 31.395 1.418h2.798l1.124 5.252c.287 1.294.497 2.397.633 3.31h.082c.094-.655.306-1.75.633-3.291l1.164-5.27h2.799L37.38 13.003v5.557H34.6v-5.557h.002ZM41.47 18.194c-.565-.381-.967-.974-1.207-1.778-.237-.805-.357-1.872-.357-3.208V11.39c0-1.348.136-2.432.409-3.248.273-.816.699-1.413 1.277-1.787.579-.374 1.338-.563 2.279-.563.927 0 1.667.191 2.227.572.558.381.967.978 1.225 1.787.26.812.389 1.891.389 3.239v1.818c0 1.336-.128 2.408-.38 3.217-.25.811-.66 1.404-1.224 1.778-.565.374-1.332.562-2.298.562-.997.002-1.776-.19-2.34-.571Zm3.165-1.962c.156-.409.236-1.074.236-2.001v-3.902c0-.898-.078-1.557-.236-1.97-.157-.417-.432-.624-.828-.624-.38 0-.651.207-.806.623-.158.417-.235 1.073-.235 1.971v3.902c0 .927.075 1.594.225 2.001.15.41.421.614.816.614.396 0 .67-.204.828-.614ZM56.815 18.563H54.61l-.244-1.533h-.061c-.6 1.157-1.498 1.736-2.698 1.736-.83 0-1.444-.273-1.839-.816-.395-.546-.593-1.397-.593-2.554V6.037h2.82v9.193c0 .56.061.957.184 1.195.122.237.327.357.613.357.245 0 .48-.075.706-.226.226-.15.39-.34.5-.571v-9.95h2.818v12.527Z" class="style-scope yt-icon" style="fill:#282828" transform="matrix(5.71504 0 0 5.71504 409.289 277.787)"/><path d="M64.475 3.688h-2.798v14.875h-2.759V3.688H56.12V1.42h8.356v2.268Z" class="style-scope yt-icon" style="fill:#282828" transform="matrix(5.71504 0 0 5.71504 409.289 277.787)"/><path d="M71.277 18.563H69.07l-.245-1.533h-.06c-.6 1.157-1.499 1.736-2.699 1.736-.83 0-1.443-.273-1.839-.816-.395-.546-.592-1.397-.592-2.554V6.037h2.82v9.193c0 .56.06.957.183 1.195.122.237.327.357.614.357.244 0 .48-.075.705-.226.226-.15.39-.34.501-.571v-9.95h2.818v12.527ZM80.609 8.039c-.172-.79-.447-1.362-.828-1.717-.38-.355-.905-.532-1.573-.532-.518 0-1.002.146-1.451.44-.45.294-.798.677-1.042 1.155h-.021v-6.6h-2.717v17.776h2.329l.287-1.186h.06c.22.424.546.755.981 1.002.436.245.92.367 1.451.367.953 0 1.656-.44 2.105-1.317.45-.88.675-2.25.675-4.118v-1.982c0-1.4-.087-2.498-.256-3.288Zm-2.585 5.11c0 .913-.037 1.628-.113 2.145-.075.518-.2.887-.378 1.103a.871.871 0 0 1-.715.327c-.233 0-.447-.054-.645-.165a1.232 1.232 0 0 1-.48-.489V8.96c.095-.34.26-.618.492-.837.23-.218.485-.327.755-.327a.76.76 0 0 1 .663.337c.158.226.266.602.327 1.133.061.532.092 1.287.092 2.268v1.615h.002ZM84.866 13.871c0 .804.023 1.407.07 1.809.047.402.146.694.297.88.15.183.38.274.693.274.421 0 .713-.164.868-.491.158-.327.243-.873.257-1.634l2.431.143c.014.108.022.259.022.45 0 1.156-.318 2.022-.95 2.593-.633.572-1.53.859-2.686.859-1.39 0-2.364-.436-2.921-1.308-.56-.873-.838-2.22-.838-4.045v-2.187c0-1.88.29-3.253.868-4.118.579-.866 1.569-1.299 2.973-1.299.966 0 1.71.177 2.227.532.517.355.882.905 1.094 1.656.211.75.317 1.785.317 3.106v2.145h-4.722v.635Zm.357-5.903c-.143.176-.237.466-.287.868-.047.402-.07 1.011-.07 1.83v.898h2.062v-.898c0-.805-.028-1.414-.082-1.83-.054-.416-.153-.708-.296-.88-.144-.169-.365-.256-.664-.256-.3.002-.522.092-.663.268Z" class="style-scope yt-icon" style="fill:#282828" transform="matrix(5.71504 0 0 5.71504 409.289 277.787)"/></g></g></g>
</symbol>
</svg>
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
{% load static %}

<div class="grid__embed streamfield__embed youtube-video-container">
{% if is_youtube %}
<div class="youtube-video-placeholder">
{% if is_youtube %}
<div class="grid__embed streamfield__embed youtube-embed" data-youtube-embed>
<div class="youtube-embed__placeholder">
{% if thumbnail_url %}
<img src="{{ thumbnail_url }}" alt="Video Thumbnail">
<img src="{{ thumbnail_url }}" alt="Video Thumbnail" class="youtube-embed__thumbnail-image">
{% else %}
{% comment %}
We need a placeholder here just in case we fail to get the thumbnail_url for some reason
{% endcomment %}
{# Fallback if we can't fetch a preview image from youtube #}
<div class="youtube-embed__fallback">{% include "patterns/atoms/icons/icon.html" with name="youtube" classname="youtube-embed__logo" %}</div>
{% endif %}
<div class="youtube-overlay">
<div class="consent-banner">This content is hosted by a third party. By showing the external content you accept the <a href="https://www.youtube.com/t/terms" target="_blank">terms and conditions</a> of YouTube.</div>
<div class="button-container">
<button class="consent-button">
Proceed
{# https://tabler.io/icons/icon/player-play #}
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-player-play"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 4v16l13 -8z" /></svg>
</button>
<button class="dont-ask-again-button">
Don't Ask Again
{# https://tabler.io/icons/icon/device-floppy #}
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-device-floppy"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2" /><path d="M12 14m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" /><path d="M14 4l0 4l-6 0l0 -4" /></svg>
</button>
<div class="youtube-embed__overlay">
<div class="youtube-embed__consent-banner">
<p>This content is hosted by a third party. By showing the external content you accept the <a class="youtube-embed__link" href="https://www.youtube.com/t/terms" target="_blank">terms and conditions</a> of YouTube.</p>
<div class="youtube-embed__button-container">
<button class="button youtube-embed__button" data-youtube-consent-button>
I accept
</button>
<div class="youtube-embed__checkbox-wrapper">
<input type="checkbox" id="youtube-consent-checkbox" data-youtube-save-prefs class="youtube-embed__checkbox">
<label for="youtube-consent-checkbox" class="youtube-embed__label">Don't ask me again</label>
</div>
</div>
</div>
</div>
</div>
<div class="youtube-embed" style="display: none;">
<div class="youtube-embed__container" data-youtube-embed-container>
{{ value }}
</div>
{% else %}
</div>
{% else %}
<div class="grid__embed streamfield__embed">
{{ value }}
{% endif %}
</div>
</div>
{% endif %}

Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
context:
value: <iframe width="420" height="315" src="https://www.youtube.com/embed/9ZY4QUhOb4Y"></iframe>
is_youtube: True
thumbnail_url: https://i.ytimg.com/vi/g9kZwNEHmdw/hqdefault.jpg
54 changes: 22 additions & 32 deletions tbx/static_src/javascript/components/youtube-embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,55 @@ import Cookies from 'js-cookie';
*/
class YouTubeConsentManager {
static selector() {
return '.grid__embed.streamfield__embed.youtube-video-container';
return '[data-youtube-embed]';
}

/**
* Create a new YouTubeConsentManager.
*/
constructor(node) {
this.consentButtonClass = 'consent-button';
this.dontAskAgainButtonClass = 'dont-ask-again-button';
this.videoPlaceholderClass = 'youtube-video-placeholder';
this.youtubeEmbedClass = 'youtube-embed';

this.youtubeEmbedContainer = node;
this.consentButton = this.youtubeEmbedContainer.querySelector(
`.${this.consentButtonClass}`,
);
this.dontAskAgainButton = this.youtubeEmbedContainer.querySelector(
`.${this.dontAskAgainButtonClass}`,
this.youtubeEmbedNode = node;
this.consentButton = this.youtubeEmbedNode.querySelector(
'[data-youtube-consent-button]',
);
this.videoPlaceholder = this.youtubeEmbedContainer.querySelector(
`.${this.videoPlaceholderClass}`,
this.dontAskAgainCheckbox = this.youtubeEmbedNode.querySelector(
'[data-youtube-save-prefs]',
);
this.youtubeEmbed = this.youtubeEmbedContainer.querySelector(
`.${this.youtubeEmbedClass}`,
this.embedContainer = this.youtubeEmbedNode.querySelector(
'[data-youtube-embed-container]',
);
this.bindEvents();
}

// Bind event handlers
this.consentButton.addEventListener(
'click',
this.handleconsentClick.bind(this),
);
this.dontAskAgainButton.addEventListener(
'click',
this.handleDontAskAgainClick.bind(this),
);
bindEvents() {
this.consentButton.addEventListener('click', () => {
this.handleconsentClick();
});

// Check if consent has been given previously
this.checkConsent();
}

loadYouTubeEmbed() {
// Hide the video placeholder
this.videoPlaceholder.style.display = 'none';
// Show the YouTube embed container
this.youtubeEmbed.style.display = 'block';
// Hide the video placeholder and show the YouTube embed container
this.youtubeEmbedNode.classList.add('loaded');
}

handleconsentClick() {
if (this.dontAskAgainCheckbox.checked) {
this.handleDontAskAgainClick();
}
this.loadYouTubeEmbed();
this.embedContainer.querySelector('button').focus();
}

handleDontAskAgainClick() {
// Set a cookie to remember the user's choice not to ask again
Cookies.set('youtube_consent', 'true', {
expires: 7,
secure: true,
expires: 365,
sameSite: 'Lax',
});
this.dontAskAgainButton.style.display = 'none';

this.loadYouTubeEmbed();
}

Expand Down
3 changes: 2 additions & 1 deletion tbx/static_src/javascript/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import foreachPolyfill from './polyfills/foreach-polyfill';
import closestPolyfill from './polyfills/closest-polyfill';

import '../sass/main.scss';
import 'lite-youtube-embed/src/lite-yt-embed.css';

// Third party imports
import 'lite-youtube-embed/src/lite-yt-embed';

foreachPolyfill();
Expand Down
1 change: 0 additions & 1 deletion tbx/static_src/sass/components/_promo.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
&__button {
width: fit-content;
color: var(--color--light-background-text);
background-color: transparent;
border-color: var(--color--light-background-text);

&:hover,
Expand Down
Loading

0 comments on commit 87de571

Please sign in to comment.