Skip to content

Commit

Permalink
Skip initialisation when GOV.UK Frontend is not supported
Browse files Browse the repository at this point in the history
See approach on GOV.UK Frontend alphagov/govuk-frontend@7e1d0f4
  • Loading branch information
colinrotherham committed Sep 28, 2023
1 parent ed6a62a commit 693bf28
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/javascripts/components/back-to-top.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ 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
}

Expand Down
1 change: 1 addition & 0 deletions src/javascripts/components/cookie-banner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CookieBanner {
constructor($module) {
if (
!($module instanceof HTMLElement) ||
!document.body.classList.contains('govuk-frontend-supported') ||
// Exit if we're on the cookies page to avoid circular journeys
this.onCookiesPage()
) {
Expand Down
5 changes: 4 additions & 1 deletion src/javascripts/components/cookies-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ 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
}

Expand Down
5 changes: 4 additions & 1 deletion src/javascripts/components/copy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ 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
}

Expand Down
5 changes: 4 additions & 1 deletion src/javascripts/components/example-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ 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
}

Expand Down
5 changes: 4 additions & 1 deletion src/javascripts/components/example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ 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
}

Expand Down
5 changes: 4 additions & 1 deletion src/javascripts/components/navigation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ 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
}

Expand Down
5 changes: 4 additions & 1 deletion src/javascripts/components/search.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ 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
}

Expand Down
5 changes: 4 additions & 1 deletion src/javascripts/components/tabs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ 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
}

Expand Down

0 comments on commit 693bf28

Please sign in to comment.