Skip to content

Commit

Permalink
Refactor JS export
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Aug 14, 2022
1 parent ea270f0 commit ee8fb10
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 62 deletions.
35 changes: 34 additions & 1 deletion x-govuk/all.js
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
module.exports = require('./components/all.js')
import Autocomplete from './components/autocomplete/autocomplete.js'
import Edge from './components/edge/edge.js'
import WarnOnUnsavedChanges from './components/warn-on-unsaved-changes/warn-on-unsaved-changes.js'

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

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

const $autocompletes = scope.querySelectorAll('[data-module="autocomplete"]')
$autocompletes.forEach(function ($autocomplete) {
new Autocomplete($autocomplete).init()
})

const $edges = scope.querySelectorAll('[data-module="edge"]')
$edges.forEach(function ($edge) {
new Edge($edge).init()
})

const $forms = scope.querySelectorAll('[data-module="warn-on-unsaved-changes"]')
$forms.forEach(function ($form) {
new WarnOnUnsavedChanges($form).init()
})
}

export {
initAll,
Autocomplete,
Edge,
WarnOnUnsavedChanges
}
61 changes: 0 additions & 61 deletions x-govuk/components/all.js

This file was deleted.

0 comments on commit ee8fb10

Please sign in to comment.