-
Notifications
You must be signed in to change notification settings - Fork 245
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
EmbedCard
improvements
#4503
base: main
Are you sure you want to change the base?
EmbedCard
improvements
#4503
Conversation
If `IntersectionObserver` is not supported by the browser (it's not present on `window`) then don't run the `IntersectionObserver` code in `application.mjs` to enable lazy-load of the Youtube embeds. Instead, the fallback (linking to the Youtube video) will be used.
✅ You can preview this change here:
To edit notification comments on pull requests, go to your Netlify site configuration. |
5a892a3
to
c711114
Compare
c711114
to
1c41f10
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers for making these updates, I think it's getting there, just noticed a couple of little things as I went through 🙌🏻
@@ -113,6 +113,9 @@ class CookieBanner extends ConfigurableComponent { | |||
// Hide banner and show confirmation message | |||
this.$cookieMessage.setAttribute('hidden', 'true') | |||
this.revealConfirmationMessage(this.$cookieConfirmationAccept) | |||
|
|||
// Dispatch custom event to notify listening components of change | |||
document.dispatchEvent(new CustomEvent('cookieChange')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌🏻 I like that as an option to let the cookie banner make other parts of the page aware cookies were accepted.
if (userConsent && userConsent.campaign) { | ||
addEmbedCardObservers($embedCards) | ||
} else { | ||
document.addEventListener('cookieChange', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isssue This will also trigger when the cookies are rejected, as the event is also fired in rejectCookies
. Given we're now only setting up observers if cookies are accepted, I propose:
- not dispatching an event in
rejectCookies
as we have no code responding to that - renaming the event in
acceptCookies
tocookieAccepted
(in case we need acookieRejected
in the future)
@@ -440,6 +440,6 @@ pre .language-plaintext { | |||
} | |||
} | |||
|
|||
.app-campaign-cookie-banner .govuk-grid-column-two-thirds { | |||
.app-campaign-cookie-banner div { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue div
is quite generic and we risk side effects from this selector. I've asked on Slack for other ideas to avoid contradicting two-thirds
in the name with 100%
in the properties.
src/embed-test.md
Outdated
@@ -47,11 +41,6 @@ ignoreInSitemap: true | |||
{% call embedCard({ | |||
ytId: "x91MPoITQ3I", | |||
transcriptHref: "https://www.google.com", | |||
authorImgSrc: "/images/dsd24-day1-speakers1.png", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue Could we have a second embed card that shows the author image, and possibly a test using it if there's none already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added another template, seems difficult to determine intersection in puppeteer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's a shame, that would have allowed us to automatically test the IntersectionObserver
worked as well 😔 Is it a lack of native methods from Puppeteer for triggering the intersection (if it is we can maybe try with native DOM methods like scrollIntoView
) or just more general issues with IntersectionObserver?
1c41f10
to
1c3e211
Compare
- EmbedCard initialisation moved to `embed-initialisation.mjs` - Fire `cookieChange` event when user accepts/rejects cookies - Add `IntersectionObserver` if user has accepted cookies already or if user accepts cookies on current page
73f9e07
to
127c76c
Compare
Instead of creating the new element, appending the new element and then deleting the placeholder element. Now we replace the placeholder with the new element instead of deleting the placeholder explicitly.
Remove confusing `.app-campaign-cookie-banner .govuk-grid-column-two-thirds` selector and replace with `div`.
Remove previous page for testing that was a draft of a Design System Day promotion page. Add new `embed-test` page specifically for testing `EmbedCard` and cookies.
If thumbnail image fails to load in the EmbedCard placeholder, it will no longer collapse the size of the placeholder link.
YouTube Thumbnail API sets cookies so use a thumbnail image from the application itself instead.
127c76c
to
12d68c3
Compare
12d68c3
to
8a93428
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers for the updates. Noticed two extra things that I didn't spot in the previous review, sorry 😔
@@ -113,6 +113,9 @@ class CookieBanner extends ConfigurableComponent { | |||
// Hide banner and show confirmation message | |||
this.$cookieMessage.setAttribute('hidden', 'true') | |||
this.revealConfirmationMessage(this.$cookieConfirmationAccept) | |||
|
|||
// Dispatch custom event to notify listening components of change | |||
document.dispatchEvent(new CustomEvent('cookieAccepted')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue Something I didn't think about with the first comment, sorry, is that there might be two cookie banners on the page (the top one and the one for the videos). We need to distinguish which cookies have been accepted in that event, as videos can only be enabled if the campaign
cookie was accepted.
subtree: true | ||
}) | ||
} | ||
embedCardsInitialisation() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick For consistency with createAll
we should probably write this as initialiseEmbedCards
(active verb rather than a noun).
What
Addresses comments left on the previous PR.
This includes:
IntersectionObserver
supported by browser before running code that addsIntersectionObserver
sEmbedCard
initialisation to a separate function, add extra functionality to cookie accepting/rejecting that would lend itself well to adding external content in the futurealt
of theEmbedCard
placeholder thumbnailreplaceWith
inEmbedCard
initialisation, removediv
placeholder from template.app-campaign-cookie-banner .govuk-grid-column-two-thirds
selector to.app-campaign-cookie-banner div
EmbedCard
andcookies
ytID
instead of extracting the ID of YouTube video fromhref
of linkWhy
So that the EmbedCard component can be used to enhance the site and we can in the future add other external embeddable functionality (such as Soundcloud, Vimeo, etc).