forked from alphagov/govuk-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall.js
75 lines (63 loc) · 2.47 KB
/
all.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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 Header from './components/header/header'
import Radios from './components/radios/radios'
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
// Find all buttons with [role=button] on the scope to enhance.
new Button(scope).init()
// Find all global accordion components to enhance.
var $accordions = scope.querySelectorAll('[data-module="accordion"]')
nodeListForEach($accordions, function ($accordion) {
new Accordion($accordion).init()
})
// Find all global details elements to enhance.
var $details = scope.querySelectorAll('details')
nodeListForEach($details, function ($detail) {
new Details($detail).init()
})
var $characterCount = scope.querySelectorAll('[data-module="character-count"]')
nodeListForEach($characterCount, function ($characterCount) {
new CharacterCount($characterCount).init()
})
var $checkboxes = scope.querySelectorAll('[data-module="checkboxes"]')
nodeListForEach($checkboxes, function ($checkbox) {
new Checkboxes($checkbox).init()
})
// Find first error summary module to enhance.
var $errorSummary = scope.querySelector('[data-module="error-summary"]')
new ErrorSummary($errorSummary).init()
// Find first header module to enhance.
var $toggleButton = scope.querySelector('[data-module="header"]')
new Header($toggleButton).init()
var $radios = scope.querySelectorAll('[data-module="radios"]')
nodeListForEach($radios, function ($radio) {
new Radios($radio).init()
})
var $tabs = scope.querySelectorAll('[data-module="tabs"]')
nodeListForEach($tabs, function ($tabs) {
new Tabs($tabs).init()
})
}
export {
initAll,
Accordion,
Button,
Details,
CharacterCount,
Checkboxes,
ErrorSummary,
Header,
Radios,
Tabs
}