From f5f35e48b7abee7fd8818f3125af7497129c4d1b Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 27 Jul 2023 17:43:13 +0100 Subject: [PATCH] Skip initialisation when GOV.UK Frontend is not supported See approach on GOV.UK Frontend https://github.com/alphagov/govuk-frontend/pull/3801/commits/7e1d0f4bfdcfc5e6866c62aa230a8320a8bd2fb5 --- src/javascripts/components/back-to-top.mjs | 2 +- src/javascripts/components/cookie-banner.mjs | 2 +- src/javascripts/components/cookies-page.mjs | 2 +- src/javascripts/components/copy.mjs | 2 +- src/javascripts/components/example-page.mjs | 2 +- src/javascripts/components/example.mjs | 2 +- src/javascripts/components/navigation.mjs | 2 +- src/javascripts/components/search.mjs | 2 +- src/javascripts/components/tabs.mjs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/javascripts/components/back-to-top.mjs b/src/javascripts/components/back-to-top.mjs index 228be7f88f..66291eb800 100644 --- a/src/javascripts/components/back-to-top.mjs +++ b/src/javascripts/components/back-to-top.mjs @@ -3,7 +3,7 @@ class BackToTop { * @param {Element} $module - HTML element */ constructor ($module) { - if (!($module instanceof HTMLElement)) { + if (!($module instanceof HTMLElement) || !document.body.classList.contains('govuk-frontend-supported')) { return this } diff --git a/src/javascripts/components/cookie-banner.mjs b/src/javascripts/components/cookie-banner.mjs index a58eab24da..3baa2084f3 100644 --- a/src/javascripts/components/cookie-banner.mjs +++ b/src/javascripts/components/cookie-banner.mjs @@ -12,7 +12,7 @@ class CookieBanner { * @param {Element} $module - HTML element */ constructor ($module) { - if (!($module instanceof HTMLElement)) { + if (!($module instanceof HTMLElement) || !document.body.classList.contains('govuk-frontend-supported')) { return this } diff --git a/src/javascripts/components/cookies-page.mjs b/src/javascripts/components/cookies-page.mjs index b57bd53efc..e9ae4c32f4 100644 --- a/src/javascripts/components/cookies-page.mjs +++ b/src/javascripts/components/cookies-page.mjs @@ -5,7 +5,7 @@ class CookiesPage { * @param {Element} $module - HTML element */ constructor ($module) { - if (!($module instanceof HTMLElement)) { + if (!($module instanceof HTMLElement) || !document.body.classList.contains('govuk-frontend-supported')) { return this } diff --git a/src/javascripts/components/copy.mjs b/src/javascripts/components/copy.mjs index 8d72bc6904..bdfa80d6fd 100644 --- a/src/javascripts/components/copy.mjs +++ b/src/javascripts/components/copy.mjs @@ -5,7 +5,7 @@ class Copy { * @param {Element} $module - HTML element */ constructor ($module) { - if (!($module instanceof HTMLElement)) { + if (!($module instanceof HTMLElement) || !document.body.classList.contains('govuk-frontend-supported')) { return this } diff --git a/src/javascripts/components/example-page.mjs b/src/javascripts/components/example-page.mjs index 16172e6fdf..c7f8d9cfa2 100644 --- a/src/javascripts/components/example-page.mjs +++ b/src/javascripts/components/example-page.mjs @@ -3,7 +3,7 @@ class ExamplePage { * @param {Document} $module - HTML document */ constructor ($module) { - if (!($module instanceof Document)) { + if (!($module instanceof Document) || !document.body.classList.contains('govuk-frontend-supported')) { return this } diff --git a/src/javascripts/components/example.mjs b/src/javascripts/components/example.mjs index 0930f0050e..0073e61d3c 100644 --- a/src/javascripts/components/example.mjs +++ b/src/javascripts/components/example.mjs @@ -13,7 +13,7 @@ class Example { * @param {Element} $module - HTML element */ constructor ($module) { - if (!($module instanceof HTMLIFrameElement)) { + if (!($module instanceof HTMLIFrameElement) || !document.body.classList.contains('govuk-frontend-supported')) { return } diff --git a/src/javascripts/components/navigation.mjs b/src/javascripts/components/navigation.mjs index 6f4310e9f8..40fb0db79c 100644 --- a/src/javascripts/components/navigation.mjs +++ b/src/javascripts/components/navigation.mjs @@ -9,7 +9,7 @@ class Navigation { * @param {Document} $module - HTML document */ constructor ($module) { - if (!($module instanceof Document)) { + if (!($module instanceof Document) || !document.body.classList.contains('govuk-frontend-supported')) { return this } diff --git a/src/javascripts/components/search.mjs b/src/javascripts/components/search.mjs index 14cb54bcb7..1fd97c64f9 100644 --- a/src/javascripts/components/search.mjs +++ b/src/javascripts/components/search.mjs @@ -36,7 +36,7 @@ class Search { * @param {Element} $module - HTML element */ constructor ($module) { - if (!($module instanceof HTMLElement)) { + if (!($module instanceof HTMLElement) || !document.body.classList.contains('govuk-frontend-supported')) { return this } diff --git a/src/javascripts/components/tabs.mjs b/src/javascripts/components/tabs.mjs index 2407226c6e..c54652e3ab 100644 --- a/src/javascripts/components/tabs.mjs +++ b/src/javascripts/components/tabs.mjs @@ -14,7 +14,7 @@ class AppTabs { * @param {Element} $module - HTML element */ constructor ($module) { - if (!($module instanceof HTMLElement)) { + if (!($module instanceof HTMLElement) || !document.body.classList.contains('govuk-frontend-supported')) { return this }