diff --git a/CHANGELOG.md b/CHANGELOG.md index 9456df51fe..862717349e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ useful summary for people upgrading their application, not a replication of the commit log. +## Unreleased + +* **BREAKING:** Upgrade to govuk frontend 5.1 ([PR #4041](https://github.com/alphagov/govuk_publishing_components/pull/4041)) + ## 39.2.5 * LUX version 4.0.23 ([PR #4102](https://github.com/alphagov/govuk_publishing_components/pull/4102)) diff --git a/app/assets/config/govuk_publishing_components_manifest.js b/app/assets/config/govuk_publishing_components_manifest.js index 2fe27c8045..59491a681e 100644 --- a/app/assets/config/govuk_publishing_components_manifest.js +++ b/app/assets/config/govuk_publishing_components_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/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-ecommerce-tracker.js b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js index 7404004b18..5ba85ee0f2 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,4 @@ -//= require govuk/vendor/polyfills/Element/prototype/closest.js +//= require ../vendor/polyfills-govuk-frontend-v4/Element/prototype/closest.js ;(function (global) { 'use strict' 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..1a85584921 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,4 @@ -// = require govuk/vendor/polyfills/Element/prototype/closest.js +// = require ../vendor/polyfills-govuk-frontend-v4/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/external-link-tracker.js b/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js index 50d4f5fdec..4a0fa61c32 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,4 @@ -// = require govuk/vendor/polyfills/Element/prototype/closest.js +// = require ../vendor/polyfills-govuk-frontend-v4/Element/prototype/closest.js ;(function (global) { 'use strict' diff --git a/app/assets/javascripts/govuk_publishing_components/components/accordion.js b/app/assets/javascripts/govuk_publishing_components/components/accordion.js index 07884d121c..aa33b5d563 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/accordion.js +++ b/app/assets/javascripts/govuk_publishing_components/components/accordion.js @@ -1,7 +1,5 @@ -/* 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; @@ -85,11 +83,11 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion; GemAccordion.prototype.addEventListenersForAnchors = function () { var links = this.$module.querySelectorAll(this.sectionInnerContentClass + ' a[href*="#"]') - nodeListForEach(links, function (link) { + for (var link of links) { if (link.pathname === window.location.pathname) { link.addEventListener('click', this.openForAnchor.bind(this, link.hash.split('#')[1])) } - }.bind(this)) + } } // Find the parent accordion section for the given id and open it @@ -153,9 +151,9 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion; GemAccordion.prototype.addEventListenerSections = function () { var sections = this.$module.querySelectorAll(this.sectionButton) - nodeListForEach(sections, function (section) { + for (var section of sections) { section.addEventListener('click', this.addAccordionSectionTracking.bind(this, section)) - }.bind(this)) + } } // If the Accordion's sections are opened on click, then pass them to the GA event tracking 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..10437c6e4f 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; diff --git a/app/assets/javascripts/govuk_publishing_components/components/details.js b/app/assets/javascripts/govuk_publishing_components/components/details.js index 36665e5758..3b3144681e 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) { 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/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..a315a630c4 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,4 +1,4 @@ -//= require govuk/vendor/polyfills/Element/prototype/classList.js +//= require ../vendor/polyfills-govuk-frontend-v4/Element/prototype/classList.js window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {}; 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 747105e331..793019a280 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/option-select.js +++ b/app/assets/javascripts/govuk_publishing_components/components/option-select.js @@ -140,7 +140,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; } for (i = 0; i < showCheckboxes.length; i++) { - obj.$allCheckboxes[showCheckboxes[i]].style.display = 'block' + obj.$allCheckboxes[showCheckboxes[i]].style.display = 'flex' } var lenChecked = obj.$optionsContainer.querySelectorAll('.govuk-checkboxes__input:checked').length 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/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..f4129dd63d 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,4 +1,4 @@ -//= require govuk/vendor/polyfills/Element/prototype/classList.js +//= require ../vendor/polyfills-govuk-frontend-v4/Element/prototype/classList.js //= require ../vendor/polyfills/closest.js //= require ../vendor/polyfills/indexOf.js 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/govspeak/magna-charta.js b/app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js index c144c30939..474a7f5063 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,4 @@ -//= require govuk/vendor/polyfills/Element/prototype/classList.js +//= require ../../vendor/polyfills-govuk-frontend-v4/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/toggle-input-class-on-focus.js b/app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js index 8ed4a6fa12..e69e3ae0a4 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,4 @@ -//= require govuk/vendor/polyfills/Element/prototype/classList.js +//= require ../vendor/polyfills-govuk-frontend-v4/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 diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/DOMTokenList.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/DOMTokenList.js new file mode 100644 index 0000000000..c6bbe54fe0 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/DOMTokenList.js @@ -0,0 +1,273 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js + var detect = ( + 'DOMTokenList' in this && (function (x) { + return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true; + })(document.createElement('x')) + ); + + if (detect) return + + // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js + (function (global) { + var nativeImpl = "DOMTokenList" in global && global.DOMTokenList; + + if ( + !nativeImpl || + ( + !!document.createElementNS && + !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') && + !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList) + ) + ) { + global.DOMTokenList = (function() { // eslint-disable-line no-unused-vars + var dpSupport = true; + var defineGetter = function (object, name, fn, configurable) { + if (Object.defineProperty) + Object.defineProperty(object, name, { + configurable: false === dpSupport ? true : !!configurable, + get: fn + }); + + else object.__defineGetter__(name, fn); + }; + + /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */ + try { + defineGetter({}, "support"); + } + catch (e) { + dpSupport = false; + } + + + var _DOMTokenList = function (el, prop) { + var that = this; + var tokens = []; + var tokenMap = {}; + var length = 0; + var maxLength = 0; + var addIndexGetter = function (i) { + defineGetter(that, i, function () { + preop(); + return tokens[i]; + }, false); + + }; + var reindex = function () { + + /** Define getter functions for array-like access to the tokenList's contents. */ + if (length >= maxLength) + for (; maxLength < length; ++maxLength) { + addIndexGetter(maxLength); + } + }; + + /** Helper function called at the start of each class method. Internal use only. */ + var preop = function () { + var error; + var i; + var args = arguments; + var rSpace = /\s+/; + + /** Validate the token/s passed to an instance method, if any. */ + if (args.length) + for (i = 0; i < args.length; ++i) + if (rSpace.test(args[i])) { + error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character'); + error.code = 5; + error.name = "InvalidCharacterError"; + throw error; + } + + + /** Split the new value apart by whitespace*/ + if (typeof el[prop] === "object") { + tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace); + } else { + tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace); + } + + /** Avoid treating blank strings as single-item token lists */ + if ("" === tokens[0]) tokens = []; + + /** Repopulate the internal token lists */ + tokenMap = {}; + for (i = 0; i < tokens.length; ++i) + tokenMap[tokens[i]] = true; + length = tokens.length; + reindex(); + }; + + /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */ + preop(); + + /** Return the number of tokens in the underlying string. Read-only. */ + defineGetter(that, "length", function () { + preop(); + return length; + }); + + /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */ + that.toLocaleString = + that.toString = function () { + preop(); + return tokens.join(" "); + }; + + that.item = function (idx) { + preop(); + return tokens[idx]; + }; + + that.contains = function (token) { + preop(); + return !!tokenMap[token]; + }; + + that.add = function () { + preop.apply(that, args = arguments); + + for (var args, token, i = 0, l = args.length; i < l; ++i) { + token = args[i]; + if (!tokenMap[token]) { + tokens.push(token); + tokenMap[token] = true; + } + } + + /** Update the targeted attribute of the attached element if the token list's changed. */ + if (length !== tokens.length) { + length = tokens.length >>> 0; + if (typeof el[prop] === "object") { + el[prop].baseVal = tokens.join(" "); + } else { + el[prop] = tokens.join(" "); + } + reindex(); + } + }; + + that.remove = function () { + preop.apply(that, args = arguments); + + /** Build a hash of token names to compare against when recollecting our token list. */ + for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) { + ignore[args[i]] = true; + delete tokenMap[args[i]]; + } + + /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */ + for (i = 0; i < tokens.length; ++i) + if (!ignore[tokens[i]]) t.push(tokens[i]); + + tokens = t; + length = t.length >>> 0; + + /** Update the targeted attribute of the attached element. */ + if (typeof el[prop] === "object") { + el[prop].baseVal = tokens.join(" "); + } else { + el[prop] = tokens.join(" "); + } + reindex(); + }; + + that.toggle = function (token, force) { + preop.apply(that, [token]); + + /** Token state's being forced. */ + if (undefined !== force) { + if (force) { + that.add(token); + return true; + } else { + that.remove(token); + return false; + } + } + + /** Token already exists in tokenList. Remove it, and return FALSE. */ + if (tokenMap[token]) { + that.remove(token); + return false; + } + + /** Otherwise, add the token and return TRUE. */ + that.add(token); + return true; + }; + + return that; + }; + + return _DOMTokenList; + }()); + } + + // Add second argument to native DOMTokenList.toggle() if necessary + (function () { + var e = document.createElement('span'); + if (!('classList' in e)) return; + e.classList.toggle('x', false); + if (!e.classList.contains('x')) return; + e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) { + var force = arguments[1]; + if (force === undefined) { + var add = !this.contains(token); + this[add ? 'add' : 'remove'](token); + return add; + } + force = !!force; + this[force ? 'add' : 'remove'](token); + return force; + }; + }()); + + // Add multiple arguments to native DOMTokenList.add() if necessary + (function () { + var e = document.createElement('span'); + if (!('classList' in e)) return; + e.classList.add('a', 'b'); + if (e.classList.contains('b')) return; + var native = e.classList.constructor.prototype.add; + e.classList.constructor.prototype.add = function () { + var args = arguments; + var l = arguments.length; + for (var i = 0; i < l; i++) { + native.call(this, args[i]); + } + }; + }()); + + // Add multiple arguments to native DOMTokenList.remove() if necessary + (function () { + var e = document.createElement('span'); + if (!('classList' in e)) return; + e.classList.add('a'); + e.classList.add('b'); + e.classList.remove('a', 'b'); + if (!e.classList.contains('b')) return; + var native = e.classList.constructor.prototype.remove; + e.classList.constructor.prototype.remove = function () { + var args = arguments; + var l = arguments.length; + for (var i = 0; i < l; i++) { + native.call(this, args[i]); + } + }; + }()); + + }(this)); + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Date/now.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Date/now.js new file mode 100644 index 0000000000..c1875c9a38 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Date/now.js @@ -0,0 +1,21 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-library/blob/v3.111.0/polyfills/Date/now/detect.js + var detect = ('Date' in self && 'now' in self.Date && 'getTime' in self.Date.prototype); + + if (detect) return + + Date.now = function () { + return new Date().getTime(); + }; + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Document.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Document.js new file mode 100644 index 0000000000..7ef87ecc4e --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Document.js @@ -0,0 +1,34 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js + var detect = ("Document" in this); + + if (detect) return + + if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) { + + if (this.HTMLDocument) { // IE8 + + // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter. + this.Document = this.HTMLDocument; + + } else { + + // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made. + this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')()); + this.Document.prototype = document; + } + } + + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element.js new file mode 100644 index 0000000000..cfb1b4225d --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element.js @@ -0,0 +1,148 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js + var detect = ("Document" in this); + + if (detect) return + + if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) { + + if (this.HTMLDocument) { // IE8 + + // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter. + this.Document = this.HTMLDocument; + + } else { + + // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made. + this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')()); + this.Document.prototype = document; + } + } + + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js + var detect = ('Element' in this && 'HTMLElement' in this); + + if (detect) return + + (function () { + + // IE8 + if (window.Element && !window.HTMLElement) { + window.HTMLElement = window.Element; + return; + } + + // create Element constructor + window.Element = window.HTMLElement = new Function('return function Element() {}')(); + + // generate sandboxed iframe + var vbody = document.appendChild(document.createElement('body')); + var frame = vbody.appendChild(document.createElement('iframe')); + + // use sandboxed iframe to replicate Element functionality + var frameDocument = frame.contentWindow.document; + var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*')); + var cache = {}; + + // polyfill Element.prototype on an element + var shiv = function (element, deep) { + var + childNodes = element.childNodes || [], + index = -1, + key, value, childNode; + + if (element.nodeType === 1 && element.constructor !== Element) { + element.constructor = Element; + + for (key in cache) { + value = cache[key]; + element[key] = value; + } + } + + while (childNode = deep && childNodes[++index]) { + shiv(childNode, deep); + } + + return element; + }; + + var elements = document.getElementsByTagName('*'); + var nativeCreateElement = document.createElement; + var interval; + var loopLimit = 100; + + prototype.attachEvent('onpropertychange', function (event) { + var + propertyName = event.propertyName, + nonValue = !cache.hasOwnProperty(propertyName), + newValue = prototype[propertyName], + oldValue = cache[propertyName], + index = -1, + element; + + while (element = elements[++index]) { + if (element.nodeType === 1) { + if (nonValue || element[propertyName] === oldValue) { + element[propertyName] = newValue; + } + } + } + + cache[propertyName] = newValue; + }); + + prototype.constructor = Element; + + if (!prototype.hasAttribute) { + // .hasAttribute + prototype.hasAttribute = function hasAttribute(name) { + return this.getAttribute(name) !== null; + }; + } + + // Apply Element prototype to the pre-existing DOM as soon as the body element appears. + function bodyCheck() { + if (!(loopLimit--)) clearTimeout(interval); + if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) { + shiv(document, true); + if (interval && document.body.prototype) clearTimeout(interval); + return (!!document.body.prototype); + } + return false; + } + if (!bodyCheck()) { + document.onreadystatechange = bodyCheck; + interval = setInterval(bodyCheck, 25); + } + + // Apply to any new elements created after load + document.createElement = function createElement(nodeName) { + var element = nativeCreateElement(String(nodeName).toLowerCase()); + return shiv(element); + }; + + // remove sandboxed iframe + document.removeChild(vbody); + }()); + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/classList.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/classList.js new file mode 100644 index 0000000000..29168b8844 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/classList.js @@ -0,0 +1,592 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js + var detect = ( + // In IE8, defineProperty could only act on DOM elements, so full support + // for the feature requires the ability to set a property on an arbitrary object + 'defineProperty' in Object && (function() { + try { + var a = {}; + Object.defineProperty(a, 'test', {value:42}); + return true; + } catch(e) { + return false + } + }()) + ); + + if (detect) return + + (function (nativeDefineProperty) { + + var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); + var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; + var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + // Where native support exists, assume it + if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { + return nativeDefineProperty(object, property, descriptor); + } + + if (object === null || !(object instanceof Object || typeof object === 'object')) { + throw new TypeError('Object.defineProperty called on non-object'); + } + + if (!(descriptor instanceof Object)) { + throw new TypeError('Property description must be an object'); + } + + var propertyString = String(property); + var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; + var getterType = 'get' in descriptor && typeof descriptor.get; + var setterType = 'set' in descriptor && typeof descriptor.set; + + // handle descriptor.get + if (getterType) { + if (getterType !== 'function') { + throw new TypeError('Getter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineGetter__.call(object, propertyString, descriptor.get); + } else { + object[propertyString] = descriptor.value; + } + + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineSetter__.call(object, propertyString, descriptor.set); + } + + // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above + if ('value' in descriptor) { + object[propertyString] = descriptor.value; + } + + return object; + }; + }(Object.defineProperty)); + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + (function (undefined) { + + // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js + var detect = ( + 'DOMTokenList' in this && (function (x) { + return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true; + })(document.createElement('x')) + ); + + if (detect) return + + // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js + (function (global) { + var nativeImpl = "DOMTokenList" in global && global.DOMTokenList; + + if ( + !nativeImpl || + ( + !!document.createElementNS && + !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') && + !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList) + ) + ) { + global.DOMTokenList = (function() { // eslint-disable-line no-unused-vars + var dpSupport = true; + var defineGetter = function (object, name, fn, configurable) { + if (Object.defineProperty) + Object.defineProperty(object, name, { + configurable: false === dpSupport ? true : !!configurable, + get: fn + }); + + else object.__defineGetter__(name, fn); + }; + + /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */ + try { + defineGetter({}, "support"); + } + catch (e) { + dpSupport = false; + } + + + var _DOMTokenList = function (el, prop) { + var that = this; + var tokens = []; + var tokenMap = {}; + var length = 0; + var maxLength = 0; + var addIndexGetter = function (i) { + defineGetter(that, i, function () { + preop(); + return tokens[i]; + }, false); + + }; + var reindex = function () { + + /** Define getter functions for array-like access to the tokenList's contents. */ + if (length >= maxLength) + for (; maxLength < length; ++maxLength) { + addIndexGetter(maxLength); + } + }; + + /** Helper function called at the start of each class method. Internal use only. */ + var preop = function () { + var error; + var i; + var args = arguments; + var rSpace = /\s+/; + + /** Validate the token/s passed to an instance method, if any. */ + if (args.length) + for (i = 0; i < args.length; ++i) + if (rSpace.test(args[i])) { + error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character'); + error.code = 5; + error.name = "InvalidCharacterError"; + throw error; + } + + + /** Split the new value apart by whitespace*/ + if (typeof el[prop] === "object") { + tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace); + } else { + tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace); + } + + /** Avoid treating blank strings as single-item token lists */ + if ("" === tokens[0]) tokens = []; + + /** Repopulate the internal token lists */ + tokenMap = {}; + for (i = 0; i < tokens.length; ++i) + tokenMap[tokens[i]] = true; + length = tokens.length; + reindex(); + }; + + /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */ + preop(); + + /** Return the number of tokens in the underlying string. Read-only. */ + defineGetter(that, "length", function () { + preop(); + return length; + }); + + /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */ + that.toLocaleString = + that.toString = function () { + preop(); + return tokens.join(" "); + }; + + that.item = function (idx) { + preop(); + return tokens[idx]; + }; + + that.contains = function (token) { + preop(); + return !!tokenMap[token]; + }; + + that.add = function () { + preop.apply(that, args = arguments); + + for (var args, token, i = 0, l = args.length; i < l; ++i) { + token = args[i]; + if (!tokenMap[token]) { + tokens.push(token); + tokenMap[token] = true; + } + } + + /** Update the targeted attribute of the attached element if the token list's changed. */ + if (length !== tokens.length) { + length = tokens.length >>> 0; + if (typeof el[prop] === "object") { + el[prop].baseVal = tokens.join(" "); + } else { + el[prop] = tokens.join(" "); + } + reindex(); + } + }; + + that.remove = function () { + preop.apply(that, args = arguments); + + /** Build a hash of token names to compare against when recollecting our token list. */ + for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) { + ignore[args[i]] = true; + delete tokenMap[args[i]]; + } + + /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */ + for (i = 0; i < tokens.length; ++i) + if (!ignore[tokens[i]]) t.push(tokens[i]); + + tokens = t; + length = t.length >>> 0; + + /** Update the targeted attribute of the attached element. */ + if (typeof el[prop] === "object") { + el[prop].baseVal = tokens.join(" "); + } else { + el[prop] = tokens.join(" "); + } + reindex(); + }; + + that.toggle = function (token, force) { + preop.apply(that, [token]); + + /** Token state's being forced. */ + if (undefined !== force) { + if (force) { + that.add(token); + return true; + } else { + that.remove(token); + return false; + } + } + + /** Token already exists in tokenList. Remove it, and return FALSE. */ + if (tokenMap[token]) { + that.remove(token); + return false; + } + + /** Otherwise, add the token and return TRUE. */ + that.add(token); + return true; + }; + + return that; + }; + + return _DOMTokenList; + }()); + } + + // Add second argument to native DOMTokenList.toggle() if necessary + (function () { + var e = document.createElement('span'); + if (!('classList' in e)) return; + e.classList.toggle('x', false); + if (!e.classList.contains('x')) return; + e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) { + var force = arguments[1]; + if (force === undefined) { + var add = !this.contains(token); + this[add ? 'add' : 'remove'](token); + return add; + } + force = !!force; + this[force ? 'add' : 'remove'](token); + return force; + }; + }()); + + // Add multiple arguments to native DOMTokenList.add() if necessary + (function () { + var e = document.createElement('span'); + if (!('classList' in e)) return; + e.classList.add('a', 'b'); + if (e.classList.contains('b')) return; + var native = e.classList.constructor.prototype.add; + e.classList.constructor.prototype.add = function () { + var args = arguments; + var l = arguments.length; + for (var i = 0; i < l; i++) { + native.call(this, args[i]); + } + }; + }()); + + // Add multiple arguments to native DOMTokenList.remove() if necessary + (function () { + var e = document.createElement('span'); + if (!('classList' in e)) return; + e.classList.add('a'); + e.classList.add('b'); + e.classList.remove('a', 'b'); + if (!e.classList.contains('b')) return; + var native = e.classList.constructor.prototype.remove; + e.classList.constructor.prototype.remove = function () { + var args = arguments; + var l = arguments.length; + for (var i = 0; i < l; i++) { + native.call(this, args[i]); + } + }; + }()); + + }(this)); + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js + var detect = ("Document" in this); + + if (detect) return + + if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) { + + if (this.HTMLDocument) { // IE8 + + // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter. + this.Document = this.HTMLDocument; + + } else { + + // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made. + this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')()); + this.Document.prototype = document; + } + } + + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js + var detect = ('Element' in this && 'HTMLElement' in this); + + if (detect) return + + (function () { + + // IE8 + if (window.Element && !window.HTMLElement) { + window.HTMLElement = window.Element; + return; + } + + // create Element constructor + window.Element = window.HTMLElement = new Function('return function Element() {}')(); + + // generate sandboxed iframe + var vbody = document.appendChild(document.createElement('body')); + var frame = vbody.appendChild(document.createElement('iframe')); + + // use sandboxed iframe to replicate Element functionality + var frameDocument = frame.contentWindow.document; + var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*')); + var cache = {}; + + // polyfill Element.prototype on an element + var shiv = function (element, deep) { + var + childNodes = element.childNodes || [], + index = -1, + key, value, childNode; + + if (element.nodeType === 1 && element.constructor !== Element) { + element.constructor = Element; + + for (key in cache) { + value = cache[key]; + element[key] = value; + } + } + + while (childNode = deep && childNodes[++index]) { + shiv(childNode, deep); + } + + return element; + }; + + var elements = document.getElementsByTagName('*'); + var nativeCreateElement = document.createElement; + var interval; + var loopLimit = 100; + + prototype.attachEvent('onpropertychange', function (event) { + var + propertyName = event.propertyName, + nonValue = !cache.hasOwnProperty(propertyName), + newValue = prototype[propertyName], + oldValue = cache[propertyName], + index = -1, + element; + + while (element = elements[++index]) { + if (element.nodeType === 1) { + if (nonValue || element[propertyName] === oldValue) { + element[propertyName] = newValue; + } + } + } + + cache[propertyName] = newValue; + }); + + prototype.constructor = Element; + + if (!prototype.hasAttribute) { + // .hasAttribute + prototype.hasAttribute = function hasAttribute(name) { + return this.getAttribute(name) !== null; + }; + } + + // Apply Element prototype to the pre-existing DOM as soon as the body element appears. + function bodyCheck() { + if (!(loopLimit--)) clearTimeout(interval); + if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) { + shiv(document, true); + if (interval && document.body.prototype) clearTimeout(interval); + return (!!document.body.prototype); + } + return false; + } + if (!bodyCheck()) { + document.onreadystatechange = bodyCheck; + interval = setInterval(bodyCheck, 25); + } + + // Apply to any new elements created after load + document.createElement = function createElement(nodeName) { + var element = nativeCreateElement(String(nodeName).toLowerCase()); + return shiv(element); + }; + + // remove sandboxed iframe + document.removeChild(vbody); + }()); + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/detect.js + var detect = ( + 'document' in this && "classList" in document.documentElement && 'Element' in this && 'classList' in Element.prototype && (function () { + var e = document.createElement('span'); + e.classList.add('a', 'b'); + return e.classList.contains('b'); + }()) + ); + + if (detect) return + + (function (global) { + var dpSupport = true; + var defineGetter = function (object, name, fn, configurable) { + if (Object.defineProperty) + Object.defineProperty(object, name, { + configurable: false === dpSupport ? true : !!configurable, + get: fn + }); + + else object.__defineGetter__(name, fn); + }; + /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */ + try { + defineGetter({}, "support"); + } + catch (e) { + dpSupport = false; + } + /** Polyfills a property with a DOMTokenList */ + var addProp = function (o, name, attr) { + + defineGetter(o.prototype, name, function () { + var tokenList; + + var THIS = this, + + /** Prevent this from firing twice for some reason. What the hell, IE. */ + gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name; + if(THIS[gibberishProperty]) return tokenList; + THIS[gibberishProperty] = true; + + /** + * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead. + * + * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror") + * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML + * element instead, this would conflict with element types which use indexed properties (such as forms and + * select lists). + */ + if (false === dpSupport) { + + var visage; + var mirror = addProp.mirror || document.createElement("div"); + var reflections = mirror.childNodes; + var l = reflections.length; + + for (var i = 0; i < l; ++i) + if (reflections[i]._R === THIS) { + visage = reflections[i]; + break; + } + + /** Couldn't find an element's reflection inside the mirror. Materialise one. */ + visage || (visage = mirror.appendChild(document.createElement("div"))); + + tokenList = DOMTokenList.call(visage, THIS, attr); + } else tokenList = new DOMTokenList(THIS, attr); + + defineGetter(THIS, name, function () { + return tokenList; + }); + delete THIS[gibberishProperty]; + + return tokenList; + }, true); + }; + + addProp(global.Element, "classList", "className"); + addProp(global.HTMLElement, "classList", "className"); + addProp(global.HTMLLinkElement, "relList", "rel"); + addProp(global.HTMLAnchorElement, "relList", "rel"); + addProp(global.HTMLAreaElement, "relList", "rel"); + }(this)); + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/closest.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/closest.js new file mode 100644 index 0000000000..b48a227339 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/closest.js @@ -0,0 +1,57 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/detect.js + var detect = ( + 'document' in this && "matches" in document.documentElement + ); + + if (detect) return + + // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/polyfill.js + Element.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function matches(selector) { + var element = this; + var elements = (element.document || element.ownerDocument).querySelectorAll(selector); + var index = 0; + + while (elements[index] && elements[index] !== element) { + ++index; + } + + return !!elements[index]; + }; + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/detect.js + var detect = ( + 'document' in this && "closest" in document.documentElement + ); + + if (detect) return + + // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/polyfill.js + Element.prototype.closest = function closest(selector) { + var node = this; + + while (node) { + if (node.matches(selector)) return node; + else node = 'SVGElement' in window && node instanceof SVGElement ? node.parentNode : node.parentElement; + } + + return null; + }; + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/dataset.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/dataset.js new file mode 100644 index 0000000000..dc3d83244f --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/dataset.js @@ -0,0 +1,303 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js + var detect = ( + // In IE8, defineProperty could only act on DOM elements, so full support + // for the feature requires the ability to set a property on an arbitrary object + 'defineProperty' in Object && (function() { + try { + var a = {}; + Object.defineProperty(a, 'test', {value:42}); + return true; + } catch(e) { + return false + } + }()) + ); + + if (detect) return + + (function (nativeDefineProperty) { + + var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); + var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; + var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + // Where native support exists, assume it + if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { + return nativeDefineProperty(object, property, descriptor); + } + + if (object === null || !(object instanceof Object || typeof object === 'object')) { + throw new TypeError('Object.defineProperty called on non-object'); + } + + if (!(descriptor instanceof Object)) { + throw new TypeError('Property description must be an object'); + } + + var propertyString = String(property); + var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; + var getterType = 'get' in descriptor && typeof descriptor.get; + var setterType = 'set' in descriptor && typeof descriptor.set; + + // handle descriptor.get + if (getterType) { + if (getterType !== 'function') { + throw new TypeError('Getter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineGetter__.call(object, propertyString, descriptor.get); + } else { + object[propertyString] = descriptor.value; + } + + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineSetter__.call(object, propertyString, descriptor.set); + } + + // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above + if ('value' in descriptor) { + object[propertyString] = descriptor.value; + } + + return object; + }; + }(Object.defineProperty)); + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js + var detect = ("Document" in this); + + if (detect) return + + if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) { + + if (this.HTMLDocument) { // IE8 + + // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter. + this.Document = this.HTMLDocument; + + } else { + + // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made. + this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')()); + this.Document.prototype = document; + } + } + + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js + var detect = ('Element' in this && 'HTMLElement' in this); + + if (detect) return + + (function () { + + // IE8 + if (window.Element && !window.HTMLElement) { + window.HTMLElement = window.Element; + return; + } + + // create Element constructor + window.Element = window.HTMLElement = new Function('return function Element() {}')(); + + // generate sandboxed iframe + var vbody = document.appendChild(document.createElement('body')); + var frame = vbody.appendChild(document.createElement('iframe')); + + // use sandboxed iframe to replicate Element functionality + var frameDocument = frame.contentWindow.document; + var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*')); + var cache = {}; + + // polyfill Element.prototype on an element + var shiv = function (element, deep) { + var + childNodes = element.childNodes || [], + index = -1, + key, value, childNode; + + if (element.nodeType === 1 && element.constructor !== Element) { + element.constructor = Element; + + for (key in cache) { + value = cache[key]; + element[key] = value; + } + } + + while (childNode = deep && childNodes[++index]) { + shiv(childNode, deep); + } + + return element; + }; + + var elements = document.getElementsByTagName('*'); + var nativeCreateElement = document.createElement; + var interval; + var loopLimit = 100; + + prototype.attachEvent('onpropertychange', function (event) { + var + propertyName = event.propertyName, + nonValue = !cache.hasOwnProperty(propertyName), + newValue = prototype[propertyName], + oldValue = cache[propertyName], + index = -1, + element; + + while (element = elements[++index]) { + if (element.nodeType === 1) { + if (nonValue || element[propertyName] === oldValue) { + element[propertyName] = newValue; + } + } + } + + cache[propertyName] = newValue; + }); + + prototype.constructor = Element; + + if (!prototype.hasAttribute) { + // .hasAttribute + prototype.hasAttribute = function hasAttribute(name) { + return this.getAttribute(name) !== null; + }; + } + + // Apply Element prototype to the pre-existing DOM as soon as the body element appears. + function bodyCheck() { + if (!(loopLimit--)) clearTimeout(interval); + if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) { + shiv(document, true); + if (interval && document.body.prototype) clearTimeout(interval); + return (!!document.body.prototype); + } + return false; + } + if (!bodyCheck()) { + document.onreadystatechange = bodyCheck; + interval = setInterval(bodyCheck, 25); + } + + // Apply to any new elements created after load + document.createElement = function createElement(nodeName) { + var element = nativeCreateElement(String(nodeName).toLowerCase()); + return shiv(element); + }; + + // remove sandboxed iframe + document.removeChild(vbody); + }()); + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/13cf7c340974d128d557580b5e2dafcd1b1192d1/polyfills/Element/prototype/dataset/detect.js + var detect = (function(){ + if (!document.documentElement.dataset) { + return false; + } + var el = document.createElement('div'); + el.setAttribute("data-a-b", "c"); + return el.dataset && el.dataset.aB == "c"; + }()); + + if (detect) return + + // Polyfill derived from https://raw.githubusercontent.com/Financial-Times/polyfill-library/13cf7c340974d128d557580b5e2dafcd1b1192d1/polyfills/Element/prototype/dataset/polyfill.js + Object.defineProperty(Element.prototype, 'dataset', { + get: function() { + var element = this; + var attributes = this.attributes; + var map = {}; + + for (var i = 0; i < attributes.length; i++) { + var attribute = attributes[i]; + + // This regex has been edited from the original polyfill, to add + // support for period (.) separators in data-* attribute names. These + // are allowed in the HTML spec, but were not covered by the original + // polyfill's regex. We use periods in our i18n implementation. + if (attribute && attribute.name && (/^data-\w[.\w-]*$/).test(attribute.name)) { + var name = attribute.name; + var value = attribute.value; + + var propName = name.substr(5).replace(/-./g, function (prop) { + return prop.charAt(1).toUpperCase(); + }); + + // If this browser supports __defineGetter__ and __defineSetter__, + // continue using defineProperty. If not (like IE 8 and below), we use + // a hacky fallback which at least gives an object in the right format + if ('__defineGetter__' in Object.prototype && '__defineSetter__' in Object.prototype) { + Object.defineProperty(map, propName, { + enumerable: true, + get: function() { + return this.value; + }.bind({value: value || ''}), + set: function setter(name, value) { + if (typeof value !== 'undefined') { + this.setAttribute(name, value); + } else { + this.removeAttribute(name); + } + }.bind(element, name) + }); + } else { + map[propName] = value; + } + + } + } + + return map; + } + }); + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/matches.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/matches.js new file mode 100644 index 0000000000..44a526157a --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/matches.js @@ -0,0 +1,32 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/detect.js + var detect = ( + 'document' in this && "matches" in document.documentElement + ); + + if (detect) return + + // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/polyfill.js + Element.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function matches(selector) { + var element = this; + var elements = (element.document || element.ownerDocument).querySelectorAll(selector); + var index = 0; + + while (elements[index] && elements[index] !== element) { + ++index; + } + + return !!elements[index]; + }; + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/nextElementSibling.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/nextElementSibling.js new file mode 100644 index 0000000000..b08b2fe451 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/nextElementSibling.js @@ -0,0 +1,257 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js + var detect = ( + // In IE8, defineProperty could only act on DOM elements, so full support + // for the feature requires the ability to set a property on an arbitrary object + 'defineProperty' in Object && (function() { + try { + var a = {}; + Object.defineProperty(a, 'test', {value:42}); + return true; + } catch(e) { + return false + } + }()) + ); + + if (detect) return + + (function (nativeDefineProperty) { + + var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); + var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; + var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + // Where native support exists, assume it + if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { + return nativeDefineProperty(object, property, descriptor); + } + + if (object === null || !(object instanceof Object || typeof object === 'object')) { + throw new TypeError('Object.defineProperty called on non-object'); + } + + if (!(descriptor instanceof Object)) { + throw new TypeError('Property description must be an object'); + } + + var propertyString = String(property); + var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; + var getterType = 'get' in descriptor && typeof descriptor.get; + var setterType = 'set' in descriptor && typeof descriptor.set; + + // handle descriptor.get + if (getterType) { + if (getterType !== 'function') { + throw new TypeError('Getter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineGetter__.call(object, propertyString, descriptor.get); + } else { + object[propertyString] = descriptor.value; + } + + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineSetter__.call(object, propertyString, descriptor.set); + } + + // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above + if ('value' in descriptor) { + object[propertyString] = descriptor.value; + } + + return object; + }; + }(Object.defineProperty)); + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js + var detect = ("Document" in this); + + if (detect) return + + if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) { + + if (this.HTMLDocument) { // IE8 + + // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter. + this.Document = this.HTMLDocument; + + } else { + + // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made. + this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')()); + this.Document.prototype = document; + } + } + + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js + var detect = ('Element' in this && 'HTMLElement' in this); + + if (detect) return + + (function () { + + // IE8 + if (window.Element && !window.HTMLElement) { + window.HTMLElement = window.Element; + return; + } + + // create Element constructor + window.Element = window.HTMLElement = new Function('return function Element() {}')(); + + // generate sandboxed iframe + var vbody = document.appendChild(document.createElement('body')); + var frame = vbody.appendChild(document.createElement('iframe')); + + // use sandboxed iframe to replicate Element functionality + var frameDocument = frame.contentWindow.document; + var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*')); + var cache = {}; + + // polyfill Element.prototype on an element + var shiv = function (element, deep) { + var + childNodes = element.childNodes || [], + index = -1, + key, value, childNode; + + if (element.nodeType === 1 && element.constructor !== Element) { + element.constructor = Element; + + for (key in cache) { + value = cache[key]; + element[key] = value; + } + } + + while (childNode = deep && childNodes[++index]) { + shiv(childNode, deep); + } + + return element; + }; + + var elements = document.getElementsByTagName('*'); + var nativeCreateElement = document.createElement; + var interval; + var loopLimit = 100; + + prototype.attachEvent('onpropertychange', function (event) { + var + propertyName = event.propertyName, + nonValue = !cache.hasOwnProperty(propertyName), + newValue = prototype[propertyName], + oldValue = cache[propertyName], + index = -1, + element; + + while (element = elements[++index]) { + if (element.nodeType === 1) { + if (nonValue || element[propertyName] === oldValue) { + element[propertyName] = newValue; + } + } + } + + cache[propertyName] = newValue; + }); + + prototype.constructor = Element; + + if (!prototype.hasAttribute) { + // .hasAttribute + prototype.hasAttribute = function hasAttribute(name) { + return this.getAttribute(name) !== null; + }; + } + + // Apply Element prototype to the pre-existing DOM as soon as the body element appears. + function bodyCheck() { + if (!(loopLimit--)) clearTimeout(interval); + if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) { + shiv(document, true); + if (interval && document.body.prototype) clearTimeout(interval); + return (!!document.body.prototype); + } + return false; + } + if (!bodyCheck()) { + document.onreadystatechange = bodyCheck; + interval = setInterval(bodyCheck, 25); + } + + // Apply to any new elements created after load + document.createElement = function createElement(nodeName) { + var element = nativeCreateElement(String(nodeName).toLowerCase()); + return shiv(element); + }; + + // remove sandboxed iframe + document.removeChild(vbody); + }()); + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/nextElementSibling/detect.js + var detect = ( + 'document' in this && "nextElementSibling" in document.documentElement + ); + + if (detect) return + + // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/nextElementSibling/polyfill.js + Object.defineProperty(Element.prototype, "nextElementSibling", { + get: function(){ + var el = this.nextSibling; + while (el && el.nodeType !== 1) { el = el.nextSibling; } + return el; + } + }); + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/previousElementSibling.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/previousElementSibling.js new file mode 100644 index 0000000000..6a68741bf5 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Element/prototype/previousElementSibling.js @@ -0,0 +1,257 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js + var detect = ( + // In IE8, defineProperty could only act on DOM elements, so full support + // for the feature requires the ability to set a property on an arbitrary object + 'defineProperty' in Object && (function() { + try { + var a = {}; + Object.defineProperty(a, 'test', {value:42}); + return true; + } catch(e) { + return false + } + }()) + ); + + if (detect) return + + (function (nativeDefineProperty) { + + var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); + var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; + var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + // Where native support exists, assume it + if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { + return nativeDefineProperty(object, property, descriptor); + } + + if (object === null || !(object instanceof Object || typeof object === 'object')) { + throw new TypeError('Object.defineProperty called on non-object'); + } + + if (!(descriptor instanceof Object)) { + throw new TypeError('Property description must be an object'); + } + + var propertyString = String(property); + var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; + var getterType = 'get' in descriptor && typeof descriptor.get; + var setterType = 'set' in descriptor && typeof descriptor.set; + + // handle descriptor.get + if (getterType) { + if (getterType !== 'function') { + throw new TypeError('Getter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineGetter__.call(object, propertyString, descriptor.get); + } else { + object[propertyString] = descriptor.value; + } + + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineSetter__.call(object, propertyString, descriptor.set); + } + + // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above + if ('value' in descriptor) { + object[propertyString] = descriptor.value; + } + + return object; + }; + }(Object.defineProperty)); + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js + var detect = ("Document" in this); + + if (detect) return + + if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) { + + if (this.HTMLDocument) { // IE8 + + // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter. + this.Document = this.HTMLDocument; + + } else { + + // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made. + this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')()); + this.Document.prototype = document; + } + } + + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js + var detect = ('Element' in this && 'HTMLElement' in this); + + if (detect) return + + (function () { + + // IE8 + if (window.Element && !window.HTMLElement) { + window.HTMLElement = window.Element; + return; + } + + // create Element constructor + window.Element = window.HTMLElement = new Function('return function Element() {}')(); + + // generate sandboxed iframe + var vbody = document.appendChild(document.createElement('body')); + var frame = vbody.appendChild(document.createElement('iframe')); + + // use sandboxed iframe to replicate Element functionality + var frameDocument = frame.contentWindow.document; + var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*')); + var cache = {}; + + // polyfill Element.prototype on an element + var shiv = function (element, deep) { + var + childNodes = element.childNodes || [], + index = -1, + key, value, childNode; + + if (element.nodeType === 1 && element.constructor !== Element) { + element.constructor = Element; + + for (key in cache) { + value = cache[key]; + element[key] = value; + } + } + + while (childNode = deep && childNodes[++index]) { + shiv(childNode, deep); + } + + return element; + }; + + var elements = document.getElementsByTagName('*'); + var nativeCreateElement = document.createElement; + var interval; + var loopLimit = 100; + + prototype.attachEvent('onpropertychange', function (event) { + var + propertyName = event.propertyName, + nonValue = !cache.hasOwnProperty(propertyName), + newValue = prototype[propertyName], + oldValue = cache[propertyName], + index = -1, + element; + + while (element = elements[++index]) { + if (element.nodeType === 1) { + if (nonValue || element[propertyName] === oldValue) { + element[propertyName] = newValue; + } + } + } + + cache[propertyName] = newValue; + }); + + prototype.constructor = Element; + + if (!prototype.hasAttribute) { + // .hasAttribute + prototype.hasAttribute = function hasAttribute(name) { + return this.getAttribute(name) !== null; + }; + } + + // Apply Element prototype to the pre-existing DOM as soon as the body element appears. + function bodyCheck() { + if (!(loopLimit--)) clearTimeout(interval); + if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) { + shiv(document, true); + if (interval && document.body.prototype) clearTimeout(interval); + return (!!document.body.prototype); + } + return false; + } + if (!bodyCheck()) { + document.onreadystatechange = bodyCheck; + interval = setInterval(bodyCheck, 25); + } + + // Apply to any new elements created after load + document.createElement = function createElement(nodeName) { + var element = nativeCreateElement(String(nodeName).toLowerCase()); + return shiv(element); + }; + + // remove sandboxed iframe + document.removeChild(vbody); + }()); + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/previousElementSibling/detect.js + var detect = ( + 'document' in this && "previousElementSibling" in document.documentElement + ); + + if (detect) return + + // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/previousElementSibling/polyfill.js + Object.defineProperty(Element.prototype, 'previousElementSibling', { + get: function(){ + var el = this.previousSibling; + while (el && el.nodeType !== 1) { el = el.previousSibling; } + return el; + } + }); + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Event.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Event.js new file mode 100644 index 0000000000..ab568046e2 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Event.js @@ -0,0 +1,506 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js + var detect = ('Window' in this); + + if (detect) return + + if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) { + (function (global) { + if (global.constructor) { + global.Window = global.constructor; + } else { + (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this; + } + }(this)); + } + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js + var detect = ("Document" in this); + + if (detect) return + + if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) { + + if (this.HTMLDocument) { // IE8 + + // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter. + this.Document = this.HTMLDocument; + + } else { + + // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made. + this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')()); + this.Document.prototype = document; + } + } + + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js + var detect = ('Element' in this && 'HTMLElement' in this); + + if (detect) return + + (function () { + + // IE8 + if (window.Element && !window.HTMLElement) { + window.HTMLElement = window.Element; + return; + } + + // create Element constructor + window.Element = window.HTMLElement = new Function('return function Element() {}')(); + + // generate sandboxed iframe + var vbody = document.appendChild(document.createElement('body')); + var frame = vbody.appendChild(document.createElement('iframe')); + + // use sandboxed iframe to replicate Element functionality + var frameDocument = frame.contentWindow.document; + var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*')); + var cache = {}; + + // polyfill Element.prototype on an element + var shiv = function (element, deep) { + var + childNodes = element.childNodes || [], + index = -1, + key, value, childNode; + + if (element.nodeType === 1 && element.constructor !== Element) { + element.constructor = Element; + + for (key in cache) { + value = cache[key]; + element[key] = value; + } + } + + while (childNode = deep && childNodes[++index]) { + shiv(childNode, deep); + } + + return element; + }; + + var elements = document.getElementsByTagName('*'); + var nativeCreateElement = document.createElement; + var interval; + var loopLimit = 100; + + prototype.attachEvent('onpropertychange', function (event) { + var + propertyName = event.propertyName, + nonValue = !cache.hasOwnProperty(propertyName), + newValue = prototype[propertyName], + oldValue = cache[propertyName], + index = -1, + element; + + while (element = elements[++index]) { + if (element.nodeType === 1) { + if (nonValue || element[propertyName] === oldValue) { + element[propertyName] = newValue; + } + } + } + + cache[propertyName] = newValue; + }); + + prototype.constructor = Element; + + if (!prototype.hasAttribute) { + // .hasAttribute + prototype.hasAttribute = function hasAttribute(name) { + return this.getAttribute(name) !== null; + }; + } + + // Apply Element prototype to the pre-existing DOM as soon as the body element appears. + function bodyCheck() { + if (!(loopLimit--)) clearTimeout(interval); + if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) { + shiv(document, true); + if (interval && document.body.prototype) clearTimeout(interval); + return (!!document.body.prototype); + } + return false; + } + if (!bodyCheck()) { + document.onreadystatechange = bodyCheck; + interval = setInterval(bodyCheck, 25); + } + + // Apply to any new elements created after load + document.createElement = function createElement(nodeName) { + var element = nativeCreateElement(String(nodeName).toLowerCase()); + return shiv(element); + }; + + // remove sandboxed iframe + document.removeChild(vbody); + }()); + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js + var detect = ( + // In IE8, defineProperty could only act on DOM elements, so full support + // for the feature requires the ability to set a property on an arbitrary object + 'defineProperty' in Object && (function() { + try { + var a = {}; + Object.defineProperty(a, 'test', {value:42}); + return true; + } catch(e) { + return false + } + }()) + ); + + if (detect) return + + (function (nativeDefineProperty) { + + var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); + var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; + var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + // Where native support exists, assume it + if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { + return nativeDefineProperty(object, property, descriptor); + } + + if (object === null || !(object instanceof Object || typeof object === 'object')) { + throw new TypeError('Object.defineProperty called on non-object'); + } + + if (!(descriptor instanceof Object)) { + throw new TypeError('Property description must be an object'); + } + + var propertyString = String(property); + var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; + var getterType = 'get' in descriptor && typeof descriptor.get; + var setterType = 'set' in descriptor && typeof descriptor.set; + + // handle descriptor.get + if (getterType) { + if (getterType !== 'function') { + throw new TypeError('Getter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineGetter__.call(object, propertyString, descriptor.get); + } else { + object[propertyString] = descriptor.value; + } + + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineSetter__.call(object, propertyString, descriptor.set); + } + + // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above + if ('value' in descriptor) { + object[propertyString] = descriptor.value; + } + + return object; + }; + }(Object.defineProperty)); + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js + var detect = ( + (function(global) { + + if (!('Event' in global)) return false; + if (typeof global.Event === 'function') return true; + + try { + + // In IE 9-11, the Event object exists but cannot be instantiated + new Event('click'); + return true; + } catch(e) { + return false; + } + }(this)) + ); + + if (detect) return + + (function () { + var unlistenableWindowEvents = { + click: 1, + dblclick: 1, + keyup: 1, + keypress: 1, + keydown: 1, + mousedown: 1, + mouseup: 1, + mousemove: 1, + mouseover: 1, + mouseenter: 1, + mouseleave: 1, + mouseout: 1, + storage: 1, + storagecommit: 1, + textinput: 1 + }; + + // This polyfill depends on availability of `document` so will not run in a worker + // However, we asssume there are no browsers with worker support that lack proper + // support for `Event` within the worker + if (typeof document === 'undefined' || typeof window === 'undefined') return; + + function indexOf(array, element) { + var + index = -1, + length = array.length; + + while (++index < length) { + if (index in array && array[index] === element) { + return index; + } + } + + return -1; + } + + var existingProto = (window.Event && window.Event.prototype) || null; + window.Event = Window.prototype.Event = function Event(type, eventInitDict) { + if (!type) { + throw new Error('Not enough arguments'); + } + + var event; + // Shortcut if browser supports createEvent + if ('createEvent' in document) { + event = document.createEvent('Event'); + var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false; + var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false; + + event.initEvent(type, bubbles, cancelable); + + return event; + } + + event = document.createEventObject(); + + event.type = type; + event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false; + event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false; + + return event; + }; + if (existingProto) { + Object.defineProperty(window.Event, 'prototype', { + configurable: false, + enumerable: false, + writable: true, + value: existingProto + }); + } + + if (!('createEvent' in document)) { + window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() { + var + element = this, + type = arguments[0], + listener = arguments[1]; + + if (element === window && type in unlistenableWindowEvents) { + throw new Error('In IE8 the event: ' + type + ' is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.'); + } + + if (!element._events) { + element._events = {}; + } + + if (!element._events[type]) { + element._events[type] = function (event) { + var + list = element._events[event.type].list, + events = list.slice(), + index = -1, + length = events.length, + eventElement; + + event.preventDefault = function preventDefault() { + if (event.cancelable !== false) { + event.returnValue = false; + } + }; + + event.stopPropagation = function stopPropagation() { + event.cancelBubble = true; + }; + + event.stopImmediatePropagation = function stopImmediatePropagation() { + event.cancelBubble = true; + event.cancelImmediate = true; + }; + + event.currentTarget = element; + event.relatedTarget = event.fromElement || null; + event.target = event.target || event.srcElement || element; + event.timeStamp = new Date().getTime(); + + if (event.clientX) { + event.pageX = event.clientX + document.documentElement.scrollLeft; + event.pageY = event.clientY + document.documentElement.scrollTop; + } + + while (++index < length && !event.cancelImmediate) { + if (index in events) { + eventElement = events[index]; + + if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') { + eventElement.call(element, event); + } + } + } + }; + + element._events[type].list = []; + + if (element.attachEvent) { + element.attachEvent('on' + type, element._events[type]); + } + } + + element._events[type].list.push(listener); + }; + + window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() { + var + element = this, + type = arguments[0], + listener = arguments[1], + index; + + if (element._events && element._events[type] && element._events[type].list) { + index = indexOf(element._events[type].list, listener); + + if (index !== -1) { + element._events[type].list.splice(index, 1); + + if (!element._events[type].list.length) { + if (element.detachEvent) { + element.detachEvent('on' + type, element._events[type]); + } + delete element._events[type]; + } + } + } + }; + + window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) { + if (!arguments.length) { + throw new Error('Not enough arguments'); + } + + if (!event || typeof event.type !== 'string') { + throw new Error('DOM Events Exception 0'); + } + + var element = this, type = event.type; + + try { + if (!event.bubbles) { + event.cancelBubble = true; + + var cancelBubbleEvent = function (event) { + event.cancelBubble = true; + + (element || window).detachEvent('on' + type, cancelBubbleEvent); + }; + + this.attachEvent('on' + type, cancelBubbleEvent); + } + + this.fireEvent('on' + type, event); + } catch (error) { + event.target = element; + + do { + event.currentTarget = element; + + if ('_events' in element && typeof element._events[type] === 'function') { + element._events[type].call(element, event); + } + + if (typeof element['on' + type] === 'function') { + element['on' + type].call(element, event); + } + + element = element.nodeType === 9 ? element.parentWindow : element.parentNode; + } while (element && !event.cancelBubble); + } + + return true; + }; + + // Add the DOMContentLoaded Event + document.attachEvent('onreadystatechange', function() { + if (document.readyState === 'complete') { + document.dispatchEvent(new Event('DOMContentLoaded', { + bubbles: true + })); + } + }); + } + }()); + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Function/prototype/bind.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Function/prototype/bind.js new file mode 100644 index 0000000000..4c736d6ae7 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Function/prototype/bind.js @@ -0,0 +1,253 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js + var detect = ( + // In IE8, defineProperty could only act on DOM elements, so full support + // for the feature requires the ability to set a property on an arbitrary object + 'defineProperty' in Object && (function() { + try { + var a = {}; + Object.defineProperty(a, 'test', {value:42}); + return true; + } catch(e) { + return false + } + }()) + ); + + if (detect) return + + (function (nativeDefineProperty) { + + var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); + var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; + var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + // Where native support exists, assume it + if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { + return nativeDefineProperty(object, property, descriptor); + } + + if (object === null || !(object instanceof Object || typeof object === 'object')) { + throw new TypeError('Object.defineProperty called on non-object'); + } + + if (!(descriptor instanceof Object)) { + throw new TypeError('Property description must be an object'); + } + + var propertyString = String(property); + var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; + var getterType = 'get' in descriptor && typeof descriptor.get; + var setterType = 'set' in descriptor && typeof descriptor.set; + + // handle descriptor.get + if (getterType) { + if (getterType !== 'function') { + throw new TypeError('Getter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineGetter__.call(object, propertyString, descriptor.get); + } else { + object[propertyString] = descriptor.value; + } + + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineSetter__.call(object, propertyString, descriptor.set); + } + + // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above + if ('value' in descriptor) { + object[propertyString] = descriptor.value; + } + + return object; + }; + }(Object.defineProperty)); + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + + // @ts-nocheck + + (function(undefined) { + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js + var detect = 'bind' in Function.prototype; + + if (detect) return + + Object.defineProperty(Function.prototype, 'bind', { + value: function bind(that) { // .length is 1 + // add necessary es5-shim utilities + var $Array = Array; + var $Object = Object; + var ObjectPrototype = $Object.prototype; + var ArrayPrototype = $Array.prototype; + var Empty = function Empty() {}; + var to_string = ObjectPrototype.toString; + var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; + var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; }; + var array_slice = ArrayPrototype.slice; + var array_concat = ArrayPrototype.concat; + var array_push = ArrayPrototype.push; + var max = Math.max; + // /add necessary es5-shim utilities + + // 1. Let Target be the this value. + var target = this; + // 2. If IsCallable(Target) is false, throw a TypeError exception. + if (!isCallable(target)) { + throw new TypeError('Function.prototype.bind called on incompatible ' + target); + } + // 3. Let A be a new (possibly empty) internal list of all of the + // argument values provided after thisArg (arg1, arg2 etc), in order. + // XXX slicedArgs will stand in for "A" if used + var args = array_slice.call(arguments, 1); // for normal call + // 4. Let F be a new native ECMAScript object. + // 11. Set the [[Prototype]] internal property of F to the standard + // built-in Function prototype object as specified in 15.3.3.1. + // 12. Set the [[Call]] internal property of F as described in + // 15.3.4.5.1. + // 13. Set the [[Construct]] internal property of F as described in + // 15.3.4.5.2. + // 14. Set the [[HasInstance]] internal property of F as described in + // 15.3.4.5.3. + var bound; + var binder = function () { + + if (this instanceof bound) { + // 15.3.4.5.2 [[Construct]] + // When the [[Construct]] internal method of a function object, + // F that was created using the bind function is called with a + // list of arguments ExtraArgs, the following steps are taken: + // 1. Let target be the value of F's [[TargetFunction]] + // internal property. + // 2. If target has no [[Construct]] internal method, a + // TypeError exception is thrown. + // 3. Let boundArgs be the value of F's [[BoundArgs]] internal + // property. + // 4. Let args be a new list containing the same values as the + // list boundArgs in the same order followed by the same + // values as the list ExtraArgs in the same order. + // 5. Return the result of calling the [[Construct]] internal + // method of target providing args as the arguments. + + var result = target.apply( + this, + array_concat.call(args, array_slice.call(arguments)) + ); + if ($Object(result) === result) { + return result; + } + return this; + + } else { + // 15.3.4.5.1 [[Call]] + // When the [[Call]] internal method of a function object, F, + // which was created using the bind function is called with a + // this value and a list of arguments ExtraArgs, the following + // steps are taken: + // 1. Let boundArgs be the value of F's [[BoundArgs]] internal + // property. + // 2. Let boundThis be the value of F's [[BoundThis]] internal + // property. + // 3. Let target be the value of F's [[TargetFunction]] internal + // property. + // 4. Let args be a new list containing the same values as the + // list boundArgs in the same order followed by the same + // values as the list ExtraArgs in the same order. + // 5. Return the result of calling the [[Call]] internal method + // of target providing boundThis as the this value and + // providing args as the arguments. + + // equiv: target.call(this, ...boundArgs, ...args) + return target.apply( + that, + array_concat.call(args, array_slice.call(arguments)) + ); + + } + + }; + + // 15. If the [[Class]] internal property of Target is "Function", then + // a. Let L be the length property of Target minus the length of A. + // b. Set the length own property of F to either 0 or L, whichever is + // larger. + // 16. Else set the length own property of F to 0. + + var boundLength = max(0, target.length - args.length); + + // 17. Set the attributes of the length own property of F to the values + // specified in 15.3.5.1. + var boundArgs = []; + for (var i = 0; i < boundLength; i++) { + array_push.call(boundArgs, '$' + i); + } + + // XXX Build a dynamic function with desired amount of arguments is the only + // way to set the length property of a function. + // In environments where Content Security Policies enabled (Chrome extensions, + // for ex.) all use of eval or Function costructor throws an exception. + // However in all of these environments Function.prototype.bind exists + // and so this code will never be executed. + bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder); + + if (target.prototype) { + Empty.prototype = target.prototype; + bound.prototype = new Empty(); + // Clean up dangling references. + Empty.prototype = null; + } + + // TODO + // 18. Set the [[Extensible]] internal property of F to true. + + // TODO + // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3). + // 20. Call the [[DefineOwnProperty]] internal method of F with + // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]: + // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and + // false. + // 21. Call the [[DefineOwnProperty]] internal method of F with + // arguments "arguments", PropertyDescriptor {[[Get]]: thrower, + // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false}, + // and false. + + // TODO + // NOTE Function objects created using Function.prototype.bind do not + // have a prototype property or the [[Code]], [[FormalParameters]], and + // [[Scope]] internal properties. + // XXX can't delete prototype in pure-js. + + // 22. Return F. + return bound; + } + }); + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Object/defineProperty.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Object/defineProperty.js new file mode 100644 index 0000000000..cc69cace21 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Object/defineProperty.js @@ -0,0 +1,94 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js + var detect = ( + // In IE8, defineProperty could only act on DOM elements, so full support + // for the feature requires the ability to set a property on an arbitrary object + 'defineProperty' in Object && (function() { + try { + var a = {}; + Object.defineProperty(a, 'test', {value:42}); + return true; + } catch(e) { + return false + } + }()) + ); + + if (detect) return + + (function (nativeDefineProperty) { + + var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); + var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; + var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + // Where native support exists, assume it + if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { + return nativeDefineProperty(object, property, descriptor); + } + + if (object === null || !(object instanceof Object || typeof object === 'object')) { + throw new TypeError('Object.defineProperty called on non-object'); + } + + if (!(descriptor instanceof Object)) { + throw new TypeError('Property description must be an object'); + } + + var propertyString = String(property); + var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; + var getterType = 'get' in descriptor && typeof descriptor.get; + var setterType = 'set' in descriptor && typeof descriptor.set; + + // handle descriptor.get + if (getterType) { + if (getterType !== 'function') { + throw new TypeError('Getter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineGetter__.call(object, propertyString, descriptor.get); + } else { + object[propertyString] = descriptor.value; + } + + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineSetter__.call(object, propertyString, descriptor.set); + } + + // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above + if ('value' in descriptor) { + object[propertyString] = descriptor.value; + } + + return object; + }; + }(Object.defineProperty)); + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/String/prototype/trim.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/String/prototype/trim.js new file mode 100644 index 0000000000..96479b0d80 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/String/prototype/trim.js @@ -0,0 +1,22 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/mdn/content/blob/cf607d68522cd35ee7670782d3ee3a361eaef2e4/files/en-us/web/javascript/reference/global_objects/string/trim/index.md#polyfill + var detect = ('trim' in String.prototype); + + if (detect) return + + // Polyfill from https://github.com/mdn/content/blob/cf607d68522cd35ee7670782d3ee3a361eaef2e4/files/en-us/web/javascript/reference/global_objects/string/trim/index.md#polyfill + String.prototype.trim = function () { + return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); + }; + + }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Window.js b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Window.js new file mode 100644 index 0000000000..3935021488 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/vendor/polyfills-govuk-frontend-v4/Window.js @@ -0,0 +1,28 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : + (factory()); +}(this, (function () { 'use strict'; + + // @ts-nocheck + (function (undefined) { + + // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js + var detect = ('Window' in this); + + if (detect) return + + if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) { + (function (global) { + if (global.constructor) { + global.Window = global.constructor; + } else { + (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this; + } + }(this)); + } + + }) + .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); + +}))); 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 c3561d3377..f0e1d70418 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss @@ -2,11 +2,12 @@ @import "govuk/components/checkboxes/checkboxes"; .govuk-checkboxes--nested { - margin-left: -(govuk-spacing(4) + 2px); // 22px + width: 100%; + margin-left: govuk-spacing(4); 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 dffd7756fb..d31812b9c7 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/_layout-super-navigation-header.scss b/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss index 3007868d56..e2a5196ef3 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss @@ -123,6 +123,7 @@ $after-button-padding-left: govuk-spacing(4); .gem-c-layout-super-navigation-header__header-logo { display: inline-block; height: govuk-spacing(6); + line-height: 1; padding-bottom: govuk-spacing(2); padding-top: govuk-spacing(2); } 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_admin.html.erb b/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb index ea09eb0cb4..2a4eeeb5c4 100644 --- a/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb +++ b/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb @@ -1,6 +1,7 @@ <% add_gem_component_stylesheet("layout-for-admin") js_filename ||= "application" + js_module_filename ||= "es6-components" css_filename ||= "application" product_name ||= "Publishing" @@ -17,6 +18,9 @@ <%= favicon_link_tag "govuk_publishing_components/favicon-#{environment}.png" %> <%= stylesheet_link_tag css_filename, media: "all" %> <%= javascript_include_tag "govuk_publishing_components/vendor/modernizr" %> + <% if GovukPublishingComponents::Config.use_es6_components %> + <%= javascript_include_tag js_module_filename, type: "module" %> + <% end %> <%= yield :head %> 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 4f5f668a57..d29b0647ac 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 @@ -80,12 +80,10 @@ <%= stylesheet_link_tag "application", media: "all" %> - - - "> - "> - "> - "> + + + + @@ -188,5 +186,8 @@ } %> <% end %> <%= javascript_include_tag 'application' %> + <% if GovukPublishingComponents::Config.use_es6_components %> + <%= javascript_include_tag 'es6-components', type: "module" %> + <% end %> <% 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..d69d8ed928 100644 --- a/app/views/govuk_publishing_components/components/_modal_dialogue.html.erb +++ b/app/views/govuk_publishing_components/components/_modal_dialogue.html.erb @@ -17,7 +17,6 @@ - <% end %> <%= tag.div yield, class: "gem-c-modal-dialogue__content" %> diff --git a/app/views/govuk_publishing_components/components/_phase_banner.html.erb b/app/views/govuk_publishing_components/components/_phase_banner.html.erb index e347a2a186..714cc4d89c 100644 --- a/app/views/govuk_publishing_components/components/_phase_banner.html.erb +++ b/app/views/govuk_publishing_components/components/_phase_banner.html.erb @@ -37,7 +37,7 @@ end <%= tag.div class: container_css_classes, data: data_attributes do %> <%= tag.p class: "govuk-phase-banner__content" do %> <%= tag.strong app_name, class: "govuk-phase-banner__content__app-name" if app_name %> - <%= tag.strong phase, class: "govuk-tag govuk-phase-banner__content__tag" if phase %> + <%= tag.strong phase.titleize, class: "govuk-tag govuk-phase-banner__content__tag" if phase %> <%= tag.span message, class: "govuk-phase-banner__text" if message %> <% end %> <% end %> diff --git a/app/views/govuk_publishing_components/components/_warning_text.html.erb b/app/views/govuk_publishing_components/components/_warning_text.html.erb index 456ffd327e..852d319da0 100644 --- a/app/views/govuk_publishing_components/components/_warning_text.html.erb +++ b/app/views/govuk_publishing_components/components/_warning_text.html.erb @@ -21,7 +21,7 @@ <%= tag.span text_icon, class: "govuk-warning-text__icon", "aria-hidden": "true" %> <% end %> <% inner_text = capture do %> - <%= tag.span text_assistive, class: "govuk-warning-text__assistive" %> + <%= tag.span text_assistive, class: "govuk-visually-hidden" %> <%= text %> <% end %> <% if heading_level > 0 %> diff --git a/app/views/govuk_publishing_components/components/docs/accordion.yml b/app/views/govuk_publishing_components/components/docs/accordion.yml index f610fd2ae2..2c210cb3cc 100644 --- a/app/views/govuk_publishing_components/components/docs/accordion.yml +++ b/app/views/govuk_publishing_components/components/docs/accordion.yml @@ -23,7 +23,6 @@ accessibility_criteria: | * pass [colour contrast](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html) * be readable should a [user change colours](https://support.mozilla.org/en-US/kb/change-fonts-and-colors-websites-use) * associate panel content with the control that opens it using the `aria-controls` attribute - * have `aria-label` / `aria-labelledby` on section content with a value that refers to the button that controls display of the content Section headings must use a button element so that users: @@ -63,7 +62,7 @@ examples: The `id` must be unique across the domain of your service. This is because the open or closed state of individual instances of the accordion uses `localStorage` to persist across page loads. - Used as an `id` in the HTML for the accordion as a whole, and also as a prefix for the `id`s of the section contents and the buttons that open them, so that those `id`s can be the target of `aria-labelledby` and `aria-control` attributes. + Used as an `id` in the HTML for the accordion as a whole, and also as a prefix for the `id`s of the section contents and the buttons that open them, so that those `id`s can be the target of `aria-control` attributes. data: id: with-supplied-id-thats-unique-across-the-domain items: diff --git a/app/views/govuk_publishing_components/components/docs/layout_for_admin.yml b/app/views/govuk_publishing_components/components/docs/layout_for_admin.yml index 24b6b974cd..40a2f2dee8 100644 --- a/app/views/govuk_publishing_components/components/docs/layout_for_admin.yml +++ b/app/views/govuk_publishing_components/components/docs/layout_for_admin.yml @@ -32,6 +32,15 @@ examples: js_filename: "application" block: | + with_custom_js_filename_for_es6_components: + description: An alternative JS filename can be used in place of the default `es6-components.js` if required (note that this cannot easily be demonstrated here). + data: + environment: production + product_name: Publishing + browser_title: 'A page title' + js_module_filename: "es6-bundle" + block: | + with_custom_css_filename: description: An alternative JS filename can be used in place of the default `application.scss` if required (note that this cannot easily be demonstrated here). data: diff --git a/app/views/govuk_publishing_components/components/layout_for_public/_header_logo.html.erb b/app/views/govuk_publishing_components/components/layout_for_public/_header_logo.html.erb new file mode 100644 index 0000000000..42fa29ef81 --- /dev/null +++ b/app/views/govuk_publishing_components/components/layout_for_public/_header_logo.html.erb @@ -0,0 +1,41 @@ +<% + hide_logo_text ||= false + large_navbar ||= false + logo_text ||= t("components.layout_super_navigation_header.logo_text") + logotype_classes = %w(govuk-header__logotype gem-c-layout-super-navigation-header__logotype-crown) + logotype_classes << "gem-c-layout-super-navigation-header__logotype-crown--large-navbar" if large_navbar +%> + +<% unless hide_logo_text %> + + GOV.UK + + +<% else %> + + <%= 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 %> 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,7 +41,7 @@ describe('Accordion component', function () { 'Writing well for specialists' + '' + '' + - '
' + + '
' + '

This is the content for Writing well for specialists.

' + '
' + '
' + diff --git a/yarn.lock b/yarn.lock index 1eca146b15..476a11ee66 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1347,10 +1347,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"