Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v4.1.0 (Feature release) #2630

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

## 4.1.0 (Feature release)

### New features

#### Import GOV.UK Frontend JavaScript as ECMAScript (ES) modules
Expand Down
2 changes: 1 addition & 1 deletion dist/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.1
4.1.0
3 changes: 0 additions & 3 deletions dist/govuk-frontend-4.0.1.min.css

This file was deleted.

3 changes: 3 additions & 0 deletions dist/govuk-frontend-4.1.0.min.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/govuk-frontend-ie8-4.0.1.min.css

This file was deleted.

1 change: 1 addition & 0 deletions dist/govuk-frontend-ie8-4.1.0.min.css

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions package/govuk-esm/all.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { nodeListForEach } from './common'
import Accordion from './components/accordion/accordion'
import Button from './components/button/button'
import Details from './components/details/details'
import CharacterCount from './components/character-count/character-count'
import Checkboxes from './components/checkboxes/checkboxes'
import ErrorSummary from './components/error-summary/error-summary'
import NotificationBanner from './components/notification-banner/notification-banner'
import Header from './components/header/header'
import Radios from './components/radios/radios'
import SkipLink from './components/skip-link/skip-link'
import Tabs from './components/tabs/tabs'

function initAll (options) {
// Set the options to an empty object by default if no options are passed.
options = typeof options !== 'undefined' ? options : {}

// Allow the user to initialise GOV.UK Frontend in only certain sections of the page
// Defaults to the entire document if nothing is set.
var scope = typeof options.scope !== 'undefined' ? options.scope : document

var $buttons = scope.querySelectorAll('[data-module="govuk-button"]')
nodeListForEach($buttons, function ($button) {
new Button($button).init()
})

var $accordions = scope.querySelectorAll('[data-module="govuk-accordion"]')
nodeListForEach($accordions, function ($accordion) {
new Accordion($accordion).init()
})

var $details = scope.querySelectorAll('[data-module="govuk-details"]')
nodeListForEach($details, function ($detail) {
new Details($detail).init()
})

var $characterCounts = scope.querySelectorAll('[data-module="govuk-character-count"]')
nodeListForEach($characterCounts, function ($characterCount) {
new CharacterCount($characterCount).init()
})

var $checkboxes = scope.querySelectorAll('[data-module="govuk-checkboxes"]')
nodeListForEach($checkboxes, function ($checkbox) {
new Checkboxes($checkbox).init()
})

// Find first error summary module to enhance.
var $errorSummary = scope.querySelector('[data-module="govuk-error-summary"]')
new ErrorSummary($errorSummary).init()

// Find first header module to enhance.
var $toggleButton = scope.querySelector('[data-module="govuk-header"]')
new Header($toggleButton).init()

var $notificationBanners = scope.querySelectorAll('[data-module="govuk-notification-banner"]')
nodeListForEach($notificationBanners, function ($notificationBanner) {
new NotificationBanner($notificationBanner).init()
})

var $radios = scope.querySelectorAll('[data-module="govuk-radios"]')
nodeListForEach($radios, function ($radio) {
new Radios($radio).init()
})

// Find first skip link module to enhance.
var $skipLink = scope.querySelector('[data-module="govuk-skip-link"]')
new SkipLink($skipLink).init()

var $tabs = scope.querySelectorAll('[data-module="govuk-tabs"]')
nodeListForEach($tabs, function ($tabs) {
new Tabs($tabs).init()
})
}

export {
initAll,
Accordion,
Button,
Details,
CharacterCount,
Checkboxes,
ErrorSummary,
Header,
NotificationBanner,
Radios,
SkipLink,
Tabs
}
28 changes: 28 additions & 0 deletions package/govuk-esm/common.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* TODO: Ideally this would be a NodeList.prototype.forEach polyfill
* This seems to fail in IE8, requires more investigation.
* See: https://github.com/imagitama/nodelist-foreach-polyfill
*/
export function nodeListForEach (nodes, callback) {
if (window.NodeList.prototype.forEach) {
return nodes.forEach(callback)
}
for (var i = 0; i < nodes.length; i++) {
callback.call(window, nodes[i], i, nodes)
}
}

// Used to generate a unique string, allows multiple instances of the component without
// Them conflicting with each other.
// https://stackoverflow.com/a/8809472
export function generateUniqueID () {
var d = new Date().getTime()
if (typeof window.performance !== 'undefined' && typeof window.performance.now === 'function') {
d += window.performance.now() // use high-precision timer if available
}
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0
d = Math.floor(d / 16)
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16)
})
}
Loading