Skip to content

Commit

Permalink
Remove jquery from magna charta
Browse files Browse the repository at this point in the history
- includes some additional code to make it work in IE8, because it worked in IE8 with jquery
  • Loading branch information
andysellick committed Aug 27, 2020
1 parent d1e9f00 commit 8e673ef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ window.GOVUK = window.GOVUK || {};
}

BarchartEnhancement.prototype.init = function () {
// the not selectors are protection against initialising twice since that
// this is protection against initialising twice since that
// causes quite a mess. The not .mc-chart is because it creates a second
// .js-barchart-table element with .mc-chart and then the
// .js-barchart-table-init is given when we initialise
var $barcharts = this.$element.querySelectorAll('.js-barchart-table:not(.mc-chart):not(.js-barchart-table-init)')
// we'd use :not selectors but for IE8, previously worked before jquery removal
var $barchartsOriginal = this.$element.querySelectorAll('.js-barchart-table')
var $barcharts = []

for (var j = 0; j < $barchartsOriginal.length; j++) {
var styles = $barchartsOriginal[j].className
if (styles.indexOf('mc-chart') === -1 && styles.indexOf('js-barchart-table-init') === -1) {
$barcharts.push($barchartsOriginal[j])
}
}

for (var i = 0; i < $barcharts.length; i++) {
var $table = $barcharts[i]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Based on magna-charta: https://github.com/alphagov/magna-charta

// non-jquery version of magna-charta: https://github.com/alphagov/magna-charta
window.GOVUK = window.GOVUK || {}
window.GOVUK.Modules = window.GOVUK.Modules || {};

Expand Down Expand Up @@ -29,7 +28,11 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};

// lets make what will become the new graph
this.$graph = document.createElement('div')
this.$graph.setAttribute('aria-hidden', 'true') // FIXME this never gets updated

// set the graph to aria-hidden, which isn't changed at any point
// the graph is totally inaccessible, so we let screen readers navigate the table
// and ignore the graph entirely
this.$graph.setAttribute('aria-hidden', 'true')

// copy over classes from the table, and add the extra one
this.$graph.setAttribute('class', this.$table.className)
Expand Down Expand Up @@ -257,7 +260,13 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
var $this = trs[i]

// the first td is going to be the key, so ignore it
var $bodyCells = $this.querySelectorAll('.mc-td:not(:first-child)')
// we'd use $this.querySelectorAll('.mc-td:not(:first-child)') but for IE8
var $bodyCellsOriginal = $this.querySelectorAll('.mc-td')
var $bodyCells = []
for (var k = 1; k < $bodyCellsOriginal.length; k++) {
$bodyCells.push($bodyCellsOriginal[k])
}

var bodyCellsLength = $bodyCells.length

// might be the row containing th elements, so we need to check
Expand Down

0 comments on commit 8e673ef

Please sign in to comment.