diff --git a/Gemfile.lock b/Gemfile.lock index 9b04fb4845..6f1b4aede4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,6 +10,7 @@ PATH rouge sprockets (>= 3) sprockets-rails + terser GEM remote: https://rubygems.org/ diff --git a/app/assets/config/govuk_publishing_components_manifest.js b/app/assets/config/govuk_publishing_components_manifest.js index 2fe27c8045..5d2f149b13 100644 --- a/app/assets/config/govuk_publishing_components_manifest.js +++ b/app/assets/config/govuk_publishing_components_manifest.js @@ -1,7 +1,8 @@ // Pre-compile image and font assets from here and govuk-frontend //= link_tree ../images -//= link_tree ../../../node_modules/govuk-frontend/govuk/assets/images -//= link_tree ../../../node_modules/govuk-frontend/govuk/assets/fonts +//= link_tree ../../../node_modules/govuk-frontend/dist/govuk/assets/images +//= link_tree ../../../node_modules/govuk-frontend/dist/govuk/assets/fonts +//= link_tree ../../../node_modules/govuk-frontend/dist/govuk/assets // Create asset files of each of the files in these directory //= link_directory ../javascripts/component_guide diff --git a/app/assets/config/govuk_publishing_components_sassc-rails_manifest.js b/app/assets/config/govuk_publishing_components_sassc-rails_manifest.js index e738d35d46..c8a4559df8 100644 --- a/app/assets/config/govuk_publishing_components_sassc-rails_manifest.js +++ b/app/assets/config/govuk_publishing_components_sassc-rails_manifest.js @@ -1,7 +1,7 @@ // Pre-compile image and font assets from here and govuk-frontend //= link_tree ../images -//= link_tree ../../../node_modules/govuk-frontend/govuk/assets/images -//= link_tree ../../../node_modules/govuk-frontend/govuk/assets/fonts +//= link_tree ../../../node_modules/govuk-frontend/dist/govuk/assets/images +//= link_tree ../../../node_modules/govuk-frontend/dist/govuk/assets/fonts // Create asset files of each of the files in these directory //= link_directory ../javascripts/component_guide diff --git a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.js b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.js index 9f36748f2d..8eec07a8d0 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.js @@ -8,6 +8,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.module = module this.trackingTrigger = 'data-ga4-auto' this.PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover() + + this.init() } Ga4AutoTracker.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js index 7404004b18..23db841d23 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js @@ -1,4 +1,3 @@ -//= require govuk/vendor/polyfills/Element/prototype/closest.js ;(function (global) { 'use strict' diff --git a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js index 6df16f3a9f..f1a2ce36b4 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js @@ -8,6 +8,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; function Ga4EventTracker (module) { this.module = module this.trackingTrigger = 'data-ga4-event' // elements with this attribute get tracked + + this.init() } Ga4EventTracker.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js index 946a3d0016..849e45c09f 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js @@ -11,6 +11,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.trackLinksOnly = this.module.hasAttribute('data-ga4-track-links-only') this.limitToElementClass = this.module.getAttribute('data-ga4-limit-to-element-class') this.PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover() + + this.init() } Ga4LinkTracker.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js index 3b4e0cbe30..468fbeaf67 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js @@ -1,4 +1,3 @@ -// = require govuk/vendor/polyfills/Element/prototype/closest.js window.GOVUK = window.GOVUK || {} window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {} window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analyticsModules || {}; diff --git a/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js b/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js index 73306b007d..84076cd0bc 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js @@ -14,6 +14,8 @@ window.GOVUK.analyticsVars = window.GOVUK.analyticsVars || {}; resizeTimeoutDelay: 100, pageHeightTimeoutDelay: 500 } + + this.init() } AutoScrollTracker.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js b/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js index 9d367447c7..a7e9d133a0 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js @@ -4,6 +4,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function AutoTrackEvent ($module) { this.$module = $module + + this.init() } AutoTrackEvent.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.js b/app/assets/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.js index 63c5155300..3b89b288a0 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.js @@ -5,6 +5,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; function CrossDomainTracking ($module) { this.$module = $module Modules.crossDomainLinkedTrackers = Modules.crossDomainLinkedTrackers || [] + + this.init() } CrossDomainTracking.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js b/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js index e0dabf3040..ec75a0e34b 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js @@ -4,6 +4,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function ExplicitCrossDomainLinks ($module) { this.$module = $module + + this.init() } ExplicitCrossDomainLinks.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js b/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js index 50d4f5fdec..c130f37e5c 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js @@ -1,4 +1,3 @@ -// = require govuk/vendor/polyfills/Element/prototype/closest.js ;(function (global) { 'use strict' diff --git a/app/assets/javascripts/govuk_publishing_components/analytics/track-click.js b/app/assets/javascripts/govuk_publishing_components/analytics/track-click.js index 03e3f51419..8cab9277fd 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics/track-click.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics/track-click.js @@ -6,6 +6,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function GemTrackClick ($module) { this.$module = $module + + this.init() } GemTrackClick.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js b/app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js index 21d50d58ee..ba4829f538 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js @@ -4,6 +4,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function TrackSelectChange ($module) { this.$module = $module + + this.init() } TrackSelectChange.prototype.init = function ($module) { diff --git a/app/assets/javascripts/govuk_publishing_components/components/accordion.js b/app/assets/javascripts/govuk_publishing_components/components/accordion.js index e56818c510..b959d781c7 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/accordion.js +++ b/app/assets/javascripts/govuk_publishing_components/components/accordion.js @@ -1,7 +1,7 @@ /* global nodeListForEach */ // = require ../vendor/polyfills/common.js // This component relies on JavaScript from GOV.UK Frontend -// = require govuk/components/accordion/accordion.js +// = require govuk/components/accordion/accordion.bundle.js window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {} window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion; @@ -21,6 +21,8 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion; // language attribute pulled from data attributes this.$module.actions = {} this.$module.actions.locale = this.$module.getAttribute('data-locale') + + this.init() } GemAccordion.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/button.js b/app/assets/javascripts/govuk_publishing_components/components/button.js index 7f95df0a54..74008eb64c 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/button.js +++ b/app/assets/javascripts/govuk_publishing_components/components/button.js @@ -1,5 +1,5 @@ // This component relies on JavaScript from GOV.UK Frontend -// = require govuk/components/button/button.js +// = require govuk/components/button/button.bundle.js window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {} window.GOVUK.Modules.GovukButton = window.GOVUKFrontend.Button diff --git a/app/assets/javascripts/govuk_publishing_components/components/character-count.js b/app/assets/javascripts/govuk_publishing_components/components/character-count.js index 3fac518369..78c9a1e7a0 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/character-count.js +++ b/app/assets/javascripts/govuk_publishing_components/components/character-count.js @@ -1,5 +1,5 @@ // This component relies on JavaScript from GOV.UK Frontend -// = require govuk/components/character-count/character-count.js +// = require govuk/components/character-count/character-count.bundle.js window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {} window.GOVUK.Modules.GovukCharacterCount = window.GOVUKFrontend.CharacterCount diff --git a/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js b/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js index 2670693873..b802198660 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +++ b/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js @@ -1,5 +1,4 @@ -// = require govuk/vendor/polyfills/Element/prototype/closest.js -// = require govuk/components/checkboxes/checkboxes.js +// = require govuk/components/checkboxes/checkboxes.bundle.js window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {} window.GOVUK.Modules.GovukCheckboxes = window.GOVUKFrontend.Checkboxes; @@ -9,6 +8,8 @@ window.GOVUK.Modules.GovukCheckboxes = window.GOVUKFrontend.Checkboxes; this.$module = $module this.$checkboxes = this.$module.querySelectorAll('input[type=checkbox]') this.$nestedCheckboxes = this.$module.querySelectorAll('[data-nested=true] input[type=checkbox]') + + this.init() } GemCheckboxes.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/contextual-guidance.js b/app/assets/javascripts/govuk_publishing_components/components/contextual-guidance.js index 6ae776b654..0b0b094426 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/contextual-guidance.js +++ b/app/assets/javascripts/govuk_publishing_components/components/contextual-guidance.js @@ -7,6 +7,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.$guidance = this.$module.querySelector('.gem-c-contextual-guidance__wrapper') this.$inputId = this.$guidance.getAttribute('for') this.$input = this.$module.querySelector('#' + this.$inputId) + + this.init() } ContextualGuidance.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js b/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js index f982eee389..7e26de8e48 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js +++ b/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js @@ -6,6 +6,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.$module = $module this.$module.cookieBannerConfirmationMessage = this.$module.querySelector('.gem-c-cookie-banner__confirmation') this.$module.cookieBannerConfirmationMessageText = this.$module.querySelector('.gem-c-cookie-banner__confirmation-message') + + this.init() } CookieBanner.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/copy-to-clipboard.js b/app/assets/javascripts/govuk_publishing_components/components/copy-to-clipboard.js index 9310e4ca82..bd69aa8186 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/copy-to-clipboard.js +++ b/app/assets/javascripts/govuk_publishing_components/components/copy-to-clipboard.js @@ -6,6 +6,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.$module = $module this.$input = this.$module.querySelector('.gem-c-input') this.$copyButton = this.$module.querySelector('.gem-c-button') + + this.init() } CopyToClipboard.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/cross-service-header.js b/app/assets/javascripts/govuk_publishing_components/components/cross-service-header.js index 9c53e27926..af789cc3e2 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/cross-service-header.js +++ b/app/assets/javascripts/govuk_publishing_components/components/cross-service-header.js @@ -11,6 +11,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.$header = $module this.$navigation = $module && $module.querySelectorAll('[data-one-login-header-nav]') this.$numberOfNavs = this.$navigation && this.$navigation.length + + this.init() } /** * Initialise header diff --git a/app/assets/javascripts/govuk_publishing_components/components/details.js b/app/assets/javascripts/govuk_publishing_components/components/details.js index 36665e5758..ed15d126e7 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/details.js +++ b/app/assets/javascripts/govuk_publishing_components/components/details.js @@ -1,7 +1,5 @@ -// = require govuk/components/details/details.js window.GOVUK = window.GOVUK || {} -window.GOVUK.Modules = window.GOVUK.Modules || {} -window.GOVUK.Modules.GovukDetails = window.GOVUKFrontend.Details; +window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function GemDetails ($module) { @@ -10,6 +8,8 @@ window.GOVUK.Modules.GovukDetails = window.GOVUKFrontend.Details; this.customTrackLabel = this.$summary.getAttribute('data-track-label') this.detailsClick = this.$module.querySelector('[data-details-track-click]') + + this.init() } GemDetails.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/error-summary.js b/app/assets/javascripts/govuk_publishing_components/components/error-summary.js index 8378ed13e5..60fe3008f8 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/error-summary.js +++ b/app/assets/javascripts/govuk_publishing_components/components/error-summary.js @@ -1,5 +1,5 @@ // This component relies on JavaScript from GOV.UK Frontend -// = require govuk/components/error-summary/error-summary.js +// = require govuk/components/error-summary/error-summary.bundle.js window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {} window.GOVUK.Modules.GovukErrorSummary = window.GOVUKFrontend.ErrorSummary diff --git a/app/assets/javascripts/govuk_publishing_components/components/feedback.js b/app/assets/javascripts/govuk_publishing_components/components/feedback.js index 796db2568e..0809b2057f 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/feedback.js +++ b/app/assets/javascripts/govuk_publishing_components/components/feedback.js @@ -21,6 +21,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.jshiddenClass = 'js-hidden' this.whatDoingInput = this.$module.querySelector('[name=what_doing]') this.whatWrongInput = this.$module.querySelector('[name=what_wrong]') + + // this.init() } Feedback.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/govspeak.js b/app/assets/javascripts/govuk_publishing_components/components/govspeak.js index 505c63ba51..aa916aeba2 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/govspeak.js +++ b/app/assets/javascripts/govuk_publishing_components/components/govspeak.js @@ -4,6 +4,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function Govspeak ($module) { this.$module = $module + + this.init() } Govspeak.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/image-card.js b/app/assets/javascripts/govuk_publishing_components/components/image-card.js index aac62e987a..084d9a51db 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/image-card.js +++ b/app/assets/javascripts/govuk_publishing_components/components/image-card.js @@ -5,6 +5,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; function ImageCard ($module) { this.$module = $module this.$module.youtubeLink = this.$module.querySelector('.gem-c-image-card__image-wrapper div') + + this.init() } ImageCard.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/intervention.js b/app/assets/javascripts/govuk_publishing_components/components/intervention.js index 1ea158a31a..e60c7c69fb 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/intervention.js +++ b/app/assets/javascripts/govuk_publishing_components/components/intervention.js @@ -7,6 +7,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.$closeLink = this.$module.querySelector('.js-dismiss-link') this.$campaignName = this.$module.getAttribute('data-intervention-name') this.$campaignCookie = window.GOVUK.cookie('intervention_campaign') || '' + + this.init() } Intervention.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/layout-header.js b/app/assets/javascripts/govuk_publishing_components/components/layout-header.js index b4c526acb0..a3ac49d8cf 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/layout-header.js +++ b/app/assets/javascripts/govuk_publishing_components/components/layout-header.js @@ -1,5 +1,5 @@ // This component relies on JavaScript from GOV.UK Frontend -// = require govuk/components/header/header.js +// = require govuk/components/header/header.bundle.js window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {} window.GOVUK.Modules.GovukHeader = window.GOVUKFrontend.Header diff --git a/app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js b/app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js index 553123fea2..448d342043 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js +++ b/app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js @@ -1,5 +1,3 @@ -//= require govuk/vendor/polyfills/Element/prototype/classList.js - window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {}; @@ -107,6 +105,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; ) this.hiddenButtons = this.$module.querySelectorAll('button[hidden]') + + this.init() } SuperNavigationMegaMenu.prototype.buttonHandler = function (event) { diff --git a/app/assets/javascripts/govuk_publishing_components/components/metadata.js b/app/assets/javascripts/govuk_publishing_components/components/metadata.js index 0c85703cf4..d73a37f0c5 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/metadata.js +++ b/app/assets/javascripts/govuk_publishing_components/components/metadata.js @@ -4,6 +4,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function Metadata ($module) { this.$module = $module + + this.init() } Metadata.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/modal-dialogue.js b/app/assets/javascripts/govuk_publishing_components/components/modal-dialogue.js index 241647d07d..d5c73f8c20 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/modal-dialogue.js +++ b/app/assets/javascripts/govuk_publishing_components/components/modal-dialogue.js @@ -8,6 +8,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.$closeButton = this.$module.querySelector('.gem-c-modal-dialogue__close-button') this.$html = document.querySelector('html') this.$body = document.querySelector('body') + + this.init() } ModalDialogue.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/option-select.js b/app/assets/javascripts/govuk_publishing_components/components/option-select.js index f25a1b1e9b..98d23b2653 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/option-select.js +++ b/app/assets/javascripts/govuk_publishing_components/components/option-select.js @@ -19,6 +19,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.mq = window.matchMedia('(min-width: 641px)') this.isClosedOnLoad = this.$optionSelect.getAttribute('data-closed-on-load') this.isClosedOnLoadMobile = this.$optionSelect.getAttribute('data-closed-on-load-mobile') + + this.init() } OptionSelect.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/print-link.js b/app/assets/javascripts/govuk_publishing_components/components/print-link.js index 8a6bb78a86..8834b4764e 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/print-link.js +++ b/app/assets/javascripts/govuk_publishing_components/components/print-link.js @@ -4,6 +4,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function PrintLink ($module) { this.$module = $module + + this.init() } PrintLink.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/radio.js b/app/assets/javascripts/govuk_publishing_components/components/radio.js index 0ede1d0f19..76597f39d0 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/radio.js +++ b/app/assets/javascripts/govuk_publishing_components/components/radio.js @@ -1,5 +1,5 @@ // This component relies on JavaScript from GOV.UK Frontend -// = require govuk/components/radios/radios.js +// = require govuk/components/radios/radios.bundle.js window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {} window.GOVUK.Modules.GovukRadios = window.GOVUKFrontend.Radios diff --git a/app/assets/javascripts/govuk_publishing_components/components/reorderable-list.js b/app/assets/javascripts/govuk_publishing_components/components/reorderable-list.js index 8cf4d117b5..8f0233d2eb 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/reorderable-list.js +++ b/app/assets/javascripts/govuk_publishing_components/components/reorderable-list.js @@ -7,6 +7,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.$module = $module this.$upButtons = this.$module.querySelectorAll('.js-reorderable-list-up') this.$downButtons = this.$module.querySelectorAll('.js-reorderable-list-down') + + this.init() } ReorderableList.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js b/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js index 13faee1536..4f47dc8f66 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js +++ b/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js @@ -12,6 +12,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.personalisationEndpoint = '/api/personalisation/check-email-subscription?base_path=' + this.basePath // This attribute is passed through to the personalisation API to ensure the updated button has the same button_location for analytics if (this.buttonLocation) this.personalisationEndpoint += '&button_location=' + this.buttonLocation + + this.init() } SinglePageNotificationButton.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/skip-link.js b/app/assets/javascripts/govuk_publishing_components/components/skip-link.js index bb2da95709..ea922326a7 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/skip-link.js +++ b/app/assets/javascripts/govuk_publishing_components/components/skip-link.js @@ -1,5 +1,5 @@ // This component relies on JavaScript from GOV.UK Frontend -// = require govuk/components/skip-link/skip-link.js +// = require govuk/components/skip-link/skip-link.bundle.js window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {} window.GOVUK.Modules.GovukSkipLink = window.GOVUKFrontend.SkipLink diff --git a/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js b/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js index f6a3694d31..bb4d6ab229 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +++ b/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js @@ -1,7 +1,3 @@ -//= require govuk/vendor/polyfills/Element/prototype/classList.js -//= require ../vendor/polyfills/closest.js -//= require ../vendor/polyfills/indexOf.js - window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {}; @@ -16,6 +12,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.$module.activeStepClass = 'gem-c-step-nav__step--active' this.$module.activeLinkHref = '#content' this.$module.uniqueId = false + + this.init() } Gemstepnav.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/table.js b/app/assets/javascripts/govuk_publishing_components/components/table.js index b9b262ebcb..a9ede75aae 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/table.js +++ b/app/assets/javascripts/govuk_publishing_components/components/table.js @@ -16,6 +16,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; for (var i = 0; i < this.tableRows.length; i++) { this.tableRowsContent.push(this.tableRows[i].textContent.toUpperCase()) } + + this.init() } Table.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/components/tabs.js b/app/assets/javascripts/govuk_publishing_components/components/tabs.js index 512e0fa063..12030312d2 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/tabs.js +++ b/app/assets/javascripts/govuk_publishing_components/components/tabs.js @@ -1,5 +1,5 @@ // This component relies on JavaScript from GOV.UK Frontend -// = require govuk/components/tabs/tabs.js +// = require govuk/components/tabs/tabs.bundle.js window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {} window.GOVUK.Modules.GovukTabs = window.GOVUKFrontend.Tabs diff --git a/app/assets/javascripts/govuk_publishing_components/lib/cookie-settings.js b/app/assets/javascripts/govuk_publishing_components/lib/cookie-settings.js index 45c01eb8ab..5d841316ec 100644 --- a/app/assets/javascripts/govuk_publishing_components/lib/cookie-settings.js +++ b/app/assets/javascripts/govuk_publishing_components/lib/cookie-settings.js @@ -4,6 +4,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function CookieSettings ($module) { this.$module = $module + + this.init() } CookieSettings.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js b/app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js index 55f4df8bb2..38379e3bf4 100644 --- a/app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js +++ b/app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js @@ -1,4 +1,3 @@ -//= require govuk/vendor/polyfills/Element/prototype/classList.js // This is a non-jQuery version of Magna Charta: https://github.com/alphagov/magna-charta window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {}; diff --git a/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js b/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js index 96ddd21ed8..8657d70788 100644 --- a/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +++ b/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js @@ -6,6 +6,8 @@ var YoutubeLinkEnhancement = function ($element, $classOverride) { this.$element = $element this.$classOverride = typeof $classOverride !== 'undefined' ? $classOverride : 'gem-c-govspeak__youtube-video' + + this.init() } YoutubeLinkEnhancement.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/lib/initial-focus.js b/app/assets/javascripts/govuk_publishing_components/lib/initial-focus.js index cd5af39a02..404d049047 100644 --- a/app/assets/javascripts/govuk_publishing_components/lib/initial-focus.js +++ b/app/assets/javascripts/govuk_publishing_components/lib/initial-focus.js @@ -4,6 +4,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function InitialFocus ($module) { this.$module = $module + + this.init() } InitialFocus.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js b/app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js index 8ed4a6fa12..020f741761 100644 --- a/app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js +++ b/app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js @@ -1,4 +1,3 @@ -//= require govuk/vendor/polyfills/Element/prototype/classList.js /* Toggle the class 'focus' on input boxes on element focus/blur Used by the search component but generic enough for reuse @@ -9,6 +8,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function GemToggleInputClassOnFocus ($module) { this.$module = $module + + this.init() } GemToggleInputClassOnFocus.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/lib/toggle.js b/app/assets/javascripts/govuk_publishing_components/lib/toggle.js index d790e0cdc7..67b6bf5b11 100644 --- a/app/assets/javascripts/govuk_publishing_components/lib/toggle.js +++ b/app/assets/javascripts/govuk_publishing_components/lib/toggle.js @@ -89,6 +89,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function GemToggle ($module) { this.$module = $module + + this.init() } GemToggle.prototype.init = function () { diff --git a/app/assets/javascripts/govuk_publishing_components/modules.js b/app/assets/javascripts/govuk_publishing_components/modules.js index 2a1c44a8c5..8085dbc545 100644 --- a/app/assets/javascripts/govuk_publishing_components/modules.js +++ b/app/assets/javascripts/govuk_publishing_components/modules.js @@ -37,9 +37,10 @@ var started = element.getAttribute('data-' + moduleNames[j] + '-module-started') if (typeof GOVUK.Modules[moduleName] === 'function' && !started) { // Vanilla JavaScript GOV.UK Modules and GOV.UK Frontend Modules - if (GOVUK.Modules[moduleName].prototype.init) { + if (GOVUK.Modules[moduleName]) { try { - new GOVUK.Modules[moduleName](element).init() + /* eslint-disable no-new */ + new GOVUK.Modules[moduleName](element) element.setAttribute('data-' + moduleNames[j] + '-module-started', true) } catch (e) { // if there's a problem with the module, catch the error to allow other modules to start diff --git a/app/assets/stylesheets/component_guide/application.scss b/app/assets/stylesheets/component_guide/application.scss index 82a5d112be..a9fa63b37e 100644 --- a/app/assets/stylesheets/component_guide/application.scss +++ b/app/assets/stylesheets/component_guide/application.scss @@ -1,8 +1,5 @@ // This file contains the styles for the Component Guide. -// feature flag for accessible link styles -$govuk-new-link-styles: true; - @import "govuk_publishing_components/govuk_frontend_support"; @import "govuk_publishing_components/component_support"; @@ -270,7 +267,7 @@ html { // Rouge syntax highlighting // Based on https://github.com/alphagov/tech-docs-template/blob/master/template/source/stylesheets/palette/_syntax-highlighting.scss -$code-00: scale-color(govuk-colour("light-grey", $legacy: "grey-4"), $lightness: 50%); // Default Background +$code-00: scale-color(govuk-colour("light-grey"), $lightness: 50%); // Default Background $code-01: #f5f5f5; // Lighter Background (Unused) $code-02: #bfc1c3; // Selection Background $code-03: darken($govuk-secondary-text-colour, 2%); // Comments, Invisibles, Line Highlighting diff --git a/app/assets/stylesheets/govuk_publishing_components/_all_components.scss b/app/assets/stylesheets/govuk_publishing_components/_all_components.scss index e8d8e11996..5e104ceda7 100644 --- a/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +++ b/app/assets/stylesheets/govuk_publishing_components/_all_components.scss @@ -1,9 +1,6 @@ // This is the file that the application needs to include in order to use // the components. -// feature flag for accessible link styles -$govuk-new-link-styles: true; - @import "govuk_publishing_components/govuk_frontend_support"; @import "govuk_publishing_components/component_support"; diff --git a/app/assets/stylesheets/govuk_publishing_components/_individual_component_support.scss b/app/assets/stylesheets/govuk_publishing_components/_individual_component_support.scss index 2d55fe18a2..c3ce63ad8f 100644 --- a/app/assets/stylesheets/govuk_publishing_components/_individual_component_support.scss +++ b/app/assets/stylesheets/govuk_publishing_components/_individual_component_support.scss @@ -1,5 +1,3 @@ -$govuk-new-link-styles: true; - // This flag stops the font from being included in this components's // stylesheet - the font is being served by Static across all of GOV.UK, so is // not needed here. diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_attachment.scss b/app/assets/stylesheets/govuk_publishing_components/components/_attachment.scss index 976f25e9b5..954b05df8f 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_attachment.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_attachment.scss @@ -7,7 +7,7 @@ $thumbnail-background: govuk-colour("white"); $thumbnail-border-colour: rgba(11, 12, 12, .1); $thumbnail-shadow-colour: rgba(11, 12, 12, .4); $thumbnail-shadow-width: 0 2px 2px; -$thumbnail-icon-border-colour: govuk-colour("mid-grey", $legacy: "grey-3"); +$thumbnail-icon-border-colour: govuk-colour("mid-grey"); .gem-c-attachment { @include govuk-font(19); diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss b/app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss index 7ddc075695..e8eb3e210a 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss @@ -1,12 +1,18 @@ @import "govuk_publishing_components/individual_component_support"; @import "govuk/components/checkboxes/checkboxes"; +.govuk-checkboxes__item { + // Ensure the requied font-size and line-height are always set, see + // https://github.com/alphagov/govuk-frontend/pull/4267 + @include govuk-font($size: 19); +} + .govuk-checkboxes--nested { margin-left: -(govuk-spacing(4) + 2px); // 22px box-sizing: border-box; border-left-style: solid; border-left-width: 4px; - border-color: govuk-colour("mid-grey", $legacy: "grey-2"); + border-color: govuk-colour("mid-grey"); margin-top: govuk-spacing(2); margin-bottom: govuk-spacing(2); padding: govuk-spacing(2) govuk-spacing(4); diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss b/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss index bcb1474ef2..3dcd5be66a 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss @@ -27,7 +27,7 @@ .gem-c-contextual-sidebar__cta { border-top: 2px solid $govuk-brand-colour; margin-bottom: govuk-spacing(6); - background-color: govuk-colour("light-grey", $legacy: "grey-4"); + background-color: govuk-colour("light-grey"); display: block; padding: 0 govuk-spacing(3) govuk-spacing(3); text-decoration: none; diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_document-list.scss b/app/assets/stylesheets/govuk_publishing_components/components/_document-list.scss index 17e4c85991..3760c31f09 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_document-list.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_document-list.scss @@ -53,7 +53,7 @@ } .gem-c-document-list__item-context { - color: govuk-colour("dark-grey", $legacy: "grey-1"); + color: govuk-colour("dark-grey"); } .gem-c-document-list__item-description { @@ -93,7 +93,7 @@ } .gem-c-document-list__item--highlight { - border: 1px solid govuk-colour("mid-grey", $legacy: "grey-2"); + border: 1px solid govuk-colour("mid-grey"); padding: govuk-spacing(6); margin-bottom: govuk-spacing(6); diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_govspeak-html-publication.scss b/app/assets/stylesheets/govuk_publishing_components/components/_govspeak-html-publication.scss index bbaaec649e..ff00386e4a 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_govspeak-html-publication.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_govspeak-html-publication.scss @@ -77,7 +77,7 @@ // and make all of thead and tfoot stand out thead, tfoot { - background-color: govuk-colour("light-grey", $legacy: "grey-3"); + background-color: govuk-colour("light-grey"); } thead th, @@ -122,7 +122,7 @@ // total and subtotal rows tr.subtotal > *, tr.total > * { - border-top: 3px solid govuk-colour("mid-grey", $legacy: "grey-2"); + border-top: 3px solid govuk-colour("mid-grey"); } tr.total > *, @@ -133,7 +133,7 @@ // the total is usually in the tfoot, so already has that background colour // but when it's used inside the tbody, it should also be highlighted tr.total { - background-color: govuk-colour("light-grey", $legacy: "grey-3"); + background-color: govuk-colour("light-grey"); } } // stylelint-enable selector-no-qualifying-type diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss b/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss index de05432e08..e60ef44cb6 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss @@ -187,7 +187,7 @@ font-size: 16px; font-size: govuk-px-to-rem(16px); margin: 0 0 calc(govuk-spacing(3) / 2); - color: govuk-colour("dark-grey", $legacy: "grey-1"); + color: govuk-colour("dark-grey"); @include govuk-media-query($from: tablet) { margin-bottom: 0; @@ -213,7 +213,7 @@ } .gem-c-image-card__list-item--text { - color: govuk-colour("dark-grey", $legacy: "grey-1"); + color: govuk-colour("dark-grey"); } .gem-c-image-card__list-item-link { diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_intervention.scss b/app/assets/stylesheets/govuk_publishing_components/components/_intervention.scss index 331722e13b..826f1606fa 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_intervention.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_intervention.scss @@ -4,7 +4,7 @@ @include govuk-text-colour; @include govuk-responsive-padding(3); @include govuk-responsive-margin(6, "bottom"); - background-color: govuk-colour("light-grey", $legacy: "grey-4"); + background-color: govuk-colour("light-grey"); border-left: 10px solid $govuk-success-colour; .govuk-body:last-of-type { diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss b/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss index 066cfaf0b8..da8f5ce223 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss @@ -5,7 +5,7 @@ @import "govuk/components/tag/tag"; .gem-c-layout-header--production .govuk-header__container { - border-bottom-color: govuk-colour("red", $legacy: "bright-red"); + border-bottom-color: govuk-colour("red"); } .gem-c-layout-header--integration .govuk-header__container, @@ -18,7 +18,7 @@ } .gem-c-layout-header--development .govuk-header__container { - border-bottom-color: govuk-colour("dark-grey", $legacy: "grey-1"); + border-bottom-color: govuk-colour("dark-grey"); } .gem-c-layout-header--no-bottom-border, @@ -103,12 +103,9 @@ } } -.gem-c-header__logotype { - vertical-align: middle; -} - .gem-c-header__product-name { display: none; + margin-top: govuk-spacing(-1); @include govuk-media-query($from: tablet) { display: inline-block; @@ -119,12 +116,14 @@ .gem-c-environment-tag { padding: 2px 5px 0; margin-left: 3px; + margin-top: govuk-spacing(-2); vertical-align: middle; @include govuk-font($size: 16, $weight: "bold"); } .gem-c-environment-tag--production { - background-color: govuk-colour("red", $legacy: "bright-red"); + background-color: govuk-colour("red"); + color: govuk-colour("white"); } .gem-c-environment-tag--example { @@ -132,7 +131,8 @@ } .gem-c-environment-tag--development { - background-color: govuk-colour("dark-grey", $legacy: "grey-1"); + background-color: govuk-colour("dark-grey"); + color: govuk-colour("white"); } .gem-c-environment-tag--staging, diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss b/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss index 5696a4ca21..de155fce71 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss @@ -14,7 +14,7 @@ .gem-c-related-navigation__sub-heading { @include govuk-font(16); - border-top: 1px solid govuk-colour("mid-grey", $legacy: "grey-2"); + border-top: 1px solid govuk-colour("mid-grey"); margin: 0; padding-top: govuk-spacing(3); } diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss b/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss index 71d987f586..49f0c34f45 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss @@ -6,7 +6,7 @@ position: relative; padding: 10px; - background: govuk-colour("light-grey", $legacy: "grey-4"); + background: govuk-colour("light-grey"); border-bottom: solid 1px govuk-colour("blue"); margin-top: govuk-spacing(3); diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss b/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss index 5feaea2179..f3ffefd2d1 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss @@ -3,7 +3,7 @@ $stroke-width: 1px; $number-circle-size: 30px; $number-circle-size-large: 35px; -$top-border: solid 1px govuk-colour("mid-grey", $legacy: "grey-3"); +$top-border: solid 1px govuk-colour("mid-grey"); @mixin step-nav-vertical-line($line-style: solid) { content: ""; @@ -11,7 +11,7 @@ $top-border: solid 1px govuk-colour("mid-grey", $legacy: "grey-3"); z-index: 2; width: 0; height: 100%; - border-left: $line-style $stroke-width govuk-colour("mid-grey", $legacy: "grey-2"); + border-left: $line-style $stroke-width govuk-colour("mid-grey"); background: govuk-colour("white"); } @@ -263,7 +263,7 @@ $top-border: solid 1px govuk-colour("mid-grey", $legacy: "grey-3"); margin-left: calc($number-circle-size / 4); width: calc($number-circle-size / 2); height: 0; - border-bottom: solid $stroke-width govuk-colour("mid-grey", $legacy: "grey-2"); + border-bottom: solid $stroke-width govuk-colour("mid-grey"); } &::after { @@ -322,7 +322,7 @@ $top-border: solid 1px govuk-colour("mid-grey", $legacy: "grey-3"); .gem-c-step-nav__circle--number { @include step-nav-font(16, $weight: bold, $line-height: 29px); - border: solid $stroke-width govuk-colour("mid-grey", $legacy: "grey-2"); + border: solid $stroke-width govuk-colour("mid-grey"); .gem-c-step-nav--large & { @include step-nav-font(16, $tablet-size: 19, $weight: bold, $line-height: 29px, $tablet-line-height: 34px); @@ -532,7 +532,7 @@ $top-border: solid 1px govuk-colour("mid-grey", $legacy: "grey-3"); .gem-c-step-nav__context { display: inline-block; font-weight: normal; - color: govuk-colour("dark-grey", $legacy: "grey-1"); + color: govuk-colour("dark-grey"); &::before { content: " \2013\00a0"; // dash followed by   diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss b/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss index 2d5d5c073a..2285fb4370 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss @@ -96,7 +96,7 @@ .gem-c-subscription-links__feed-box { padding: govuk-spacing(3); margin-bottom: govuk-spacing(3); - background: govuk-colour("light-grey", $legacy: "grey-3"); + background: govuk-colour("light-grey"); .js-enabled &.js-hidden { display: none; diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_table.scss b/app/assets/stylesheets/govuk_publishing_components/components/_table.scss index e1e66102ca..7a3c10bef0 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_table.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_table.scss @@ -2,15 +2,15 @@ @import "govuk/components/table/table"; $table-border-width: 1px; -$table-border-colour: govuk-colour("mid-grey", $legacy: "grey-2"); +$table-border-colour: govuk-colour("mid-grey"); $table-header-border-width: 2px; -$table-header-background-colour: govuk-colour("light-grey", $legacy: "grey-3"); +$table-header-background-colour: govuk-colour("light-grey"); $sort-link-active-colour: govuk-colour("white"); $sort-link-arrow-size: 14px; $sort-link-arrow-size-small: 8px; $sort-link-arrow-spacing: calc($sort-link-arrow-size / 2); $table-row-hover-background-colour: rgba(43, 140, 196, .2); -$table-row-even-background-colour: govuk-colour("light-grey", $legacy: "grey-4"); +$table-row-even-background-colour: govuk-colour("light-grey"); .govuk-table__cell:empty, .govuk-table__cell--empty { diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_warning-text.scss b/app/assets/stylesheets/govuk_publishing_components/components/_warning-text.scss index 6b962a2a51..63283a8d04 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_warning-text.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_warning-text.scss @@ -2,6 +2,10 @@ @import "govuk/components/warning-text/warning-text"; .gem-c-warning-text .govuk-warning-text__text { + // Ensure the font-size is always set to 19px + // This prevents the default user agent styles being applied to heading elements used in the warning-text component following a change in v5.0.0, see: + // https://github.com/alphagov/govuk-frontend/pull/4267 + @include govuk-font($size: 19, $weight: bold); margin: 0; } @@ -10,7 +14,7 @@ margin-left: 0; } -.gem-c-warning-text__text--large { +.gem-c-warning-text .gem-c-warning-text__text--large { @include govuk-font($size: 24, $weight: bold); } diff --git a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_advisory.scss b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_advisory.scss index 4abb817bc7..1dd7c7ec0c 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_advisory.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_advisory.scss @@ -25,7 +25,7 @@ $high-alert-border: #cc0000; } &.high-alert { - background-color: govuk-colour("light-grey", $legacy: "grey-3"); + background-color: govuk-colour("light-grey"); border: 1px solid $high-alert-border; } diff --git a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss index 2836daea52..bcefe0cdc2 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss @@ -49,8 +49,8 @@ } svg { - fill: govuk-colour("mid-grey", $legacy: "grey-3"); - stroke: govuk-colour("mid-grey", $legacy: "grey-3"); + fill: govuk-colour("mid-grey"); + stroke: govuk-colour("mid-grey"); } } diff --git a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_call-to-action.scss b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_call-to-action.scss index 382a31dfa8..af5b29c50e 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_call-to-action.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_call-to-action.scss @@ -10,7 +10,7 @@ .gem-c-govspeak { .call-to-action { margin: 2em 0; - background-color: govuk-colour("light-grey", $legacy: "grey-3"); + background-color: govuk-colour("light-grey"); padding: 2em; &:first-child { diff --git a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss index a96fbba31d..84f5b04237 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss @@ -12,7 +12,7 @@ // .address is used by the `$A` markdown pattern .address, .contact { - border-left: 1px solid govuk-colour("mid-grey", $legacy: "grey-2"); + border-left: 1px solid govuk-colour("mid-grey"); padding-left: govuk-spacing(3); margin-bottom: govuk-spacing(6); margin-top: govuk-spacing(6); diff --git a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_example.scss b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_example.scss index 095535f452..603baa00e1 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_example.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_example.scss @@ -8,7 +8,7 @@ .govspeak, // Legacy class name that's still used in some content items - needs to be kept until `.govspeak` is removed from the content items. .gem-c-govspeak { .example { - border-left: 10px solid govuk-colour("mid-grey", $legacy: "grey-3"); + border-left: 10px solid govuk-colour("mid-grey"); padding: 1em 0 1em 1em; margin: 2em 0; diff --git a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_footnotes.scss b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_footnotes.scss index 8a12d1c17f..b982c84bf6 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_footnotes.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_footnotes.scss @@ -14,7 +14,7 @@ .govspeak, // Legacy class name that's still used in some content items - needs to be kept until `.govspeak` is removed from the content items. .gem-c-govspeak { .footnotes { - border-top: 1px solid govuk-colour("mid-grey", $legacy: "grey-2"); + border-top: 1px solid govuk-colour("mid-grey"); margin-top: govuk-spacing(6); padding-top: govuk-spacing(2); diff --git a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_information-callout.scss b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_information-callout.scss index 82a383dbb6..959a26bd22 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_information-callout.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_information-callout.scss @@ -9,7 +9,7 @@ .govspeak, // Legacy class name that's still used in some content items - needs to be kept until `.govspeak` is removed from the content items. .gem-c-govspeak { .info-notice { - border-left: 10px solid govuk-colour("mid-grey", $legacy: "grey-3"); + border-left: 10px solid govuk-colour("mid-grey"); padding: 1em 0 1em 1em; margin: 2em 0; diff --git a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_place.scss b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_place.scss index c45794c1d5..375927f52d 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_place.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_place.scss @@ -3,7 +3,7 @@ .gem-c-govspeak { .place { margin: 1.5em 0; - border-bottom: solid 1px govuk-colour("mid-grey", $legacy: "grey-2"); + border-bottom: solid 1px govuk-colour("mid-grey"); padding-bottom: 1.5em; .address { diff --git a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_tables.scss b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_tables.scss index 9774affa3d..9c4eccab7e 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_tables.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_tables.scss @@ -25,7 +25,7 @@ td { vertical-align: top; padding: govuk-spacing(2) govuk-spacing(4) govuk-spacing(2) 0; - border-bottom: 1px solid govuk-colour("mid-grey", $legacy: "grey-2"); + border-bottom: 1px solid govuk-colour("mid-grey"); &:last-child { padding: govuk-spacing(2) 0 govuk-spacing(2) 0; diff --git a/app/assets/stylesheets/govuk_publishing_components/govuk_frontend_support.scss b/app/assets/stylesheets/govuk_publishing_components/govuk_frontend_support.scss index 504933a5d4..78c7a492cf 100644 --- a/app/assets/stylesheets/govuk_publishing_components/govuk_frontend_support.scss +++ b/app/assets/stylesheets/govuk_publishing_components/govuk_frontend_support.scss @@ -11,9 +11,9 @@ $gem-secondary-button-colour: #00823b; $gem-secondary-button-hover-colour: darken($gem-secondary-button-colour, 5%); $gem-secondary-button-background-colour: govuk-colour("white"); -$gem-secondary-button-hover-background-colour: govuk-colour("light-grey", $legacy: "grey-4"); +$gem-secondary-button-hover-background-colour: govuk-colour("light-grey"); -$gem-quiet-button-colour: govuk-colour("dark-grey", $legacy: "grey-1"); +$gem-quiet-button-colour: govuk-colour("dark-grey"); $gem-quiet-button-hover-colour: darken($gem-quiet-button-colour, 5%); $gem-hover-dark-background: #dddcdb; diff --git a/app/views/govuk_publishing_components/components/_accordion.html.erb b/app/views/govuk_publishing_components/components/_accordion.html.erb index 152eeeeba6..a928f8e749 100644 --- a/app/views/govuk_publishing_components/components/_accordion.html.erb +++ b/app/views/govuk_publishing_components/components/_accordion.html.erb @@ -93,7 +93,6 @@ item[:content][:html], id: "#{id}-content-#{index}", class: "govuk-accordion__section-content", - 'aria-labelledby': "#{id}-heading-#{index}", data: ga4_link_data_attributes ) %> <% end %> diff --git a/app/views/govuk_publishing_components/components/_details.html.erb b/app/views/govuk_publishing_components/components/_details.html.erb index ed50663b9e..3f4f347604 100644 --- a/app/views/govuk_publishing_components/components/_details.html.erb +++ b/app/views/govuk_publishing_components/components/_details.html.erb @@ -13,8 +13,8 @@ css_classes << shared_helper.get_margin_bottom details_data_attributes = {} - details_data_attributes[:module] = 'govuk-details gem-details' - details_data_attributes[:module] = 'govuk-details gem-details ga4-event-tracker' unless disable_ga4 + details_data_attributes[:module] = 'gem-details' + details_data_attributes[:module] = 'gem-details ga4-event-tracker' unless disable_ga4 data_attributes ||= {} data_attributes[:details_track_click] = '' diff --git a/app/views/govuk_publishing_components/components/_layout_for_public.html.erb b/app/views/govuk_publishing_components/components/_layout_for_public.html.erb index 8e6aa70288..1f4831dee2 100644 --- a/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +++ b/app/views/govuk_publishing_components/components/_layout_for_public.html.erb @@ -79,12 +79,11 @@ <%= stylesheet_link_tag "application", media: "all" %> - - - "> - "> - "> - "> + + + + + "> @@ -186,6 +185,9 @@ meta: layout_helper.footer_meta, } %> <% end %> + <% if GovukPublishingComponents::Config.use_es6_components %> + <%= javascript_include_tag 'es6-components', type: "module" %> + <% end %> <%= javascript_include_tag 'application' %> <% end %> diff --git a/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb b/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb index 4d605d5a98..33a040b5d6 100644 --- a/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +++ b/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb @@ -54,9 +54,6 @@ header_logo_classes = %w(gem-c-layout-super-navigation-header__header-logo) header_logo_classes << "gem-c-layout-super-navigation-header__header-logo--large-navbar" if large_navbar - logotype_classes = %w(govuk-header__logotype-crown gem-c-layout-super-navigation-header__logotype-crown) - logotype_classes << "gem-c-layout-super-navigation-header__logotype-crown--large-navbar" if large_navbar - header_link_classes = %w(govuk-header__link govuk-header__link--homepage) header_link_classes << "gem-c-header__link--large-navbar" if large_navbar @@ -108,41 +105,11 @@ label: logo_link_title, } } do %> - <% if hide_logo_text %> - - <%= logo_text %> - - <% end %> - - - <%= content_tag(:svg, { - aria: { - hidden: true, - }, - class: logotype_classes, - height: "30", - width: "32", - focusable: "false", - viewBox: "0 0 32 30", - xmlns: "http://www.w3.org/2000/svg", - }) do %> - - - <% end %> - - - <% unless hide_logo_text %> - - <%= logo_text %> - - <% end %> - + <%= render "govuk_publishing_components/components/layout_for_public/header_logo", { + hide_logo_text: hide_logo_text, + logo_text: logo_text, + large_navbar: large_navbar + } %> <% end %> <% end %> diff --git a/app/views/govuk_publishing_components/components/_modal_dialogue.html.erb b/app/views/govuk_publishing_components/components/_modal_dialogue.html.erb index ebee848d0a..3932685cb8 100644 --- a/app/views/govuk_publishing_components/components/_modal_dialogue.html.erb +++ b/app/views/govuk_publishing_components/components/_modal_dialogue.html.erb @@ -13,11 +13,9 @@ <%= tag.div class: "gem-c-modal-dialogue__overlay" %> <%= tag.dialog class: dialog_classes, data: data_attributes, aria: { modal: true, label: aria_label }, role: "dialog", tabindex: 0 do %> <%= tag.div class: "gem-c-modal-dialogue__header" do %> - + <%= logo_text %> + + <%= content_tag(:svg, { + aria: { + hidden: true, + }, + class: logotype_classes, + height: "30", + width: "32", + focusable: "false", + viewBox: "0 0 32 30", + xmlns: "http://www.w3.org/2000/svg", + }) do %> + + + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb b/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb index 668aa6397e..8d26df4e79 100644 --- a/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +++ b/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb @@ -1,20 +1,18 @@ ' + - '
' + + '
' + '

This is the content for Writing well for the web.

' + '
' + '
' + @@ -41,14 +41,15 @@ describe('Accordion component', function () { 'Writing well for specialists' + '' + '' + - '
' + + '
' + '

This is the content for Writing well for specialists.

' + '
' + '
' + '' function startAccordion () { - new GOVUK.Modules.GemAccordion(accordion).init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemAccordion(accordion) } beforeEach(function () { diff --git a/spec/javascripts/components/checkboxes-spec.js b/spec/javascripts/components/checkboxes-spec.js index ec2f15557d..343a6d368a 100644 --- a/spec/javascripts/components/checkboxes-spec.js +++ b/spec/javascripts/components/checkboxes-spec.js @@ -3,7 +3,8 @@ describe('Checkboxes component', function () { function loadCheckboxesComponent () { - new GOVUK.Modules.GemCheckboxes($('.gem-c-checkboxes')[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemCheckboxes($('.gem-c-checkboxes')[0]) } var FIXTURE = diff --git a/spec/javascripts/components/contextual-guidance-spec.js b/spec/javascripts/components/contextual-guidance-spec.js index 7fa7882ade..3ca7a8ade1 100644 --- a/spec/javascripts/components/contextual-guidance-spec.js +++ b/spec/javascripts/components/contextual-guidance-spec.js @@ -35,8 +35,10 @@ describe('Contextual guidance component', function () { document.body.appendChild(container) var titleContextualGuidance = document.getElementById('document-title-guidance') var summaryContextualGuidance = document.getElementById('document-summary-guidance') - new GOVUK.Modules.ContextualGuidance(titleContextualGuidance).init() - new GOVUK.Modules.ContextualGuidance(summaryContextualGuidance).init() + /* eslint-disable no-new */ + new GOVUK.Modules.ContextualGuidance(titleContextualGuidance) + /* eslint-disable no-new */ + new GOVUK.Modules.ContextualGuidance(summaryContextualGuidance) }) afterEach(function () { diff --git a/spec/javascripts/components/cookie-banner-spec.js b/spec/javascripts/components/cookie-banner-spec.js index 30d17c525d..b1ba0f93b7 100644 --- a/spec/javascripts/components/cookie-banner-spec.js +++ b/spec/javascripts/components/cookie-banner-spec.js @@ -61,7 +61,8 @@ describe('Cookie banner', function () { it('should show the cookie banner', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var cookieBannerMain = document.querySelector('.js-banner-wrapper') var cookieBannerConfirmationAccept = document.querySelector('.gem-c-cookie-banner__confirmation-message--accepted') @@ -77,7 +78,8 @@ describe('Cookie banner', function () { GOVUK.setDefaultConsentCookie() // Set default cookies, which are set whether there is any interaction or not. var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var cookieBannerMain = document.querySelector('.js-banner-wrapper') var cookieBannerConfirmationAccept = document.querySelector('.gem-c-cookie-banner__confirmation-message--accepted') @@ -93,7 +95,8 @@ describe('Cookie banner', function () { GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 }) var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(element).toBeHidden() }) @@ -102,7 +105,8 @@ describe('Cookie banner', function () { var element = document.querySelector('[data-module="cookie-banner"]') expect(element.hasAttribute('hidden')).toEqual(true) expect(element.offsetParent).toEqual(null) - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(element.hasAttribute('hidden')).toEqual(false) expect(!!element.offsetParent).toEqual(true) }) @@ -112,14 +116,16 @@ describe('Cookie banner', function () { var element = document.querySelector('[data-module="cookie-banner"]') expect(element.offsetParent).toEqual(null) expect(element.hasAttribute('hidden')).toEqual(true) - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(element.offsetParent).toEqual(null) expect(element.hasAttribute('hidden')).toEqual(true) }) it('sets a default consent cookie', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(GOVUK.getCookie('cookies_preferences_set')).toEqual(null) expect(GOVUK.getCookie('cookies_policy')).toEqual(DEFAULT_COOKIE_CONSENT) @@ -130,7 +136,8 @@ describe('Cookie banner', function () { spyOn(GOVUK, 'deleteUnconsentedCookies').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(GOVUK.getCookie('cookies_policy')).toEqual(DEFAULT_COOKIE_CONSENT) expect(GOVUK.deleteUnconsentedCookies).toHaveBeenCalled() @@ -142,7 +149,8 @@ describe('Cookie banner', function () { spyOn(GOVUK, 'setCookie').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) // Manually reset the consent cookie so we can check the accept button works as intended expect(GOVUK.getCookie('cookies_policy')).toEqual(DEFAULT_COOKIE_CONSENT) @@ -167,7 +175,8 @@ describe('Cookie banner', function () { spyOn(GOVUK, 'setCookie').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) // Manually reset the consent cookie so we can check the accept button works as intended expect(GOVUK.getCookie('cookies_policy')).toEqual(DEFAULT_COOKIE_CONSENT) @@ -184,7 +193,8 @@ describe('Cookie banner', function () { it('shows a confirmation message when cookies have been accepted', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var acceptCookiesButton = document.querySelector('[data-accept-cookies]') var confirmationMessageAccepted = document.querySelector('.gem-c-cookie-banner__confirmation-message--accepted') @@ -199,7 +209,8 @@ describe('Cookie banner', function () { it('shows a confirmation message when cookies have been rejected', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var rejectCookiesButton = document.querySelector('[data-reject-cookies]') var confirmationMessageRejected = document.querySelector('.gem-c-cookie-banner__confirmation-message--rejected') @@ -214,7 +225,8 @@ describe('Cookie banner', function () { it('set focus to the confirmation message after clicking button', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var rejectCookiesButton = document.querySelector('[data-reject-cookies]') var confirmationMessage = document.querySelector('.gem-c-cookie-banner__confirmation') @@ -229,7 +241,8 @@ describe('Cookie banner', function () { it('set cookies_preferences_set cookie, and re-set cookies_policy expiration date when rejecting cookies', function () { spyOn(GOVUK, 'setCookie').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var rejectCookiesButton = document.querySelector('[data-reject-cookies]') @@ -243,7 +256,8 @@ describe('Cookie banner', function () { spyOn(GOVUK, 'setCookie').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var link = document.querySelector('button[data-hide-cookie-banner="true"]') link.dispatchEvent(new window.Event('click')) @@ -266,7 +280,8 @@ describe('Cookie banner', function () { it('should hide the cookie banner', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(element).toBeHidden() }) }) @@ -310,7 +325,8 @@ describe('Cookie banner', function () { it('initialises the single consent api on init', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(window.GOVUK.singleConsent.init).toHaveBeenCalled() expect(window.GOVUK.singleConsent.apiCallback).toHaveBeenCalled() expect(window.GOVUK.setCookie).not.toHaveBeenCalled() @@ -318,7 +334,8 @@ describe('Cookie banner', function () { it('should show the cookie banner', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(element).toBeVisible() }) @@ -338,7 +355,8 @@ describe('Cookie banner', function () { it('should hide the cookie banner and set cookies for consent', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'text/plain', @@ -352,7 +370,8 @@ describe('Cookie banner', function () { it('should hide the cookie banner and set cookies for reject', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'text/plain', @@ -366,7 +385,8 @@ describe('Cookie banner', function () { it('should hide the cookie banner and set cookies for a varied cookie consent', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'text/plain', diff --git a/spec/javascripts/components/cross-service-header-spec.js b/spec/javascripts/components/cross-service-header-spec.js index 15ba07e0c3..a1f50fe33f 100644 --- a/spec/javascripts/components/cross-service-header-spec.js +++ b/spec/javascripts/components/cross-service-header-spec.js @@ -5,7 +5,6 @@ describe('The _layout_header_one_login', function () { 'use strict' var container - var thisModule beforeEach(function () { container = document.createElement('div') @@ -134,7 +133,8 @@ describe('The _layout_header_one_login', function () { document.body.appendChild(container) var $element = document.querySelector('[data-module="cross-service-header"]') - thisModule = new GOVUK.Modules.CrossServiceHeader($element) + /* eslint-disable no-new */ + new GOVUK.Modules.CrossServiceHeader($element) spyOn(GOVUK.analytics, 'trackEvent') }) @@ -151,7 +151,6 @@ describe('The _layout_header_one_login', function () { var $button beforeEach(function () { - thisModule.init() $button = document.querySelector('.gem-c-cross-service-header__button--one-login.js-x-header-toggle') }) @@ -227,7 +226,6 @@ describe('The _layout_header_one_login', function () { var $button beforeEach(function () { - thisModule.init() $button = document.querySelector('.gem-c-cross-service-header__button--service-header.js-x-header-toggle') }) diff --git a/spec/javascripts/components/details-spec.js b/spec/javascripts/components/details-spec.js index 561d4dba82..e8e7621fde 100644 --- a/spec/javascripts/components/details-spec.js +++ b/spec/javascripts/components/details-spec.js @@ -6,7 +6,8 @@ describe('Details component', function () { function loadDetailsComponent () { var element = document.querySelector('[data-module="gem-details"]') - new GOVUK.Modules.GemDetails(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemDetails(element) } beforeEach(function () { diff --git a/spec/javascripts/components/govspeak-spec.js b/spec/javascripts/components/govspeak-spec.js index cb33a36cd1..e8a2e25358 100644 --- a/spec/javascripts/components/govspeak-spec.js +++ b/spec/javascripts/components/govspeak-spec.js @@ -26,6 +26,7 @@ describe('Govspeak', function () { document.body.appendChild(container) var element = document.querySelector('[data-module="govspeak"]') + /* eslint-disable no-new */ new GOVUK.Modules.Govspeak(element).init() expect(document.querySelectorAll('.gem-c-govspeak__youtube-video').length).toBe(1) @@ -40,6 +41,7 @@ describe('Govspeak', function () { document.body.appendChild(container) var element = document.querySelector('[data-module="govspeak"]') + /* eslint-disable no-new */ new GOVUK.Modules.Govspeak(element).init() expect(document.querySelectorAll('.gem-c-govspeak__youtube-video').length).toBe(0) @@ -62,6 +64,7 @@ describe('Govspeak', function () { document.body.appendChild(container) var element = document.querySelector('[data-module="govspeak"]') + /* eslint-disable no-new */ new GOVUK.Modules.Govspeak(element).init() expect(document.querySelectorAll('.mc-chart').length).toBe(1) diff --git a/spec/javascripts/components/intervention-spec.js b/spec/javascripts/components/intervention-spec.js index 2b59a525ff..a455733ac5 100644 --- a/spec/javascripts/components/intervention-spec.js +++ b/spec/javascripts/components/intervention-spec.js @@ -61,6 +61,7 @@ describe('Intervention banner component', function () { it('does not display the banner', function () { GOVUK.setCookie('intervention_campaign', 'test-intervention-name', { days: 1 }) var element = document.querySelector('[data-module="intervention"]') + /* eslint-disable no-new */ new GOVUK.Modules.Intervention(element).init() var banner = document.querySelector('.gem-c-intervention') diff --git a/spec/javascripts/components/layout-super-navigation-header-spec.js b/spec/javascripts/components/layout-super-navigation-header-spec.js index 9741daa3b3..108e90d559 100644 --- a/spec/javascripts/components/layout-super-navigation-header-spec.js +++ b/spec/javascripts/components/layout-super-navigation-header-spec.js @@ -5,7 +5,6 @@ describe('The super header navigation', function () { 'use strict' var container - var thisModule beforeEach(function () { container = document.createElement('div') @@ -176,10 +175,6 @@ describe('The super header navigation', function () { '' document.body.appendChild(container) - - var $element = document.querySelector('[data-module="super-navigation-mega-menu"]') - thisModule = new GOVUK.Modules.SuperNavigationMegaMenu($element) - spyOn(GOVUK.analytics, 'trackEvent') }) @@ -193,7 +188,9 @@ describe('The super header navigation', function () { describe('on both small and large screens', function () { beforeEach(function () { - thisModule.init() + var $element = document.querySelector('[data-module="super-navigation-mega-menu"]') + /* eslint-disable no-new */ + new GOVUK.Modules.SuperNavigationMegaMenu($element) }) it('has the initialised class once the JavaScript has run', function () { @@ -207,7 +204,9 @@ describe('The super header navigation', function () { var $button beforeEach(function () { - thisModule.init() + var $element = document.querySelector('[data-module="super-navigation-mega-menu"]') + /* eslint-disable no-new */ + new GOVUK.Modules.SuperNavigationMegaMenu($element) $button = document.querySelector('#super-navigation-menu-toggle') }) @@ -333,7 +332,9 @@ describe('The super header navigation', function () { var $lastSearchMenuTabbable beforeEach(function () { - thisModule.init() + var $element = document.querySelector('[data-module="super-navigation-mega-menu"]') + /* eslint-disable no-new */ + new GOVUK.Modules.SuperNavigationMegaMenu($element) $navMenuButton = document.querySelector('#super-navigation-menu-toggle') $searchMenuButton = document.querySelector('#super-search-menu-toggle') $navMenu = document.querySelector('#super-navigation-menu') @@ -400,7 +401,9 @@ describe('The super header navigation', function () { var $searchMenuButton beforeEach(function () { - thisModule.init() + var $element = document.querySelector('[data-module="super-navigation-mega-menu"]') + /* eslint-disable no-new */ + new GOVUK.Modules.SuperNavigationMegaMenu($element) $navMenu = document.querySelector('#super-navigation-menu') $navMenuButton = document.querySelector('#super-navigation-menu-toggle') $searchMenu = document.querySelector('#super-search-menu') @@ -437,7 +440,9 @@ describe('The super header navigation', function () { var $button beforeEach(function () { - thisModule.init() + var $element = document.querySelector('[data-module="super-navigation-mega-menu"]') + /* eslint-disable no-new */ + new GOVUK.Modules.SuperNavigationMegaMenu($element) $button = document.querySelector('#super-search-menu-toggle') }) diff --git a/spec/javascripts/components/metadata-spec.js b/spec/javascripts/components/metadata-spec.js index 1921bedd9f..e23054a7d8 100644 --- a/spec/javascripts/components/metadata-spec.js +++ b/spec/javascripts/components/metadata-spec.js @@ -60,7 +60,7 @@ describe('The metadata component', function () { function init (element, target) { new GOVUK.Modules.Metadata(element).init() - var toggle = new GOVUK.Modules.GemToggle($(target)[0]) - target && toggle.init() + /* eslint-disable no-new */ + target && new GOVUK.Modules.GemToggle($(target)[0]) } }) diff --git a/spec/javascripts/components/option-select-spec.js b/spec/javascripts/components/option-select-spec.js index 4422e919e9..0dd2d8a2e8 100644 --- a/spec/javascripts/components/option-select-spec.js +++ b/spec/javascripts/components/option-select-spec.js @@ -104,7 +104,8 @@ describe('An option select component', function () { var $closedOnLoadFixture = $(optionSelectWithAttrs('data-closed-on-load=true')) $('body').append($closedOnLoadFixture) - new GOVUK.Modules.OptionSelect($closedOnLoadFixture[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($closedOnLoadFixture[0]) expect($closedOnLoadFixture.find('button').attr('aria-expanded')).toBe('false') }) @@ -113,7 +114,8 @@ describe('An option select component', function () { var $openOnLoadFixture = $(optionSelectWithAttrs('data-closed-on-load=false')) $('body').append($openOnLoadFixture) - new GOVUK.Modules.OptionSelect($openOnLoadFixture[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($openOnLoadFixture[0]) expect($openOnLoadFixture.find('button').attr('aria-expanded')).toBe('true') expect($('body').find('.js-options-container').is(':visible')).toBe(true) @@ -123,7 +125,8 @@ describe('An option select component', function () { var $openOnLoadFixture = $(optionSelectWithAttrs('')) $('body').append($openOnLoadFixture) - new GOVUK.Modules.OptionSelect($openOnLoadFixture[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($openOnLoadFixture[0]) expect($openOnLoadFixture.find('button').attr('aria-expanded')).toBe('true') expect($('body').find('.js-options-container').is(':visible')).toBe(true) @@ -132,7 +135,8 @@ describe('An option select component', function () { it('sets the height of the options container as part of initialisation', function () { $element = document.createElement('div') $element.innerHTML = html - new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')) expect($($element).find('.js-options-container').attr('style')).toContain('height') }) @@ -140,7 +144,8 @@ describe('An option select component', function () { it('doesn\'t set the height of the options container as part of initialisation if closed-on-load is true', function () { var $closedOnLoadFixture = $(optionSelectWithAttrs('data-closed-on-load=true')) - new GOVUK.Modules.OptionSelect($closedOnLoadFixture[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($closedOnLoadFixture[0]) expect($closedOnLoadFixture.find('.js-options-container').attr('style')).not.toContain('height') }) @@ -148,7 +153,8 @@ describe('An option select component', function () { it('replaces the `span.gem-c-option-select__title` with a button', function () { $element = document.createElement('div') $element.innerHTML = html - new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')) expect($($element).find('button')).toBeDefined() }) @@ -187,7 +193,6 @@ describe('An option select component', function () { $('body').append($element) optionSelect = new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')) - optionSelect.init() }) it('calls optionSelect.close() if the optionSelect is currently open', function () { @@ -211,7 +216,8 @@ describe('An option select component', function () { $element.innerHTML = html $('body').append($element) - new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')) }) it('closes and opens the option select', function () { @@ -241,7 +247,6 @@ describe('An option select component', function () { $('body').append($element) optionSelect = new GOVUK.Modules.OptionSelect($element.find('.gem-c-option-select')[0]) - optionSelect.init() optionSelect.setContainerHeight(100) firstCheckbox = optionSelect.$allCheckboxes[0] lastCheckbox = optionSelect.$allCheckboxes[optionSelect.$allCheckboxes.length - 1] @@ -263,7 +268,6 @@ describe('An option select component', function () { $element = $(html) $('body').append($element) optionSelect = new GOVUK.Modules.OptionSelect($element.find('.gem-c-option-select')[0]) - optionSelect.init() }) it('returns all the checkboxes if the container doesn\'t overflow', function () { @@ -303,7 +307,6 @@ describe('An option select component', function () { }) $checkboxListInner = $checkboxList.find(' > .js-auto-height-inner') - optionSelect.init() }) it('expands the checkbox-container to fit checkbox list if the list is < 50px larger than the container', function () { @@ -334,7 +337,6 @@ describe('An option select component', function () { $wrapper.hide() optionSelect = new GOVUK.Modules.OptionSelect($wrapper.find('.gem-c-option-select')[0]) - optionSelect.init() }) afterEach(function () { @@ -354,7 +356,6 @@ describe('An option select component', function () { var $wrapper = $('
').addClass('wrapper').hide().html($element) $('body').append($wrapper) optionSelect = new GOVUK.Modules.OptionSelect($element.find('.gem-c-option-select')[0]) - optionSelect.init() }) afterEach(function () { @@ -388,7 +389,6 @@ describe('An option select component', function () { $element.find('.gem-c-checkboxes').prepend($(filterSpan)) $('body').append($element) optionSelect = new GOVUK.Modules.OptionSelect($element.find('.gem-c-option-select')[0]) - optionSelect.init() jasmine.clock().install() $filterInput = document.querySelector('[name="option-select-filter"]') diff --git a/spec/javascripts/components/step-by-step-nav-spec.js b/spec/javascripts/components/step-by-step-nav-spec.js index a8deff8461..d803bb838f 100644 --- a/spec/javascripts/components/step-by-step-nav-spec.js +++ b/spec/javascripts/components/step-by-step-nav-spec.js @@ -120,7 +120,8 @@ describe('A stepnav module', function () { beforeEach(function () { $element = $(html) - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) expectedstepnavStepCount = $element.find('.gem-c-step-nav__step').length expectedstepnavContentCount = $element.find('.gem-c-step-nav__step').first().find('.js-link').length expectedstepnavLinkCount = $element.find('.gem-c-step-nav__list-item').length @@ -382,7 +383,8 @@ describe('A stepnav module', function () { $element = $(html) $element.attr('data-remember', true) $element.addClass('gem-c-step-nav--large') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -430,7 +432,8 @@ describe('A stepnav module', function () { $element.attr('data-remember', true) $element.addClass('gem-c-step-nav--large') window.sessionStorage.setItem('unique-id', '["topic-step-one","topic-step-three"]') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -469,7 +472,8 @@ describe('A stepnav module', function () { $element.attr('data-remember', true) $element.addClass('gem-c-step-nav--large') window.sessionStorage.setItem('unique-id', '["topic-step-one","topic-step-two","topic-step-three"]') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -487,7 +491,8 @@ describe('A stepnav module', function () { $element = $(html) $element.attr('data-remember', true) window.sessionStorage.setItem('unique-id', '["topic-step-one","topic-step-two","topic-step-three"]') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -512,7 +517,8 @@ describe('A stepnav module', function () { beforeEach(function () { $element = $(html) $element.find('#topic-step-two').attr('data-show', '') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) it('shows the step it\'s supposed to', function () { @@ -533,7 +539,8 @@ describe('A stepnav module', function () { beforeEach(function () { $element = $(html) $element.addClass('gem-c-step-nav--large') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) it('triggers a google analytics custom event when clicking on the title on a big stepnav', function () { @@ -683,7 +690,8 @@ describe('A stepnav module', function () { beforeEach(function () { $element = $(html) $element.find('.js-will-be-an-active-link').addClass('gem-c-step-nav__list-item--active') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -742,7 +750,8 @@ describe('A stepnav module', function () { $element = $(html) $element.find('.js-will-be-an-active-link').addClass('gem-c-step-nav__list-item--active') window.sessionStorage.setItem('govuk-step-nav-active-link_unique-id', '3.5') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -765,7 +774,8 @@ describe('A stepnav module', function () { $element = $(html) $element.find('.js-will-be-an-active-link').addClass('gem-c-step-nav__list-item--active') window.sessionStorage.setItem('govuk-step-nav-active-link_unique-id', 'definitelynotvalid') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -784,7 +794,8 @@ describe('A stepnav module', function () { $element = $(html) $element.find('.js-will-be-an-active-link').addClass('gem-c-step-nav__list-item--active') $element.find('.gem-c-step-nav__step').removeClass('gem-c-step-nav__step--active') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -802,7 +813,8 @@ describe('A stepnav module', function () { beforeEach(function () { $element = $(html) $element.removeAttr('data-id') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) it('triggers a google analytics custom event on show all', function () { @@ -929,7 +941,8 @@ describe('A stepnav module', function () { element.childNodes[0].setAttribute('data-module', 'gemstepnav ga4-event-tracker') element.childNodes[0].setAttribute('data-ga4-expandable', '') element.querySelector('.js-step-title').innerText = "This title's got quotation marks \" in it." - new GOVUK.Modules.Gemstepnav(element.childNodes[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav(element.childNodes[0]) }) it('adds the "Show all" JSON to the JS generated "show all steps" button', function () { diff --git a/spec/javascripts/components/toggle-input-class-on-focus-spec.js b/spec/javascripts/components/toggle-input-class-on-focus-spec.js index ffbb723c23..de51d15668 100644 --- a/spec/javascripts/components/toggle-input-class-on-focus-spec.js +++ b/spec/javascripts/components/toggle-input-class-on-focus-spec.js @@ -4,7 +4,7 @@ describe('A toggle class module', function () { 'use strict' - var element, toggle + var element afterEach(function () { element.remove() @@ -17,8 +17,8 @@ describe('A toggle class module', function () { '' + '
') $('body').append(element) - toggle = new GOVUK.Modules.GemToggleInputClassOnFocus(element[0]) - toggle.init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemToggleInputClassOnFocus(element[0]) }) it('applies the focus style on focus and removes it on blur', function () { @@ -38,8 +38,8 @@ describe('A toggle class module', function () { '' + '') $('body').append(element) - toggle = new GOVUK.Modules.GemToggleInputClassOnFocus(element[0]) - toggle.init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemToggleInputClassOnFocus(element[0]) }) it('applies the focus style on load if the search box already has a value', function () { diff --git a/spec/javascripts/components/toggle-spec.js b/spec/javascripts/components/toggle-spec.js index 652c5010ba..6a775fcebf 100644 --- a/spec/javascripts/components/toggle-spec.js +++ b/spec/javascripts/components/toggle-spec.js @@ -20,8 +20,8 @@ describe('A toggle module', function () { '
Target
' + '' element = $(html) - var toggle = new GOVUK.Modules.GemToggle(element[0]) - toggle.init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemToggle(element[0]) }) it('adds aria attributes to toggles', function () { @@ -42,8 +42,8 @@ describe('A toggle module', function () { '
Target
' + '' element = $(html) - var toggle = new GOVUK.Modules.GemToggle(element[0]) - toggle.init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemToggle(element[0]) element.find('.my-toggle')[0].click() }) @@ -83,8 +83,8 @@ describe('A toggle module', function () { '
Target
' + '' element = $(html) - var toggle = new GOVUK.Modules.GemToggle(element[0]) - toggle.init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemToggle(element[0]) element.find('.my-toggle')[0].click() }) @@ -131,8 +131,8 @@ describe('A toggle module', function () { '
Another target
' + '' element = $(html) - var toggle = new GOVUK.Modules.GemToggle(element[0]) - toggle.init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemToggle(element[0]) expect(element.find('#target').is('.js-hidden')).toBe(true) expect(element.find('#another-target').is('.js-hidden')).toBe(true) @@ -155,8 +155,8 @@ describe('A toggle module', function () { '
Target
' + '' element = $(html) - var toggle = new GOVUK.Modules.GemToggle(element[0]) - toggle.init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemToggle(element[0]) expect(element.find('#target').is('.myclass')).toBe(false) element.find('.my-toggle')[0].click() diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.spec.js index 10c2a529f5..785379ca5e 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.spec.js @@ -38,18 +38,17 @@ describe('Google Analytics auto tracker', function () { describe('when the user has a cookie consent choice', function () { it('starts the module if consent has already been given', function () { agreeToCookies() + spyOn(GOVUK.Modules.Ga4AutoTracker.prototype, 'startModule').and.callThrough() var tracker = new GOVUK.Modules.Ga4AutoTracker(element) - spyOn(tracker, 'startModule').and.callThrough() - tracker.init() expect(tracker.startModule).toHaveBeenCalled() }) it('starts the module on the same page as cookie consent is given', function () { denyCookies() + spyOn(GOVUK.Modules.Ga4AutoTracker.prototype, 'sendEvent').and.callThrough() var tracker = new GOVUK.Modules.Ga4AutoTracker(element) - spyOn(tracker, 'sendEvent').and.callThrough() - tracker.init() + expect(tracker.sendEvent).not.toHaveBeenCalled() // page has not been reloaded, user consents to cookies @@ -64,9 +63,8 @@ describe('Google Analytics auto tracker', function () { it('does not do anything if consent is not given', function () { denyCookies() + spyOn(GOVUK.Modules.Ga4AutoTracker.prototype, 'sendEvent') var tracker = new GOVUK.Modules.Ga4AutoTracker(element) - spyOn(tracker, 'sendEvent') - tracker.init() expect(tracker.sendEvent).not.toHaveBeenCalled() }) @@ -75,7 +73,8 @@ describe('Google Analytics auto tracker', function () { describe('configuring tracking without any data', function () { beforeEach(function () { element.setAttribute('data-ga4-auto', '') - new GOVUK.Modules.Ga4AutoTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4AutoTracker(element) }) it('does not cause an error or fire an event', function () { @@ -86,7 +85,8 @@ describe('Google Analytics auto tracker', function () { describe('configuring tracking with incorrect data', function () { beforeEach(function () { element.setAttribute('data-ga4-auto', 'invalid json') - new GOVUK.Modules.Ga4AutoTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4AutoTracker(element) }) it('does not cause an error', function () { @@ -117,7 +117,8 @@ describe('Google Analytics auto tracker', function () { index_section_count: undefined } element.setAttribute('data-ga4-auto', JSON.stringify(attributes)) - new GOVUK.Modules.Ga4AutoTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4AutoTracker(element) }) it('pushes ga4 attributes to the dataLayer', function () { @@ -145,7 +146,7 @@ describe('Google Analytics auto tracker', function () { text: '/2022-02-02/SW10AA/email@example.com' } element.setAttribute('data-ga4-auto', JSON.stringify(attributes)) - new GOVUK.Modules.Ga4AutoTracker(element).init() + new GOVUK.Modules.Ga4AutoTracker(element) }) it('redacts dates, postcodes and emails from text', function () { diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.spec.js index be22b30884..184d2be570 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.spec.js @@ -33,12 +33,14 @@ describe('Google Analytics event tracker', function () { }) describe('when the user has a cookie consent choice', function () { + beforeEach(function () { + spyOn(GOVUK.Modules.Ga4EventTracker.prototype, 'trackClick') + }) + it('starts the module if consent has already been given', function () { agreeToCookies() document.body.appendChild(element) var tracker = new GOVUK.Modules.Ga4EventTracker(element) - spyOn(tracker, 'trackClick') - tracker.init() element.click() expect(tracker.trackClick).toHaveBeenCalled() @@ -48,8 +50,6 @@ describe('Google Analytics event tracker', function () { denyCookies() document.body.appendChild(element) var tracker = new GOVUK.Modules.Ga4EventTracker(element) - spyOn(tracker, 'trackClick') - tracker.init() element.click() expect(tracker.trackClick).not.toHaveBeenCalled() @@ -70,8 +70,6 @@ describe('Google Analytics event tracker', function () { denyCookies() document.body.appendChild(element) var tracker = new GOVUK.Modules.Ga4EventTracker(element) - spyOn(tracker, 'trackClick') - tracker.init() element.click() expect(tracker.trackClick).not.toHaveBeenCalled() @@ -82,7 +80,8 @@ describe('Google Analytics event tracker', function () { beforeEach(function () { element.setAttribute('data-ga4-event', '') document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('does not cause an error or fire an event', function () { @@ -95,7 +94,8 @@ describe('Google Analytics event tracker', function () { beforeEach(function () { element.setAttribute('data-ga4-event', 'invalid json') document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('does not cause an error', function () { @@ -121,7 +121,8 @@ describe('Google Analytics event tracker', function () { } element.setAttribute('data-ga4-event', JSON.stringify(attributes)) document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('pushes ga4 attributes to the dataLayer', function () { @@ -154,7 +155,8 @@ describe('Google Analytics event tracker', function () { it('records the text of the element by default', function () { element.setAttribute('data-ga4-event', JSON.stringify(attributes)) document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) expected.event_data.text = 'text from the button' element.click() @@ -165,7 +167,8 @@ describe('Google Analytics event tracker', function () { attributes.text = 'text from the attributes' element.setAttribute('data-ga4-event', JSON.stringify(attributes)) document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) expected.event_data.text = 'text from the attributes' element.click() @@ -207,7 +210,8 @@ describe('Google Analytics event tracker', function () { 'class="clickme"' + '>' document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('pushes ga4 attributes to the dataLayer', function () { @@ -229,7 +233,8 @@ describe('Google Analytics event tracker', function () { element.setAttribute('data-ga4-event', JSON.stringify(attributes)) element.setAttribute('aria-expanded', 'false') document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('includes the expanded state in the ga4 attributes', function () { @@ -268,7 +273,8 @@ describe('Google Analytics event tracker', function () { '>' + '' document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('includes the open state in the ga4 attributes', function () { @@ -309,7 +315,8 @@ describe('Google Analytics event tracker', function () { '' + '' document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('includes the expanded state in the ga4 attributes', function () { @@ -354,7 +361,8 @@ describe('Google Analytics event tracker', function () { 'Example' + '' document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('includes the open state in the ga4 attributes', function () { @@ -399,7 +407,8 @@ describe('Google Analytics event tracker', function () { '' + '' document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('should not track the aria-expanded state', function () { @@ -422,7 +431,8 @@ describe('Google Analytics event tracker', function () { '' + '' document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('should not track the open/closed state', function () { @@ -448,7 +458,8 @@ describe('Google Analytics event tracker', function () { '' + '' document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) spyOn(GOVUK.analyticsGa4.core.trackFunctions, 'getPathname').and.returnValue('/hello-world') }) @@ -495,7 +506,8 @@ describe('Google Analytics event tracker', function () { element.appendChild(noButton) document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) window.dataLayer = [] expected = new GOVUK.analyticsGa4.Schemas().eventSchema() @@ -533,7 +545,8 @@ describe('Google Analytics event tracker', function () { '' + '' document.body.appendChild(element) - new GOVUK.Modules.Ga4EventTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4EventTracker(element) }) it('tracks expanding/collapsing sections under the data-ga4-expandable attribute', function () { diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.spec.js index 9f9cf61bbf..32756ae379 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.spec.js @@ -7,7 +7,8 @@ describe('GA4 link tracker', function () { var attributes function initModule (element, click) { - new GOVUK.Modules.Ga4LinkTracker(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4LinkTracker(element) if (click) { GOVUK.triggerEvent(element, 'click') } @@ -56,7 +57,6 @@ describe('GA4 link tracker', function () { document.body.appendChild(element) var tracker = new GOVUK.Modules.Ga4LinkTracker(element) spyOn(tracker, 'trackClick') - tracker.init() element.click() expect(tracker.trackClick).toHaveBeenCalled() @@ -67,7 +67,6 @@ describe('GA4 link tracker', function () { document.body.appendChild(element) var tracker = new GOVUK.Modules.Ga4LinkTracker(element) spyOn(tracker, 'trackClick') - tracker.init() element.click() expect(tracker.trackClick).not.toHaveBeenCalled() @@ -89,7 +88,6 @@ describe('GA4 link tracker', function () { document.body.appendChild(element) var tracker = new GOVUK.Modules.Ga4LinkTracker(element) spyOn(tracker, 'trackClick') - tracker.init() element.click() expect(tracker.trackClick).not.toHaveBeenCalled() @@ -469,9 +467,8 @@ describe('GA4 link tracker', function () { element.setAttribute('data-ga4-set-indexes', '') - var tracker = new GOVUK.Modules.Ga4LinkTracker(element) spyOn(GOVUK.analyticsGa4.core.trackFunctions, 'setIndexes') - tracker.init() + new GOVUK.Modules.Ga4LinkTracker(element) expect(GOVUK.analyticsGa4.core.trackFunctions.setIndexes).toHaveBeenCalled() }) @@ -485,9 +482,8 @@ describe('GA4 link tracker', function () { 'Link 2' + 'Link 3' - var tracker = new GOVUK.Modules.Ga4LinkTracker(element) spyOn(GOVUK.analyticsGa4.core.trackFunctions, 'setIndexes') - tracker.init() + new GOVUK.Modules.Ga4LinkTracker(element) expect(GOVUK.analyticsGa4.core.trackFunctions.setIndexes).not.toHaveBeenCalled() }) diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.spec.js index 917c6f3d6e..2b551c438a 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.spec.js @@ -110,18 +110,21 @@ describe('GA4 smart answer results tracking', function () { describe('on page load', function () { it('should push a nullified ecommerce object to the dataLayer', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() expect(window.dataLayer[0].search_results.ecommerce).toBe(null) }) it('should get the number of results i.e. 5 results in this test case', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() expect(window.dataLayer[1].search_results.results).toBe(onPageLoadExpected.search_results.results) }) it('should get the item id for each result', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() var smartAnswerResultItems = window.dataLayer[1].search_results.ecommerce.items @@ -131,6 +134,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should get the item list name for each result', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() var smartAnswerResultItems = window.dataLayer[1].search_results.ecommerce.items @@ -145,6 +149,7 @@ describe('GA4 smart answer results tracking', function () { } smartAnswerResultsParentEl.removeAttribute('data-ga4-list-title') + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() var smartAnswerResultItems = window.dataLayer[1].search_results.ecommerce.items @@ -154,6 +159,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should get the index for each result using the data-ga4-ecommerce-index attribute', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() var smartAnswerResultItems = window.dataLayer[1].search_results.ecommerce.items @@ -169,6 +175,7 @@ describe('GA4 smart answer results tracking', function () { smartAnswerResults[i].removeAttribute('data-ga4-ecommerce-index') } + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() var smartAnswerResultItems = window.dataLayer[1].search_results.ecommerce.items @@ -210,6 +217,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should push a nullified ecommerce object to the dataLayer', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() expect(window.dataLayer[0].search_results.ecommerce).toBe(null) @@ -226,6 +234,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should push 1 search result to the dataLayer (i.e. the clicked search result)', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() smartAnswerResultToBeClicked.click() @@ -233,6 +242,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should add the event_data property to the object and set it appropriately', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() smartAnswerResultToBeClicked.click() @@ -241,6 +251,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should set the remaining properties appropriately', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() smartAnswerResultToBeClicked.click() diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.spec.js index 9e8865885c..bf4c1d7943 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.spec.js @@ -763,8 +763,8 @@ describe('A specialist link tracker', function () { GOVUK.setCookie('cookies_policy', '{"essential":true,"settings":true,"usage":true,"campaigns":true}') - var otherLinkTracker = new GOVUK.Modules.Ga4LinkTracker(links) - otherLinkTracker.init() + /* eslint-disable no-new */ + new GOVUK.Modules.Ga4LinkTracker(links) specialistLinkTracker = GOVUK.analyticsGa4.analyticsModules.Ga4SpecialistLinkTracker specialistLinkTracker.init() diff --git a/spec/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker-spec.js b/spec/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker-spec.js index 54f37052c2..97da612845 100644 --- a/spec/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker-spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker-spec.js @@ -33,18 +33,15 @@ describe('GOVUK.AutoScrollTracker', function () { } it('should only initialise once on a page', function () { + spyOn(GOVUK.Modules.AutoScrollTracker.prototype, 'getWindowDetails') + var el = document.createElement('div') scrollTracker = new GOVUK.Modules.AutoScrollTracker(el) - spyOn(scrollTracker, 'getWindowDetails') - scrollTracker.init() var el2 = document.createElement('div') scrollTracker2 = new GOVUK.Modules.AutoScrollTracker(el2) - spyOn(scrollTracker2, 'getWindowDetails') - scrollTracker2.init() - expect(scrollTracker.getWindowDetails).toHaveBeenCalled() - expect(scrollTracker2.getWindowDetails).not.toHaveBeenCalled() + expect(GOVUK.Modules.AutoScrollTracker.prototype.getWindowDetails).toHaveBeenCalledTimes(1) }) describe('with invalid configuration', function () { @@ -56,8 +53,6 @@ describe('GOVUK.AutoScrollTracker', function () { }) it('does not start scroll tracking', function () { - scrollTracker.init() - expect(window.GOVUK.analyticsVars.scrollTrackerStarted).toEqual(false) }) }) @@ -81,8 +76,6 @@ describe('GOVUK.AutoScrollTracker', function () { }) it('only tracks those headings', function () { - scrollTracker.init() - expect(scrollTracker.trackedNodes.length).toEqual(2) expect(scrollTracker.trackedNodes[0].eventData.label).toEqual('First heading') expect(scrollTracker.trackedNodes[1].eventData.label).toEqual('Third heading') @@ -110,7 +103,6 @@ describe('GOVUK.AutoScrollTracker', function () { el.innerHTML = FIXTURE document.body.appendChild(el) scrollTracker = new GOVUK.Modules.AutoScrollTracker(el) - scrollTracker.init() }) afterEach(function () { @@ -187,7 +179,6 @@ describe('GOVUK.AutoScrollTracker', function () { el = document.createElement('div') document.body.appendChild(el) scrollTracker = new GOVUK.Modules.AutoScrollTracker(el) - scrollTracker.init() }) afterEach(function () { @@ -264,14 +255,14 @@ describe('GOVUK.AutoScrollTracker', function () { it('does not track headings on initial page load', function () { window.location.hash = 'testId' scrollTracker = new GOVUK.Modules.AutoScrollTracker(el) - scrollTracker.init() + expect(GOVUK.analytics.trackEvent.calls.count()).toBe(0) }) it('does track headings on initial page load if there is a hash but it does not match an ID on the page', function () { window.location.hash = 'notAThing' scrollTracker = new GOVUK.Modules.AutoScrollTracker(el) - scrollTracker.init() + expect(GOVUK.analytics.trackEvent.calls.count()).toBe(1) expect(GOVUK.analytics.trackEvent.calls.argsFor(0)).toEqual(['ScrollTo', 'Heading', { label: 'Heading 1', nonInteraction: true }]) }) diff --git a/spec/javascripts/govuk_publishing_components/analytics/auto-track-event.spec.js b/spec/javascripts/govuk_publishing_components/analytics/auto-track-event.spec.js index cfba89c4d3..02b41dfb12 100644 --- a/spec/javascripts/govuk_publishing_components/analytics/auto-track-event.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics/auto-track-event.spec.js @@ -5,8 +5,7 @@ var $ = window.jQuery describe('An auto event tracker', function () { 'use strict' var GOVUK = window.GOVUK - var tracker, - element + var element beforeEach(function () { spyOn(GOVUK.analytics, 'trackEvent') @@ -27,8 +26,9 @@ describe('An auto event tracker', function () { '' ) - tracker = new GOVUK.Modules.AutoTrackEvent(element[0]) - tracker.init() + /* eslint-disable no-new */ + new GOVUK.Modules.AutoTrackEvent(element[0]) + expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( 'category', 'action', { nonInteraction: 1 }) }) @@ -44,8 +44,9 @@ describe('An auto event tracker', function () { '' ) - tracker = new GOVUK.Modules.AutoTrackEvent(element[0]) - tracker.init() + /* eslint-disable no-new */ + new GOVUK.Modules.AutoTrackEvent(element[0]) + expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( 'category', 'action', { label: 'label', value: 10, nonInteraction: 1 }) }) diff --git a/spec/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.spec.js b/spec/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.spec.js index 5c578ddbde..e85ffe6177 100644 --- a/spec/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.spec.js @@ -2,7 +2,6 @@ describe('Cross Domain Tracking', function () { 'use strict' - var module var GOVUK = window.GOVUK beforeEach(function () { @@ -20,8 +19,8 @@ describe('Cross Domain Tracking', function () { anchorToTest.setAttribute('data-tracking-name', 'transactionTracker') anchorToTest.textContent = 'Start Now' - module = new GOVUK.Modules.CrossDomainTracking($(anchorToTest)[0]) - module.init() + /* eslint-disable no-new */ + new GOVUK.Modules.CrossDomainTracking($(anchorToTest)[0]) expect( GOVUK.analytics.addLinkedTrackerDomain @@ -38,8 +37,8 @@ describe('Cross Domain Tracking', function () { var wrapperDiv = document.createElement('div') wrapperDiv.appendChild(anchorToTest) - module = new GOVUK.Modules.CrossDomainTracking($(wrapperDiv)[0]) - module.init() + /* eslint-disable no-new */ + new GOVUK.Modules.CrossDomainTracking($(wrapperDiv)[0]) expect( GOVUK.analytics.addLinkedTrackerDomain @@ -73,8 +72,8 @@ describe('Cross Domain Tracking', function () { wrapperDiv.appendChild(anchorToTest) wrapperDiv.appendChild(secondAnchorToTest) - module = new GOVUK.Modules.CrossDomainTracking($(wrapperDiv)[0]) - module.init() + /* eslint-disable no-new */ + new GOVUK.Modules.CrossDomainTracking($(wrapperDiv)[0]) expect( GOVUK.analytics.addLinkedTrackerDomain @@ -92,8 +91,8 @@ describe('Cross Domain Tracking', function () { var wrapperDiv = document.createElement('div') wrapperDiv.appendChild(anchorToTest) - module = new GOVUK.Modules.CrossDomainTracking($(wrapperDiv)[0]) - module.init() + /* eslint-disable no-new */ + new GOVUK.Modules.CrossDomainTracking($(wrapperDiv)[0]) expect(GOVUK.analytics.addLinkedTrackerDomain).not.toHaveBeenCalled() }) @@ -112,8 +111,8 @@ describe('Cross Domain Tracking', function () { var wrapperDiv = document.createElement('div') wrapperDiv.appendChild(anchorToTest) - module = new GOVUK.Modules.CrossDomainTracking($(wrapperDiv)[0]) - module.init() + /* eslint-disable no-new */ + new GOVUK.Modules.CrossDomainTracking($(wrapperDiv)[0]) expect( GOVUK.analytics.addLinkedTrackerDomain @@ -149,11 +148,11 @@ describe('Cross Domain Tracking', function () { wrapperDiv.appendChild(anchor1) wrapperDiv.appendChild(anchor2) - module = new GOVUK.Modules.CrossDomainTracking($(wrapperDiv)[0]) - module.init() + /* eslint-disable no-new */ + new GOVUK.Modules.CrossDomainTracking($(wrapperDiv)[0]) - var moduleDup = new GOVUK.Modules.CrossDomainTracking($(anchor2)[0]) - moduleDup.init() + /* eslint-disable no-new */ + new GOVUK.Modules.CrossDomainTracking($(anchor2)[0]) expect(GOVUK.analytics.addLinkedTrackerDomain.calls.count()).toBe(1) diff --git a/spec/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.spec.js b/spec/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.spec.js index 66c9a1c23d..a6dec387b8 100644 --- a/spec/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.spec.js @@ -4,7 +4,6 @@ describe('Explicit cross-domain linker', function () { 'use strict' - var explicitCrossDomainLinks var element var linker var trackers @@ -29,7 +28,8 @@ describe('Explicit cross-domain linker', function () { } element = $('') - explicitCrossDomainLinks = new GOVUK.Modules.ExplicitCrossDomainLinks(element[0]) + /* eslint-disable no-new */ + new GOVUK.Modules.ExplicitCrossDomainLinks(element[0]) spyOn(window.gaplugins, 'Linker').and.returnValue(linker) spyOn(linker, 'decorate').and.callFake(function (url) { @@ -46,7 +46,6 @@ describe('Explicit cross-domain linker', function () { describe('when a cross-domain link is clicked', function () { it('modifies the link href to append cookie_consent parameter "not-engaged" if cookies_preferences_set cookie is "false"', function () { GOVUK.cookie('cookies_preferences_set', 'false') - explicitCrossDomainLinks.init() expect(element.attr('href')).toEqual('#') window.GOVUK.triggerEvent(element[0], 'click') expect(element.attr('href')).toEqual('#?cookie_consent=not-engaged') @@ -55,7 +54,6 @@ describe('Explicit cross-domain linker', function () { it('modifies the link href to append cookie_consent parameter "not-engaged" if cookies_preferences_set cookie is not set', function () { GOVUK.cookie('cookies_preferences_set', null) - explicitCrossDomainLinks.init() expect(element.attr('href')).toEqual('#') window.GOVUK.triggerEvent(element[0], 'click') expect(element.attr('href')).toEqual('#?cookie_consent=not-engaged') @@ -65,7 +63,6 @@ describe('Explicit cross-domain linker', function () { it('modifies the link href to append cookie_consent parameter "reject" if usage cookies have been rejected', function () { GOVUK.cookie('cookies_preferences_set', 'true') GOVUK.setConsentCookie({ usage: false }) - explicitCrossDomainLinks.init() expect(element.attr('href')).toEqual('#') window.GOVUK.triggerEvent(element[0], 'click') expect(element.attr('href')).toEqual('#?cookie_consent=reject') @@ -78,7 +75,6 @@ describe('Explicit cross-domain linker', function () { GOVUK.setConsentCookie({ usage: true }) trackers = [{ ga_mock: 'foobar' }] - explicitCrossDomainLinks.init() expect(element.attr('href')).toEqual('#') window.GOVUK.triggerEvent(element[0], 'click') @@ -91,7 +87,6 @@ describe('Explicit cross-domain linker', function () { GOVUK.setConsentCookie({ usage: true }) trackers = [] - explicitCrossDomainLinks.init() expect(element.attr('href')).toEqual('#') window.GOVUK.triggerEvent(element[0], 'click') expect(element.attr('href')).toEqual('#?cookie_consent=accept') @@ -102,7 +97,6 @@ describe('Explicit cross-domain linker', function () { GOVUK.cookie('cookies_preferences_set', 'true') GOVUK.setConsentCookie({ usage: true }) window.ga = undefined - explicitCrossDomainLinks.init() expect(element.attr('href')).toEqual('#') window.GOVUK.triggerEvent(element[0], 'click') expect(element.attr('href')).toEqual('#?cookie_consent=accept') @@ -117,12 +111,13 @@ describe('Explicit cross-domain linker', function () { '' + '' + '') - explicitCrossDomainLinks = new GOVUK.Modules.ExplicitCrossDomainLinks(element[0]) + + /* eslint-disable no-new */ + new GOVUK.Modules.ExplicitCrossDomainLinks(element[0]) }) it('modifies the form action to append cookie_consent parameter "not-engaged" if cookies_preferences_set cookie is "false"', function () { GOVUK.cookie('cookies_preferences_set', 'false') - explicitCrossDomainLinks.init() expect(element.attr('action')).toEqual('/somewhere') window.GOVUK.triggerEvent(element[0], 'submit') @@ -131,7 +126,6 @@ describe('Explicit cross-domain linker', function () { it('modifies the form action to append cookie_consent parameter "not-engaged" if cookies_preferences_set cookie is not set', function () { GOVUK.cookie('cookies_preferences_set', null) - explicitCrossDomainLinks.init() expect(element.attr('action')).toEqual('/somewhere') window.GOVUK.triggerEvent(element[0], 'submit') expect(element.attr('action')).toEqual('/somewhere?cookie_consent=not-engaged') @@ -140,7 +134,6 @@ describe('Explicit cross-domain linker', function () { it('modifies the form action to append cookie_consent parameter "reject" if usage cookies have been rejected', function () { GOVUK.cookie('cookies_preferences_set', 'true') GOVUK.setConsentCookie({ usage: false }) - explicitCrossDomainLinks.init() expect(element.attr('action')).toEqual('/somewhere') window.GOVUK.triggerEvent(element[0], 'submit') expect(element.attr('action')).toEqual('/somewhere?cookie_consent=reject') @@ -151,7 +144,6 @@ describe('Explicit cross-domain linker', function () { GOVUK.cookie('cookies_preferences_set', 'true') GOVUK.setConsentCookie({ usage: true }) trackers = [{ ga_mock: 'foobar' }] - explicitCrossDomainLinks.init() expect(element.attr('action')).toEqual('/somewhere') window.GOVUK.triggerEvent(element[0], 'submit') expect(element.attr('action')).toEqual('/somewhere?cookie_consent=accept&_ga=abc123') @@ -161,7 +153,6 @@ describe('Explicit cross-domain linker', function () { GOVUK.cookie('cookies_preferences_set', 'true') GOVUK.setConsentCookie({ usage: true }) trackers = [] - explicitCrossDomainLinks.init() expect(element.attr('action')).toEqual('/somewhere') window.GOVUK.triggerEvent(element[0], 'submit') expect(element.attr('action')).toEqual('/somewhere?cookie_consent=accept') @@ -171,7 +162,6 @@ describe('Explicit cross-domain linker', function () { GOVUK.cookie('cookies_preferences_set', 'true') GOVUK.setConsentCookie({ usage: true }) window.ga = undefined - explicitCrossDomainLinks.init() expect(element.attr('action')).toEqual('/somewhere') window.GOVUK.triggerEvent(element[0], 'submit') expect(element.attr('action')).toEqual('/somewhere?cookie_consent=accept') diff --git a/spec/javascripts/govuk_publishing_components/analytics/track-click.spec.js b/spec/javascripts/govuk_publishing_components/analytics/track-click.spec.js index 6b9a0dc269..a8fb1a1b25 100644 --- a/spec/javascripts/govuk_publishing_components/analytics/track-click.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics/track-click.spec.js @@ -5,7 +5,8 @@ describe('A click tracker', function () { var element function initModule (element, click) { - new GOVUK.Modules.GemTrackClick(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemTrackClick(element) if (click) { GOVUK.triggerEvent(element, 'click') } diff --git a/spec/javascripts/govuk_publishing_components/modules.spec.js b/spec/javascripts/govuk_publishing_components/modules.spec.js index 2c93ad918b..fb4dc70713 100644 --- a/spec/javascripts/govuk_publishing_components/modules.spec.js +++ b/spec/javascripts/govuk_publishing_components/modules.spec.js @@ -83,6 +83,7 @@ describe('GOVUK Modules', function () { // GOV.UK Frontend Modules function TestAlertFrontendModule (element) { this.element = element + this.init() } TestAlertFrontendModule.prototype.init = function () { callbackFrontendModule(this.element) @@ -92,6 +93,7 @@ describe('GOVUK Modules', function () { // GOV.UK Gem Frontend Modules function GemTestAlertFrontendModule (element) { this.element = element + this.init() } GemTestAlertFrontendModule.prototype.init = function () { callbackGemFrontendModule(this.element) @@ -101,6 +103,7 @@ describe('GOVUK Modules', function () { // GOV.UK Frontend Module with a GOVUK Publishing Module counterpart function TestAlertPublishingAndFrontendModule (element) { this.element = element + this.init() } TestAlertPublishingAndFrontendModule.prototype.init = function () { callbackFrontendModule(this.element) @@ -110,6 +113,7 @@ describe('GOVUK Modules', function () { // GOV.UK Frontend Module that depends on cookies to start and delays function TestCookieDependencyModule (element) { this.element = element + this.init() } TestCookieDependencyModule.prototype.init = function () { this.startModule = this.startModule.bind(this) @@ -124,6 +128,7 @@ describe('GOVUK Modules', function () { // module with a deliberate error in it function TestErrorModule (element) { this.element = element + this.init() } TestErrorModule.prototype.init = function () { throw new Error('This is a deliberate error') diff --git a/yarn.lock b/yarn.lock index b43119f571..2062517709 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1346,10 +1346,10 @@ globjoin@^0.1.4: resolved "https://registry.yarnpkg.com/globjoin/-/globjoin-0.1.4.tgz#2f4494ac8919e3767c5cbb691e9f463324285d43" integrity sha1-L0SUrIkZ43Z8XLtpHp9GMyQoXUM= -govuk-frontend@^4.8.0: - version "4.8.0" - resolved "https://registry.yarnpkg.com/govuk-frontend/-/govuk-frontend-4.8.0.tgz#df4e56c762e93aae74fed214bb6be08e13783772" - integrity sha512-NOmPJxL8IYq1HSNHYKx9XY2LLTxuwb+IFASiGQO4sgJ8K7AG66SlSeqARrcetevV8zOf+i1z+MbJJ2O7//OxAw== +govuk-frontend@5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/govuk-frontend/-/govuk-frontend-5.1.0.tgz#55e520940b587ddd023e96251efaa076acc9bd5f" + integrity sha512-Dc3J+uOI4i2VR3BVyfxbf6qVjTT4n4bBqbD0/Io6feP8pt/4IfKdP1vWimZf+BwMKKMXacw10hmdy5UcD6Cr8w== govuk-single-consent@^3.0.9: version "3.0.9"