From bfe8efc91015763467fe6dd28f0fdea9349ea505 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Sun, 14 Aug 2022 12:44:27 +0100 Subject: [PATCH] Call element in parent function of the module --- x-govuk/components/all.js | 4 ++-- x-govuk/components/autocomplete/autocomplete.js | 4 ++-- x-govuk/components/edge/edge.js | 4 ++-- .../warn-on-unsaved-changes/warn-on-unsaved-changes.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/x-govuk/components/all.js b/x-govuk/components/all.js index d80ad1d..116cea7 100644 --- a/x-govuk/components/all.js +++ b/x-govuk/components/all.js @@ -42,8 +42,8 @@ module.exports = (function () { const started = element.dataset.moduleStarted if (typeof GOVUKPrototypeComponents[name] === 'function' && !started) { - module = new GOVUKPrototypeComponents[name]() - module.init(element) + module = new GOVUKPrototypeComponents[name](element) + module.init() element.dataset.moduleStarted = true } }) diff --git a/x-govuk/components/autocomplete/autocomplete.js b/x-govuk/components/autocomplete/autocomplete.js index 2f1d1db..9978b96 100644 --- a/x-govuk/components/autocomplete/autocomplete.js +++ b/x-govuk/components/autocomplete/autocomplete.js @@ -1,7 +1,7 @@ const accessibleAutocomplete = require('accessible-autocomplete') -module.exports = function () { - this.init = ($module) => { +module.exports = function ($module) { + this.init = () => { // Autocomplete options get passed from Nunjucks params to data attributes const params = $module.dataset diff --git a/x-govuk/components/edge/edge.js b/x-govuk/components/edge/edge.js index 0882e38..b1db793 100644 --- a/x-govuk/components/edge/edge.js +++ b/x-govuk/components/edge/edge.js @@ -1,7 +1,7 @@ const events = require('eventslibjs') -module.exports = function () { - this.init = ($module) => { +module.exports = function ($module) { + this.init = () => { const nodes = $module.querySelectorAll('a[href="#"]') nodes.forEach(node => { events.on('click', node, alertUser) }) diff --git a/x-govuk/components/warn-on-unsaved-changes/warn-on-unsaved-changes.js b/x-govuk/components/warn-on-unsaved-changes/warn-on-unsaved-changes.js index ebaab0f..2d65076 100644 --- a/x-govuk/components/warn-on-unsaved-changes/warn-on-unsaved-changes.js +++ b/x-govuk/components/warn-on-unsaved-changes/warn-on-unsaved-changes.js @@ -1,5 +1,5 @@ -module.exports = function () { - this.init = ($module) => { +module.exports = function ($module) { + this.init = () => { let hasChanged = false $module.addEventListener('submit', () => {