Skip to content

Commit

Permalink
Fixes some JS linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtrussler committed May 24, 2024
1 parent f125a8a commit 759d4f6
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions app/assets/javascripts/components/mainstream-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@

// Adds event listeners to set state of the "Show/Hide all" button when section buttons are clicked
MainstreamTable.prototype.setUpSections = function () {
this.sections.forEach(function(section) {
section.querySelector('.govuk-accordion__section-heading').addEventListener('click', function() {
if(section.classList.contains('govuk-accordion__section--expanded')) {
this.sections.forEach(function (section) {
section.querySelector('.govuk-accordion__section-heading').addEventListener('click', function () {
if (section.classList.contains('govuk-accordion__section--expanded')) {
this.openSections--

if (this.openSections == this.numSections - 1) {
if (this.openSections === this.numSections - 1) {
this.toggleShowAllControls()
}
} else {
this.openSections++

if (this.openSections == this.numSections) {
if (this.openSections === this.numSections) {
this.toggleShowAllControls()
}
}
Expand All @@ -43,7 +43,7 @@

// Toggles the "Show/Hide all" button
MainstreamTable.prototype.toggleShowAllControls = function () {
if (this.showAllControls.getAttribute('aria-expanded') == 'true') {
if (this.showAllControls.getAttribute('aria-expanded') === 'true') {
this.showAllControls.querySelector('.govuk-accordion__show-all-text').textContent = 'Show all'
this.showAllControls.querySelector('.govuk-accordion-nav__chevron').classList.remove('govuk-accordion-nav__chevron--up')
this.showAllControls.querySelector('.govuk-accordion-nav__chevron').classList.add('govuk-accordion-nav__chevron--down')
Expand All @@ -61,23 +61,23 @@
var sections = this.$module.querySelectorAll('.' + this.sectionClass)

// Open and close all sections
sections.forEach(function(section) {
sections.forEach(function (section) {
var button = section.querySelector('button')

if (section.classList.contains(this.sectionExpandedClass)) {
if (controlAllState == 'true') {
if (controlAllState === 'true') {
section.classList.remove(this.sectionExpandedClass)
section.querySelector('.' + this.sectionInnerContentClass).hidden = "until-found"
section.querySelector('.' + this.sectionInnerContentClass).hidden = 'until-found'
button.querySelector('.govuk-accordion-nav__chevron').classList.add('govuk-accordion-nav__chevron--down')
button.querySelector('.govuk-accordion-nav__chevron').classList.remove('govuk-accordion-nav__chevron--up')
button.querySelector('.govuk-accordion__section-toggle-text').textContent = 'Show'
button.setAttribute('aria-expanded', 'false')
this.openSections = 0
}
} else {
if (controlAllState == 'false') {
if (controlAllState === 'false') {
section.classList.add(this.sectionExpandedClass)
section.querySelector('.' + this.sectionInnerContentClass).hidden = ""
section.querySelector('.' + this.sectionInnerContentClass).hidden = ''
button.querySelector('.govuk-accordion-nav__chevron').classList.remove('govuk-accordion-nav__chevron--down')
button.querySelector('.govuk-accordion-nav__chevron').classList.add('govuk-accordion-nav__chevron--up')
button.querySelector('.govuk-accordion__section-toggle-text').textContent = 'Hide'
Expand Down

0 comments on commit 759d4f6

Please sign in to comment.