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 Aug 16, 2023
1 parent 4268004 commit aca5326
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 9 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 @@ -3,7 +3,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
5 changes: 4 additions & 1 deletion src/javascripts/components/cookie-banner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ 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
}

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 @@ -5,7 +5,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 @@ -5,7 +5,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 @@ -3,7 +3,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 @@ -9,7 +9,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 @@ -36,7 +36,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 @@ -14,7 +14,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 aca5326

Please sign in to comment.