Skip to content
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

Preview v5: Skip initialisation when GOV.UK Frontend is not supported #2976

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/javascripts/components/back-to-top.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these identical constructor-y bits just make me want to do a base component sooner!

return this
}

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/components/cookie-banner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/components/cookies-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/components/copy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/components/example-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/components/example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/components/navigation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/components/search.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/components/tabs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/styles/page-template/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Use this template to keep your pages consistent with the rest of GOV.UK.

This page template combines the boilerplate markup and [components](/components/) needed for a basic GOV.UK page. It includes:

- JavaScript that adds a `.js-enabled` class, which is required by components with JavaScript behaviour
- JavaScript that adds a `.govuk-frontend-supported` class, which is required by components with JavaScript behaviour
- the [skip link](/components/skip-link/), [header](/components/header/) and [footer](/components/footer/) components
- the favicon, and other related theme icons

Expand Down
4 changes: 2 additions & 2 deletions src/stylesheets/components/_back-to-top.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
margin-bottom: govuk-spacing(8);
}

.js-enabled .app-back-to-top--fixed {
.govuk-frontend-supported .app-back-to-top--fixed {
position: fixed;
top: calc(100% - #{govuk-spacing(8)});
bottom: auto;
left: auto;
}

.js-enabled .app-back-to-top--hidden .app-back-to-top__link {
.govuk-frontend-supported .app-back-to-top--hidden .app-back-to-top__link {
@include govuk-visually-hidden-focusable;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/stylesheets/components/_navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@
list-style: none;
}

.js-enabled .app-navigation__subnav--active {
.govuk-frontend-supported .app-navigation__subnav--active {
display: block;
}

.app-navigation__subnav,
.js-enabled .app-navigation__subnav--active {
.govuk-frontend-supported .app-navigation__subnav--active {
@include govuk-media-query($from: tablet) {
display: none;
}
Expand Down
6 changes: 3 additions & 3 deletions src/stylesheets/components/_site-search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $icon-size: 40px;
margin-bottom: govuk-spacing(2);
float: left;

.js-enabled & {
.govuk-frontend-supported & {
display: block;
}

Expand All @@ -37,7 +37,7 @@ $icon-size: 40px;
float: right;
text-align: right;

.js-enabled & {
.govuk-frontend-supported & {
text-align: left;
}
}
Expand Down Expand Up @@ -205,7 +205,7 @@ $icon-size: 40px;
@include govuk-media-query($from: tablet) {
display: inline-block;

.js-enabled & {
.govuk-frontend-supported & {
display: none;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/stylesheets/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pre code {
outline: $govuk-focus-width solid $govuk-focus-colour;
}

.js-enabled [data-module="app-copy"] & {
.govuk-frontend-supported [data-module="app-copy"] & {
padding-top: 45px; // Allow extra space for the copy code button
}
}
Expand Down