Skip to content

Commit

Permalink
Remove reliance on govuk-frontend for nodeListForEach
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanita Barrett committed Apr 5, 2022
1 parent 31a7c8c commit f5ce890
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/javascripts/application-ie8.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nodeListForEach } from 'govuk-frontend/govuk-esm/common'
import { nodeListForEach } from './components/helpers.js'
import Example from './components/example.js'
import AppTabs from './components/tabs.js'
import OptionsTable from './components/options-table.js'
Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CookieBanner from './components/cookie-banner.js'
import BackToTop from './components/back-to-top.js'
import { nodeListForEach } from 'govuk-frontend/govuk-esm/common'
import { nodeListForEach } from './components/helpers.js'
import Example from './components/example.js'
import AppTabs from './components/tabs.js'
import Copy from './components/copy.js'
Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/components/cookie-banner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as CookieFunctions from './cookie-functions.js'
import 'govuk-frontend/govuk/vendor/polyfills/Function/prototype/bind'
import 'govuk-frontend/govuk/vendor/polyfills/Event'
import { nodeListForEach } from 'govuk-frontend/govuk-esm/common'
import { nodeListForEach } from './helpers.js'

var cookieBannerAcceptSelector = '.js-cookie-banner-accept'
var cookieBannerRejectSelector = '.js-cookie-banner-reject'
Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/components/cookies-page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getConsentCookie, setConsentCookie } from './cookie-functions.js'
import { nodeListForEach } from 'govuk-frontend/govuk-esm/common'
import { nodeListForEach } from './helpers.js'

function CookiesPage ($module) {
this.$module = $module
Expand Down
12 changes: 12 additions & 0 deletions src/javascripts/components/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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)
}
}

export {
nodeListForEach
}
2 changes: 1 addition & 1 deletion src/javascripts/components/mobile-navigation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'govuk-frontend/govuk/vendor/polyfills/Element/prototype/classList'

import { nodeListForEach } from 'govuk-frontend/govuk-esm/common'
import { nodeListForEach } from './helpers.js'

var navActiveClass = 'app-mobile-nav--active'
var navTogglerActiveClass = 'app-header-mobile-nav-toggler--active'
Expand Down
4 changes: 1 addition & 3 deletions src/javascripts/components/tabs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'govuk-frontend/govuk/vendor/polyfills/Function/prototype/bind'
import 'govuk-frontend/govuk/vendor/polyfills/Element/prototype/classList'
import 'govuk-frontend/govuk/vendor/polyfills/Event'
import common from 'govuk-frontend/govuk/common'

var nodeListForEach = common.nodeListForEach
import { nodeListForEach } from './helpers.js'

var tabsItemClass = 'app-tabs__item'
var tabsItemCurrentClass = tabsItemClass + '--current'
Expand Down

0 comments on commit f5ce890

Please sign in to comment.