govuk_publishing_components 21.63.2 → 21.66.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/govuk_publishing_components/action-link-arrow--transparent.svg +1 -0
  3. data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +25 -7
  4. data/app/assets/javascripts/govuk_publishing_components/components/govspeak.js +17 -15
  5. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/barchart-enhancement.js +18 -11
  6. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js +423 -0
  7. data/app/assets/javascripts/govuk_publishing_components/lib/header-navigation.js +3 -1
  8. data/app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js +25 -20
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_action-link.scss +8 -2
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_input.scss +1 -0
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +9 -5
  12. data/app/views/govuk_publishing_components/components/_action_link.html.erb +2 -0
  13. data/app/views/govuk_publishing_components/components/_breadcrumbs.html.erb +1 -4
  14. data/app/views/govuk_publishing_components/components/_notice.html.erb +2 -1
  15. data/app/views/govuk_publishing_components/components/_radio.html.erb +3 -1
  16. data/app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb +2 -2
  17. data/app/views/govuk_publishing_components/components/docs/action_link.yml +8 -0
  18. data/app/views/govuk_publishing_components/components/docs/notice.yml +8 -0
  19. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_header.yml +3 -1
  20. data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +0 -1
  21. data/app/views/govuk_publishing_components/components/layout_header/_search.html.erb +1 -1
  22. data/lib/govuk_publishing_components/presenters/breadcrumbs.rb +0 -4
  23. data/lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_priority.rb +19 -5
  24. data/lib/govuk_publishing_components/presenters/contextual_navigation.rb +1 -1
  25. data/lib/govuk_publishing_components/version.rb +1 -1
  26. metadata +4 -3
  27. data/app/assets/javascripts/govuk_publishing_components/vendor/magna-charta.min.js +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fa84400a00cf38f8ec660c724a115fa819109586c041727b4a1833d0f2e4de4
4
- data.tar.gz: 48ef894dcfcc9e0dcc18a66ddc94e163f194647a604c6074bea21c6b8cccb33e
3
+ metadata.gz: 903043f0922348d52d8bd086a8450bc950b4cef41f9698981fbac4ff94e969e0
4
+ data.tar.gz: 68eec1602de4314d9072e1cc36d746f264477d07ca26ca10fa5e4b7053837694
5
5
  SHA512:
6
- metadata.gz: a3dabec965adb6f3020171d0baf9df7988fcbb7eae881374e7f8edefa98f169ea1765a2e553cfeb4364a25d4af24e6a42d0c0b67b709afa3302ded7271066507
7
- data.tar.gz: 3f78096a67b8811112e7c368b9ed66afcc4a759d7b2f466f512f6b1cb1a8598dcfaf9d9b4ef41ec22dea2af6900e05707524beaf38bdf7a60030df795016ba96
6
+ metadata.gz: 0e640b5131f343fac9d48ae517be2b5c5edcff7c90bd3599eabda72750c11535f9aafcf22c85e703097a547b487031f385815b6b9db427914432e4bd45aa4b3e
7
+ data.tar.gz: 6de32726b845f9a80c16bd782d9afa20d9e18f3bbe85af6823bed4d9a5b250e481d45504c3f28ab72b23de5263ea54e5a7de2a075e3b7e1efec985c7e34e2370
@@ -0,0 +1 @@
1
+ <svg width="39" height="39" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M17.01 6.818l-2.828 2.828 7.853 7.854-22 .066L0 21.5h22.035l-7.853 7.854 2.828 2.828L29.69 19.5zM39 19.5C39 30.27 30.27 39 19.5 39 9.373 39 1.05 31.28.092 21.405A19.737 19.737 0 010 19.5C0 8.73 8.73 0 19.5 0S39 8.73 39 19.5z" fill="#fff500"/></svg>
@@ -8,19 +8,23 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
8
8
 
9
9
  Modules.Feedback = function () {
10
10
  this.start = function ($element) {
11
+ this.element = $element[0]
12
+ this.somethingIsWrongForm = this.element.querySelector('#something-is-wrong')
13
+ this.surveyForm = this.element.querySelector('#page-is-not-useful')
11
14
  this.$prompt = $element.find('.js-prompt')
12
15
  this.$fields = $element.find('.gem-c-feedback__form-field')
13
16
  this.$forms = $element.find('.js-feedback-form')
14
17
  this.$toggleForms = $element.find('.js-toggle-form')
15
18
  this.$closeForms = $element.find('.js-close-form')
19
+ this.activeForm = false
16
20
  this.$activeForm = false
17
21
  this.$pageIsUsefulButton = $element.find('.js-page-is-useful')
18
22
  this.$pageIsNotUsefulButton = $element.find('.js-page-is-not-useful')
19
23
  this.$somethingIsWrongButton = $element.find('.js-something-is-wrong')
20
24
  this.$promptQuestions = $element.find('.js-prompt-questions')
21
25
  this.$promptSuccessMessage = $element.find('.js-prompt-success')
22
- this.$somethingIsWrongForm = $element.find('#something-is-wrong')
23
- this.$surveyForm = $element.find('#page-is-not-useful')
26
+ this.$somethingIsWrongForm = $(this.somethingIsWrongForm)
27
+ this.$surveyForm = $(this.surveyForm)
24
28
  this.$surveyWrapper = $element.find('#survey-wrapper')
25
29
 
26
30
  var that = this
@@ -103,12 +107,23 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
103
107
  function setHiddenValues () {
104
108
  that.$somethingIsWrongForm.append('<input type="hidden" name="javascript_enabled" value="true"/>')
105
109
  that.$somethingIsWrongForm.append($('<input type="hidden" name="referrer">').val(document.referrer || 'unknown'))
110
+ that.somethingIsWrongForm.invalidInfoError = [
111
+ '<h2>',
112
+ ' Sorry, we’re unable to send your message as you haven’t given us any information.',
113
+ '</h2>',
114
+ '<p>Please tell us what you were doing or what went wrong</p>'
115
+ ].join('')
106
116
  }
107
117
 
108
118
  function setHiddenValuesNotUsefulForm (gaClientId) {
109
119
  var currentPathName = window.location.pathname.replace(/[^\s=?&]+(?:@|%40)[^\s=?&]+/, '[email]')
110
120
  var finalPathName = encodeURI(currentPathName)
111
-
121
+ that.surveyForm.invalidInfoError = [
122
+ '<h2>',
123
+ ' Sorry, we’re unable to send your message as you haven’t given us a valid email address. ',
124
+ '</h2>',
125
+ '<p>Enter an email address in the correct format, like name@example.com</p>'
126
+ ].join('')
112
127
  if (document.querySelectorAll('[name="email_survey_signup[ga_client_id]"]').length === 0) {
113
128
  that.$surveyForm.append($('<input name="email_survey_signup[ga_client_id]" type="hidden">').val(gaClientId || '0'))
114
129
  }
@@ -124,7 +139,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
124
139
  }
125
140
 
126
141
  function toggleForm (formId) {
127
- that.$activeForm = $element.find('#' + formId)
142
+ that.activeForm = that.element.querySelector('#' + formId)
143
+ that.$activeForm = $(that.activeForm)
128
144
  that.$activeForm.toggleClass(jshiddenClass)
129
145
  that.$prompt.toggleClass(jshiddenClass)
130
146
 
@@ -158,18 +174,20 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
158
174
  '<p>If the problem persists, we have other ways for you to provide',
159
175
  ' feedback on the <a href="/contact/govuk">contact page</a>.</p>'
160
176
  ].join('')
161
-
162
177
  // if the response is not a 404 or 500, show the error message if it exists
163
178
  // otherwise show the generic message
164
- // this covers the 422 status the feedback application return for empty fields
165
- // for all other, show generic error
166
179
  if (typeof (error.responseJSON) !== 'undefined') {
167
180
  error = typeof (error.responseJSON.message) === 'undefined' ? genericError : error.responseJSON.message
168
181
 
169
182
  if (error === 'email survey sign up failure') {
170
183
  error = genericError
171
184
  }
185
+ } else if (error.status === 422) {
186
+ // there's clobbering by nginx on all 422 requests, which is why the response returns a rendered html page instead of the expected JSON
187
+ // this is a temporary workaround to ensure that are are displaying relevant error messages to the users
188
+ error = that.activeForm.invalidInfoError || genericError
172
189
  } else {
190
+ // for all other, show generic error
173
191
  error = genericError
174
192
  }
175
193
  var $errors = that.$activeForm.find('.js-errors')
@@ -2,25 +2,27 @@ window.GOVUK = window.GOVUK || {}
2
2
  window.GOVUK.Modules = window.GOVUK.Modules || {};
3
3
 
4
4
  (function (Modules) {
5
- 'use strict'
5
+ function Govspeak () { }
6
6
 
7
- Modules.Govspeak = function () {
8
- this.start = function ($element) {
9
- if (!$element.hasClass('disable-youtube')) {
10
- this.embedYoutube($element)
11
- }
7
+ Govspeak.prototype.start = function ($module) {
8
+ this.$module = $module[0]
12
9
 
13
- this.createBarcharts($element)
10
+ if (this.$module.className.indexOf('disable-youtube') === -1) {
11
+ this.embedYoutube()
14
12
  }
15
13
 
16
- this.embedYoutube = function ($jqElement) {
17
- var enhancement = new window.GOVUK.GovspeakYoutubeLinkEnhancement($jqElement[0])
18
- enhancement.init()
19
- }
14
+ this.createBarcharts()
15
+ }
20
16
 
21
- this.createBarcharts = function ($element) {
22
- var enhancement = new window.GOVUK.GovspeakBarchartEnhancement($element)
23
- enhancement.init()
24
- }
17
+ Govspeak.prototype.embedYoutube = function () {
18
+ var enhancement = new window.GOVUK.GovspeakYoutubeLinkEnhancement(this.$module)
19
+ enhancement.init()
25
20
  }
21
+
22
+ Govspeak.prototype.createBarcharts = function () {
23
+ var enhancement = new window.GOVUK.GovspeakBarchartEnhancement(this.$module)
24
+ enhancement.init()
25
+ }
26
+
27
+ Modules.Govspeak = Govspeak
26
28
  })(window.GOVUK.Modules)
@@ -1,4 +1,4 @@
1
- // = require govuk_publishing_components/vendor/magna-charta.min
1
+ // = require govuk_publishing_components/lib/govspeak/magna-charta
2
2
 
3
3
  window.GOVUK = window.GOVUK || {};
4
4
 
@@ -10,16 +10,23 @@ window.GOVUK = window.GOVUK || {};
10
10
  }
11
11
 
12
12
  BarchartEnhancement.prototype.init = function () {
13
- // the not selectors are protection against initialising twice since that
14
- // causes quite a mess. The not .mc-chart is because it creates a second
15
- // .js-barchart-table element with .mc-chart and then the
16
- // .js-barchart-table-init is given when we initialise
17
- var $barcharts = this.$element.find('.js-barchart-table:not(.mc-chart):not(.js-barchart-table-init)')
18
- $barcharts.each(function () {
19
- var $table = $(this)
20
- $.magnaCharta($table, { toggleText: 'Change between chart and table' })
21
- $table.addClass('js-barchart-table-init')
22
- })
13
+ var $barchartsOriginal = this.$element.querySelectorAll('.js-barchart-table')
14
+ var $barcharts = []
15
+
16
+ for (var j = 0; j < $barchartsOriginal.length; j++) {
17
+ // this prevents the code from initialising more than once
18
+ // we'd use :not selectors for $barchartsOriginal but for lack of IE8 support
19
+ var styles = $barchartsOriginal[j].className
20
+ if (styles.indexOf('mc-chart') === -1 && styles.indexOf('js-barchart-table-init') === -1) {
21
+ $barcharts.push($barchartsOriginal[j])
22
+ }
23
+ }
24
+
25
+ for (var i = 0; i < $barcharts.length; i++) {
26
+ var $table = $barcharts[i]
27
+ new GOVUK.Modules.MagnaCharta().start($table, { toggleText: 'Change between chart and table' })
28
+ $table.className = $table.className + ' js-barchart-table-init'
29
+ }
23
30
  }
24
31
 
25
32
  GOVUK.GovspeakBarchartEnhancement = BarchartEnhancement
@@ -0,0 +1,423 @@
1
+ //= require govuk/vendor/polyfills/Element/prototype/classList.js
2
+ // This is a non-jQuery version of Magna Charta: https://github.com/alphagov/magna-charta
3
+ window.GOVUK = window.GOVUK || {}
4
+ window.GOVUK.Modules = window.GOVUK.Modules || {};
5
+
6
+ (function (Modules) {
7
+ function MagnaCharta () { }
8
+
9
+ MagnaCharta.prototype.start = function ($module, options) {
10
+ this.$module = $module[0]
11
+ this.options = {
12
+ outOf: 65,
13
+ applyOnInit: true,
14
+ toggleText: 'Toggle between chart and table',
15
+ autoOutdent: false,
16
+ outdentAll: false,
17
+ toggleAfter: false, // BOOL set TRUE to append the toggle link
18
+ returnReference: false // for testing purposes
19
+ }
20
+
21
+ for (var k in options) this.options[k] = options[k]
22
+ this.detectIEVersion()
23
+
24
+ // Magna Charta doesn't work in IE7 or less - so plain tables are shown to those browsers
25
+ this.ENABLED = !(this.ie && this.ie < 8)
26
+
27
+ // store a reference to the table in the object
28
+ this.$table = $module
29
+
30
+ // lets make what will become the new graph
31
+ this.$graph = document.createElement('div')
32
+
33
+ // set the graph to aria-hidden, which isn't changed at any point
34
+ // the graph is totally inaccessible, so we let screen readers navigate the table
35
+ // and ignore the graph entirely
36
+ this.$graph.setAttribute('aria-hidden', 'true')
37
+
38
+ // copy over classes from the table, and add the extra one
39
+ this.$graph.setAttribute('class', this.$table.className)
40
+ this.$graph.classList.add('mc-chart')
41
+
42
+ // set the stacked option based on
43
+ // giving the table a class of mc-stacked
44
+ this.options.stacked = this.$table.classList.contains('mc-stacked')
45
+
46
+ // set the negative option based on
47
+ // giving the table a class of mc-negative
48
+ this.options.negative = this.$table.classList.contains('mc-negative')
49
+
50
+ // true if it's a 'multiple' table
51
+ // this means multiple bars per rows, but not stacked.
52
+ var moreThanTwoTDs = this.$table.querySelectorAll('tbody tr')[0].querySelectorAll('td').length > 2
53
+ this.options.multiple = !this.options.stacked && (this.$table.classList.contains('mc-multiple') || moreThanTwoTDs)
54
+
55
+ // set the outdent options
56
+ // which can be set via classes or overriden by setting the value to true
57
+ // in the initial options object that's passed in
58
+ this.options.autoOutdent = this.options.autoOutdent || this.$table.classList.contains('mc-auto-outdent')
59
+
60
+ this.options.outdentAll = this.options.outdentAll || this.$table.classList.contains('mc-outdented')
61
+
62
+ // add a mc-multiple class if it is
63
+ if (this.options.multiple) {
64
+ this.$graph.classList.add('mc-multiple')
65
+ }
66
+
67
+ this.options.hasCaption = !!this.$table.querySelectorAll('caption').length
68
+
69
+ if (this.ENABLED) {
70
+ this.apply()
71
+ // if applyOnInit is false, toggle immediately to show the table and hide the graph
72
+ if (!this.options.applyOnInit) {
73
+ this.toggleLink.click()
74
+ }
75
+ }
76
+
77
+ if (this.options.returnReference) {
78
+ return this
79
+ }
80
+ }
81
+
82
+ MagnaCharta.prototype.detectIEVersion = function () {
83
+ // detect IE version: James Padolsey, https://gist.github.com/527683
84
+ this.ie = (function () {
85
+ var undef
86
+ var v = 3
87
+ var div = document.createElement('div')
88
+ var all = div.getElementsByTagName('i')
89
+
90
+ do {
91
+ div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->'
92
+ } while (v < 10 && all[0])
93
+
94
+ return (v > 4) ? v : undef
95
+ })()
96
+ }
97
+
98
+ MagnaCharta.prototype.apply = function () {
99
+ if (this.ENABLED) {
100
+ this.constructChart()
101
+ this.addClassesToHeader()
102
+ this.applyWidths()
103
+ this.insert()
104
+ this.$table.classList.add('visually-hidden')
105
+ this.applyOutdent()
106
+ }
107
+ }
108
+
109
+ // methods for constructing the chart
110
+ MagnaCharta.prototype.construct = {}
111
+
112
+ // constructs the header
113
+ MagnaCharta.prototype.construct.thead = function () {
114
+ var thead = document.createElement('div')
115
+ thead.classList.add('mc-thead')
116
+
117
+ var tr = document.createElement('div')
118
+ tr.classList.add('mc-tr')
119
+
120
+ var output = ''
121
+ var allTheTHs = this.$table.querySelectorAll('th')
122
+
123
+ for (var i = 0; i < allTheTHs.length; i++) {
124
+ output += '<div class="mc-th">'
125
+ output += allTheTHs[i].innerHTML
126
+ output += '</div>'
127
+ }
128
+
129
+ tr.innerHTML = output
130
+ thead.appendChild(tr)
131
+
132
+ return thead
133
+ }
134
+
135
+ MagnaCharta.prototype.construct.tbody = function () {
136
+ var tbody = document.createElement('div')
137
+ tbody.classList.add('mc-tbody')
138
+
139
+ var allTheTbodyTrs = this.$table.querySelectorAll('tbody tr')
140
+
141
+ for (var i = 0; i < allTheTbodyTrs.length; i++) {
142
+ var tr = document.createElement('div')
143
+ tr.classList.add('mc-tr')
144
+
145
+ var cellsOutput = ''
146
+ var allTheTds = allTheTbodyTrs[i].querySelectorAll('td')
147
+
148
+ for (var j = 0; j < allTheTds.length; j++) {
149
+ cellsOutput += '<div class="mc-td">'
150
+ cellsOutput += allTheTds[j].innerHTML
151
+ cellsOutput += '</div>'
152
+ }
153
+ tr.innerHTML = cellsOutput
154
+ tbody.appendChild(tr)
155
+ }
156
+
157
+ return tbody
158
+ }
159
+
160
+ MagnaCharta.prototype.construct.caption = function () {
161
+ var cap = this.$table.querySelector('caption')
162
+ return cap.cloneNode(true)
163
+ }
164
+
165
+ // construct a link to allow the user to toggle between chart and table
166
+ MagnaCharta.prototype.construct.toggleLink = function (toggleText) {
167
+ var link = document.createElement('a')
168
+ link.setAttribute('href', '#')
169
+ link.classList.add('mc-toggle-link')
170
+ link.innerHTML = toggleText
171
+ link.setAttribute('aria-hidden', 'true')
172
+
173
+ return link
174
+ }
175
+
176
+ // toggles between showing the table and showing the chart
177
+ MagnaCharta.prototype.addToggleClick = function () {
178
+ var that = this
179
+
180
+ this.toggleLink.addEventListener('click', function (e) {
181
+ e.preventDefault()
182
+ that.$graph.classList.toggle('visually-hidden')
183
+ that.$table.classList.toggle('visually-hidden')
184
+ })
185
+ }
186
+
187
+ MagnaCharta.prototype.constructChart = function () {
188
+ // turn every element in the table into divs with appropriate classes
189
+ // call them and define this as scope so it's easier to
190
+ // get at options and properties
191
+ var thead = this.construct.thead.call(this)
192
+ var tbody = this.construct.tbody.call(this)
193
+ this.toggleLink = this.construct.toggleLink(this.options.toggleText)
194
+ this.addToggleClick(this.toggleLink)
195
+
196
+ if (this.options.hasCaption) {
197
+ var caption = this.construct.caption.call(this)
198
+ this.$graph.appendChild(caption)
199
+ }
200
+
201
+ if (this.options.toggleAfter) {
202
+ this.$table.insertAdjacentElement('afterend', this.toggleLink)
203
+ } else {
204
+ this.$table.insertAdjacentElement('beforebegin', this.toggleLink)
205
+ }
206
+
207
+ this.$graph.appendChild(thead)
208
+ this.$graph.appendChild(tbody)
209
+ }
210
+
211
+ // some handy utility methods
212
+ MagnaCharta.prototype.utils = {
213
+ isFloat: function (val) {
214
+ return !isNaN(parseFloat(val))
215
+ },
216
+ stripValue: function (val) {
217
+ var re = new RegExp('\\,|£|%|[a-z]', 'gi')
218
+ return val.replace(re, '')
219
+ },
220
+ returnMax: function (values) {
221
+ var max = 0
222
+ for (var i = 0; i < values.length; i++) {
223
+ if (values[i] > max) { max = values[i] }
224
+ }
225
+ return max
226
+ },
227
+ isNegative: function (value) {
228
+ return (value < 0)
229
+ }
230
+ }
231
+
232
+ MagnaCharta.prototype.addClassesToHeader = function () {
233
+ var headerCells = this.$graph.querySelectorAll('.mc-th')
234
+ var looplength = headerCells.length
235
+
236
+ if (this.options.stacked) {
237
+ var last = looplength - 1
238
+ headerCells[last].classList.add('mc-stacked-header', 'mc-header-total')
239
+ looplength -= 1
240
+ }
241
+
242
+ // we deliberately don't apply this to the first cell
243
+ for (var i = 1; i < looplength; i++) {
244
+ headerCells[i].classList.add('mc-key-header')
245
+ if (!headerCells[i].classList.contains('mc-stacked-header')) {
246
+ headerCells[i].classList.add('mc-key-' + i)
247
+ }
248
+ }
249
+ }
250
+
251
+ MagnaCharta.prototype.calculateMaxWidth = function () {
252
+ // store the cell values in here so we can figure out the maximum value later
253
+ var values = []
254
+
255
+ // var to store the maximum negative value (used only for negative charts)
256
+ var maxNegativeValue = 0
257
+
258
+ // loop through every tr in the table
259
+ var trs = this.$graph.querySelectorAll('.mc-tr')
260
+ for (var i = 0; i < trs.length; i++) {
261
+ var $this = trs[i]
262
+
263
+ // the first td is going to be the key, so ignore it
264
+ // we'd use $this.querySelectorAll('.mc-td:not(:first-child)') but for IE8
265
+ var $bodyCellsOriginal = $this.querySelectorAll('.mc-td')
266
+ var $bodyCells = []
267
+ for (var k = 1; k < $bodyCellsOriginal.length; k++) {
268
+ $bodyCells.push($bodyCellsOriginal[k])
269
+ }
270
+
271
+ var bodyCellsLength = $bodyCells.length
272
+
273
+ // might be the row containing th elements, so we need to check
274
+ if (bodyCellsLength) {
275
+ // if it's stacked, the last column is a totals
276
+ // so we don't want that in our calculations
277
+ if (this.options.stacked) {
278
+ $bodyCells[bodyCellsLength - 1].classList.add('mc-stacked-total')
279
+ bodyCellsLength -= 1
280
+ }
281
+
282
+ // first td in each row is key
283
+ var firstCell = $this.querySelector('.mc-td')
284
+ if (firstCell) {
285
+ firstCell.classList.add('mc-key-cell')
286
+ }
287
+
288
+ // store the total value of the bar cells in a row
289
+ // for anything but stacked, this is just the value of one <td>
290
+ var cellsTotalValue = 0
291
+
292
+ for (var j = 0; j < bodyCellsLength; j++) {
293
+ var $cell = $bodyCells[j]
294
+ $cell.classList.add('mc-bar-cell')
295
+ $cell.classList.add('mc-bar-' + (j + 1))
296
+ var cellVal = this.utils.stripValue($cell.innerText)
297
+
298
+ if (this.utils.isFloat(cellVal)) {
299
+ var parsedVal = parseFloat(cellVal, 10)
300
+ var absParsedVal = Math.abs(parsedVal)
301
+ if (parsedVal === 0) {
302
+ $cell.classList.add('mc-bar-zero')
303
+ }
304
+
305
+ if (this.options.negative) {
306
+ if (this.utils.isNegative(parsedVal)) {
307
+ $cell.classList.add('mc-bar-negative')
308
+ if (absParsedVal > maxNegativeValue) {
309
+ maxNegativeValue = absParsedVal
310
+ }
311
+ } else {
312
+ $cell.classList.add('mc-bar-positive')
313
+ }
314
+ }
315
+ // now we are done with our negative calculations
316
+ // set parsedVal to absParsedVal
317
+ parsedVal = absParsedVal
318
+
319
+ if (!this.options.stacked) {
320
+ cellsTotalValue = parsedVal
321
+ values.push(parsedVal)
322
+ } else {
323
+ cellsTotalValue += parsedVal
324
+ }
325
+ }
326
+ }
327
+ }
328
+
329
+ // if stacked, we need to push the total value of the row to the values array
330
+ if (this.options.stacked) { values.push(cellsTotalValue) }
331
+ }
332
+
333
+ var resp = {}
334
+ resp.max = parseFloat(this.utils.returnMax(values), 10)
335
+ resp.single = parseFloat(this.options.outOf / resp.max, 10)
336
+
337
+ if (this.options.negative) {
338
+ resp.marginLeft = parseFloat(maxNegativeValue, 10) * resp.single
339
+ resp.maxNegative = parseFloat(maxNegativeValue, 10)
340
+ }
341
+
342
+ return resp
343
+ }
344
+
345
+ MagnaCharta.prototype.applyWidths = function () {
346
+ this.dimensions = this.calculateMaxWidth()
347
+ var trs = this.$graph.querySelectorAll('.mc-tr')
348
+
349
+ for (var i = 0; i < trs.length; i++) {
350
+ var cells = trs[i].querySelectorAll('.mc-bar-cell')
351
+
352
+ for (var j = 0; j < cells.length; j++) {
353
+ var $cell = cells[j]
354
+ var parsedCellVal = parseFloat(this.utils.stripValue($cell.innerText), 10)
355
+ var parsedVal = parsedCellVal * this.dimensions.single
356
+ var absParsedCellVal = Math.abs(parsedCellVal)
357
+ var absParsedVal = Math.abs(parsedVal)
358
+
359
+ // apply the left margin to the positive bars
360
+ if (this.options.negative) {
361
+ if ($cell.classList.contains('mc-bar-positive')) {
362
+ $cell.style.marginLeft = this.dimensions.marginLeft + '%'
363
+ } else {
364
+ // if its negative but not the maximum negative
365
+ // we need to give it enough margin to push it further right to align
366
+ if (absParsedCellVal < this.dimensions.maxNegative) {
367
+ // left margin needs to be (largestNegVal - thisNegVal) * single
368
+ var leftMarg = (this.dimensions.maxNegative - absParsedCellVal) * this.dimensions.single
369
+ $cell.style.marginLeft = leftMarg + '%'
370
+ }
371
+ }
372
+ }
373
+
374
+ // wrap the cell value in a span tag
375
+ $cell.innerHTML = '<span>' + $cell.innerHTML + '</span>'
376
+ $cell.style.width = absParsedVal + '%'
377
+ }
378
+ }
379
+ }
380
+
381
+ MagnaCharta.prototype.insert = function () {
382
+ this.$table.insertAdjacentElement('afterend', this.$graph)
383
+ }
384
+
385
+ MagnaCharta.prototype.applyOutdent = function () {
386
+ /*
387
+ * this figures out if a cell needs an outdent and applies it
388
+ * it needs an outdent if the width of the text is greater than the width of the bar
389
+ * if this is the case, wrap the value in a span, and use absolute positioning
390
+ * to push it out (the bar is styled to be relative)
391
+ * unfortunately this has to be done once the chart has been inserted
392
+ */
393
+ var cells = this.$graph.querySelectorAll('.mc-bar-cell')
394
+
395
+ for (var i = 0; i < cells.length; i++) {
396
+ var $cell = cells[i]
397
+ var cellVal = parseFloat(this.utils.stripValue($cell.innerText), 10)
398
+ var $cellSpan = $cell.querySelector('span')
399
+ var spanWidth = parseFloat(window.getComputedStyle($cellSpan, null).width.replace('px', '')) + 10 // +10 just for extra padding
400
+ var cellWidth = parseFloat(window.getComputedStyle($cell, null).width.replace('px', ''))
401
+
402
+ if (!this.options.stacked) {
403
+ // if it's 0, it is effectively outdented
404
+ if (cellVal === 0) { $cell.classList.add('mc-bar-outdented') }
405
+
406
+ if ((this.options.autoOutdent && spanWidth > cellWidth) || this.options.outdentAll) {
407
+ $cell.classList.add('mc-bar-outdented')
408
+ $cellSpan.style.marginLeft = '100%'
409
+ $cellSpan.style.display = 'inline-block'
410
+ } else {
411
+ $cell.classList.add('mc-bar-indented')
412
+ }
413
+ } else {
414
+ // if it's a stacked graph
415
+ if (spanWidth > cellWidth && cellVal > 0) {
416
+ $cell.classList.add('mc-value-overflow')
417
+ }
418
+ }
419
+ }
420
+ }
421
+
422
+ Modules.MagnaCharta = MagnaCharta
423
+ })(window.GOVUK.Modules)
@@ -10,7 +10,7 @@
10
10
  for (i = 0, _i = els.length; i < _i; i++) {
11
11
  els[i].addEventListener('click', function (e) {
12
12
  e.preventDefault()
13
- var target = document.getElementById(this.getAttribute('href').substr(1))
13
+ var target = this.getAttribute('href') ? document.getElementById(this.getAttribute('href').substr(1)) : document.getElementById(this.getAttribute('data-search-toggle-for'))
14
14
  var targetClass = target.getAttribute('class') || ''
15
15
  var sourceClass = this.getAttribute('class') || ''
16
16
 
@@ -21,8 +21,10 @@
21
21
  }
22
22
  if (sourceClass.indexOf('js-visible') !== -1) {
23
23
  this.setAttribute('class', sourceClass.replace(/(^|\s)js-visible(\s|$)/, ''))
24
+ this.innerText = 'Show search'
24
25
  } else {
25
26
  this.setAttribute('class', sourceClass + ' js-visible')
27
+ this.innerText = 'Hide search'
26
28
  }
27
29
  this.setAttribute('aria-expanded', this.getAttribute('aria-expanded') !== 'true')
28
30
  target.setAttribute('aria-hidden', target.getAttribute('aria-hidden') === 'false')
@@ -1,36 +1,41 @@
1
+ //= require govuk/vendor/polyfills/Element/prototype/classList.js
1
2
  /*
2
3
  Toggle the class 'focus' on input boxes on element focus/blur
3
4
  Used by the search component but generic enough for reuse
4
5
  */
6
+ window.GOVUK = window.GOVUK || {}
5
7
  window.GOVUK.Modules = window.GOVUK.Modules || {};
6
8
 
7
9
  (function (Modules) {
8
- 'use strict'
10
+ function GemToggleInputClassOnFocus () { }
9
11
 
10
- Modules.GemToggleInputClassOnFocus = function () {
11
- this.start = function ($el) {
12
- var $toggleTarget = $el.find('.js-class-toggle')
12
+ GemToggleInputClassOnFocus.prototype.start = function ($module) {
13
+ this.$module = $module[0]
14
+ this.toggleTarget = this.$module.querySelector('.js-class-toggle')
15
+ this.$module.addFocusClass = this.addFocusClass.bind(this)
16
+ this.$module.removeFocusClassFromEmptyInput = this.removeFocusClassFromEmptyInput.bind(this)
13
17
 
14
- if (!inputIsEmpty()) {
15
- addFocusClass()
16
- }
18
+ if (!this.inputIsEmpty()) {
19
+ this.addFocusClass()
20
+ }
17
21
 
18
- $toggleTarget.on('focus', addFocusClass)
19
- $toggleTarget.on('blur', removeFocusClassFromEmptyInput)
22
+ this.toggleTarget.addEventListener('focus', this.$module.addFocusClass)
23
+ this.toggleTarget.addEventListener('blur', this.$module.removeFocusClassFromEmptyInput)
24
+ }
20
25
 
21
- function inputIsEmpty () {
22
- return $toggleTarget.val() === ''
23
- }
26
+ GemToggleInputClassOnFocus.prototype.inputIsEmpty = function () {
27
+ return this.toggleTarget.value === ''
28
+ }
24
29
 
25
- function addFocusClass () {
26
- $toggleTarget.addClass('focus')
27
- }
30
+ GemToggleInputClassOnFocus.prototype.addFocusClass = function () {
31
+ this.toggleTarget.classList.add('focus')
32
+ }
28
33
 
29
- function removeFocusClassFromEmptyInput () {
30
- if (inputIsEmpty()) {
31
- $toggleTarget.removeClass('focus')
32
- }
33
- }
34
+ GemToggleInputClassOnFocus.prototype.removeFocusClassFromEmptyInput = function () {
35
+ if (this.inputIsEmpty()) {
36
+ this.toggleTarget.classList.remove('focus')
34
37
  }
35
38
  }
39
+
40
+ Modules.GemToggleInputClassOnFocus = GemToggleInputClassOnFocus
36
41
  })(window.GOVUK.Modules)
@@ -4,13 +4,13 @@
4
4
  &:before {
5
5
  content: "";
6
6
  display: table-cell;
7
- width: 50px;
7
+ width: 60px;
8
8
  height: 45px;
9
9
  background: image-url("govuk_publishing_components/action-link-arrow.png");
10
10
  background: image-url("govuk_publishing_components/action-link-arrow.svg"), linear-gradient(transparent, transparent);
11
11
  background-repeat: no-repeat;
12
12
  background-position: 0 50%;
13
- background-size: 37px auto;
13
+ background-size: 45px auto;
14
14
  }
15
15
 
16
16
  @include govuk-media-query($until: tablet) {
@@ -141,6 +141,12 @@
141
141
  }
142
142
  }
143
143
 
144
+ .gem-c-action-link--transparent-icon {
145
+ &:before {
146
+ background-image: image-url("govuk_publishing_components/action-link-arrow--transparent.svg");
147
+ }
148
+ }
149
+
144
150
  .gem-c-action-link--nhs {
145
151
  &:before {
146
152
  width: 80px;
@@ -12,6 +12,7 @@
12
12
  margin: 0;
13
13
  min-width: 0;
14
14
  padding: govuk-spacing(1);
15
+ box-sizing: border-box;
15
16
 
16
17
  &.gem-c-input--search-icon {
17
18
  padding-left: govuk-spacing(6);
@@ -10,6 +10,7 @@ $large-input-size: 50px;
10
10
  @include govuk-font($size: 19, $line-height: $input-size);
11
11
  display: block;
12
12
  background: govuk-colour("white");
13
+ color: $govuk-text-colour;
13
14
 
14
15
  h1 {
15
16
  @include govuk-font($size: 19, $line-height: $input-size);
@@ -129,10 +130,6 @@ $large-input-size: 50px;
129
130
  }
130
131
 
131
132
  .gem-c-search--on-govuk-blue {
132
- .gem-c-search__label {
133
- color: govuk-colour("white");
134
- }
135
-
136
133
  .gem-c-search__input {
137
134
  border-width: 0;
138
135
 
@@ -216,11 +213,11 @@ $large-input-size: 50px;
216
213
  }
217
214
 
218
215
  .search-toggle {
216
+ display: none;
219
217
  background-color: govuk-colour("blue");
220
218
  background-image: image-url("govuk_publishing_components/search-button.png");
221
219
  background-position: 0 50%;
222
220
  background-repeat: no-repeat;
223
- display: block;
224
221
  float: right;
225
222
  height: 30px;
226
223
  margin: -46px 0;
@@ -228,6 +225,7 @@ $large-input-size: 50px;
228
225
  padding: 0;
229
226
  text-indent: -5000px;
230
227
  width: 36px;
228
+ border: 0;
231
229
 
232
230
  &:focus {
233
231
  border-width: 0;
@@ -253,4 +251,10 @@ $large-input-size: 50px;
253
251
  @include govuk-media-query($from: tablet) {
254
252
  display: none;
255
253
  }
254
+
255
+ @include govuk-media-query($until: tablet) {
256
+ .js-enabled & {
257
+ display: block;
258
+ }
259
+ }
256
260
  }
@@ -13,6 +13,7 @@
13
13
  dark_icon ||= false
14
14
  small_icon ||= false
15
15
  nhs_icon ||= false
16
+ transparent_icon ||= false
16
17
  data ||= nil
17
18
  classes ||= nil
18
19
 
@@ -20,6 +21,7 @@
20
21
  css_classes << "gem-c-action-link--light-text" if light_text
21
22
  css_classes << "gem-c-action-link--dark-icon" if dark_icon
22
23
  css_classes << "gem-c-action-link--small-icon" if small_icon
24
+ css_classes << "gem-c-action-link--transparent-icon" if transparent_icon
23
25
  css_classes << "gem-c-action-link--nhs" if nhs_icon
24
26
  css_classes << "gem-c-action-link--simple" if simple
25
27
  css_classes << "gem-c-action-link--with-subtext" if subtext
@@ -17,16 +17,13 @@
17
17
  <ol class="govuk-breadcrumbs__list">
18
18
  <% breadcrumbs.each_with_index do |crumb, index| %>
19
19
  <% breadcrumb = GovukPublishingComponents::Presenters::Breadcrumb.new(crumb, index) %>
20
- <li class="govuk-breadcrumbs__list-item" aria-current="<%= breadcrumb.aria_current %>">
20
+ <li class="govuk-breadcrumbs__list-item">
21
21
  <% if breadcrumb.is_link? %>
22
22
  <%= link_to(
23
23
  breadcrumb[:title],
24
24
  breadcrumb.path,
25
25
  data: breadcrumb.tracking_data(breadcrumbs.length),
26
26
  class: "govuk-breadcrumbs__link",
27
- aria: {
28
- current: breadcrumb.aria_current,
29
- }
30
27
  ) %>
31
28
  <% else %>
32
29
  <%= breadcrumb[:title] %>
@@ -4,6 +4,7 @@
4
4
  description_govspeak ||= false
5
5
  description ||= yield || false
6
6
  aria_live ||= false
7
+ lang = local_assigns[:lang].presence
7
8
  local_assigns[:margin_bottom] ||= 8
8
9
  local_assigns[:margin_bottom] = 8 if local_assigns[:margin_bottom] > 9
9
10
 
@@ -17,7 +18,7 @@
17
18
  description_present = description.present? || description_text.present? || description_govspeak.present?
18
19
  %>
19
20
  <% if title || description_present %>
20
- <%= tag.section class: css_classes, aria: aria_attributes, role: "region" do %>
21
+ <%= tag.section class: css_classes, aria: aria_attributes, lang: lang, role: "region" do %>
21
22
  <% if title %>
22
23
  <% if description_present %>
23
24
  <%= tag.h2 title, class: "gem-c-notice__title" %>
@@ -53,7 +53,9 @@
53
53
  <%= tag.h1 heading, class: "gem-c-radio__heading-text govuk-fieldset__heading" %>
54
54
  <% end %>
55
55
  <% else %>
56
- <%= tag.legend heading, class: legend_classes %>
56
+ <%= tag.legend class: legend_classes do %>
57
+ <%= tag.h2 heading, class: "govuk-fieldset__heading" %>
58
+ <% end %>
57
59
  <% end %>
58
60
  <% end %>
59
61
 
@@ -28,7 +28,7 @@
28
28
  <%= raw JSON.pretty_generate(breadcrumb_presenter.structured_data) %>
29
29
  </script>
30
30
 
31
- <div class="<%= classes %>" data-module="track-click">
31
+ <h2 class="<%= classes %>" data-module="track-click">
32
32
  <span class="gem-c-step-nav-header__part-of">Part of</span>
33
33
  <% if path %>
34
34
  <a href="<%= path %>"
@@ -51,5 +51,5 @@
51
51
  <%= title %>
52
52
  </span>
53
53
  <% end %>
54
- </div>
54
+ </h2>
55
55
  <% end %>
@@ -36,6 +36,14 @@ examples:
36
36
  light_text: true
37
37
  context:
38
38
  dark_background: true
39
+ with_transparent_svg:
40
+ data:
41
+ text: Find out what you need to do
42
+ href: "/page"
43
+ light_text: true
44
+ transparent_icon: true
45
+ context:
46
+ dark_background: true
39
47
  with_subtext:
40
48
  data:
41
49
  text: Emergency something
@@ -42,3 +42,11 @@ examples:
42
42
  title: 'Your settings have been saved'
43
43
  description_govspeak: <p>This is a confirmation message to tell you your settings have been saved</p>
44
44
  aria_live: true
45
+ with_locale:
46
+ description: |
47
+ Passing a lang value allows the content of the notice to be labelled as being a different language from surrounding content.
48
+ The lang attribute must be set to a [valid BCP47 string](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang#Language_tag_syntax). A valid code can be the two or three letter language code - for example, English is en or eng, Korean is ko or kor - but if in doubt please check.
49
+ data:
50
+ title: 'This publication was withdrawn on 30 September 2015'
51
+ description_govspeak: <p>This document is no longer current. We published a new version on 30 September 2015.</p>
52
+ lang: 'en'
@@ -3,7 +3,9 @@ description: Shows that a content page is part of a step by step navigation
3
3
  body: |
4
4
  The component indicates to the user that the current page is part of a [step by step navigation](/component-guide/step_by_step_nav), and can provide a link to it.
5
5
  accessibility_criteria: |
6
- The component is designed to go into the top of an existing content page and should not interfere with the heading structure of the page, so therefore should not contain a heading tag.
6
+ The component is designed to go into the top of an existing content page. This component looks like a heading so uses a heading level 2 element.
7
+
8
+ An earlier version of the component did not use a heading element &ndash; this failed WCAG 2.1 Success Criterion 1.3.1 ("Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text.")
7
9
 
8
10
  An early version of the component contained a hidden skip link for keyboard and screen reader users, that jumped to the step by step navigation component in the sidebar (similiar to the 'skip to content' link at the top of all GOV.UK pages). User testing suggested that rather than helping users it confused them, so this has been removed.
9
11
  shared_accessibility_criteria:
@@ -26,7 +26,6 @@
26
26
  'track-category' => 'yesNoFeedbackForm',
27
27
  'track-action' => 'ffYesClick'
28
28
  },
29
- 'aria-expanded': false,
30
29
  role: 'button',
31
30
  } do %>
32
31
  <%= t("components.feedback.yes", default: "Yes") %> <span class="govuk-visually-hidden"><%= t("components.feedback.is_useful", default: "this page is useful") %></span>
@@ -1,4 +1,4 @@
1
- <a href="#search" class="search-toggle js-header-toggle">Search</a>
1
+ <button class="search-toggle js-header-toggle" data-search-toggle-for="search">Show search</button>
2
2
  <form id="search" class="gem-c-layout-header__search-form govuk-clearfix" action="/search" method="get" role="search">
3
3
  <%= render "govuk_publishing_components/components/search", {
4
4
  id: "site-search-text",
@@ -49,10 +49,6 @@ module GovukPublishingComponents
49
49
  crumb[:url]
50
50
  end
51
51
 
52
- def aria_current
53
- "false"
54
- end
55
-
56
52
  def tracking_data(breadcrumbs_length)
57
53
  data = {
58
54
  track_category: "breadcrumbClicked",
@@ -12,18 +12,22 @@ module GovukPublishingComponents
12
12
  }.freeze
13
13
 
14
14
  # Returns the highest priority taxon that has a content_id matching those in PRIORITY_TAXONS
15
- def self.call(content_item)
16
- new(content_item).breadcrumbs
15
+ def self.call(content_item, query_parameters = nil)
16
+ new(content_item, query_parameters).breadcrumbs
17
17
  end
18
18
 
19
- attr_reader :content_item
19
+ attr_reader :content_item, :query_parameters
20
20
 
21
- def initialize(content_item)
21
+ def initialize(content_item, query_parameters = nil)
22
22
  @content_item = content_item
23
+ @query_parameters = query_parameters
23
24
  end
24
25
 
25
26
  def taxon
26
- @taxon ||= priority_taxons.min_by { |t| PRIORITY_TAXONS.values.index(t["content_id"]) }
27
+ @taxon ||= begin
28
+ default_taxon = priority_taxons.min_by { |t| PRIORITY_TAXONS.values.index(t["content_id"]) }
29
+ preferred_taxon || default_taxon
30
+ end
27
31
  end
28
32
 
29
33
  def breadcrumbs
@@ -39,6 +43,12 @@ module GovukPublishingComponents
39
43
 
40
44
  private
41
45
 
46
+ def preferred_taxon
47
+ if preferred_priority_taxon
48
+ priority_taxons.find { |t| t["content_id"] == preferred_priority_taxon }
49
+ end
50
+ end
51
+
42
52
  def priority_taxons
43
53
  return [] unless content_item["links"].is_a?(Hash)
44
54
 
@@ -57,6 +67,10 @@ module GovukPublishingComponents
57
67
  def priority_taxon?(taxon)
58
68
  PRIORITY_TAXONS.values.include?(taxon["content_id"])
59
69
  end
70
+
71
+ def preferred_priority_taxon
72
+ query_parameters["priority-taxon"] if query_parameters
73
+ end
60
74
  end
61
75
  end
62
76
  end
@@ -30,7 +30,7 @@ module GovukPublishingComponents
30
30
  end
31
31
 
32
32
  def priority_breadcrumbs
33
- @priority_breadcrumbs ||= ContentBreadcrumbsBasedOnPriority.call(content_item)
33
+ @priority_breadcrumbs ||= ContentBreadcrumbsBasedOnPriority.call(content_item, query_parameters)
34
34
  end
35
35
 
36
36
  def topic_breadcrumbs
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "21.63.2".freeze
2
+ VERSION = "21.66.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 21.63.2
4
+ version: 21.66.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-27 00:00:00.000000000 Z
11
+ date: 2020-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -320,6 +320,7 @@ files:
320
320
  - app/assets/images/govuk_publishing_components/action-link-arrow--dark.svg
321
321
  - app/assets/images/govuk_publishing_components/action-link-arrow--simple.png
322
322
  - app/assets/images/govuk_publishing_components/action-link-arrow--simple.svg
323
+ - app/assets/images/govuk_publishing_components/action-link-arrow--transparent.svg
323
324
  - app/assets/images/govuk_publishing_components/action-link-arrow.png
324
325
  - app/assets/images/govuk_publishing_components/action-link-arrow.svg
325
326
  - app/assets/images/govuk_publishing_components/chevron-banner/chevron-banner-small-focus.svg
@@ -419,6 +420,7 @@ files:
419
420
  - app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js
420
421
  - app/assets/javascripts/govuk_publishing_components/lib/current-location.js
421
422
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/barchart-enhancement.js
423
+ - app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js
422
424
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js
423
425
  - app/assets/javascripts/govuk_publishing_components/lib/header-navigation.js
424
426
  - app/assets/javascripts/govuk_publishing_components/lib/primary-links.js
@@ -428,7 +430,6 @@ files:
428
430
  - app/assets/javascripts/govuk_publishing_components/modules.js
429
431
  - app/assets/javascripts/govuk_publishing_components/vendor/html5shiv-printshiv.js
430
432
  - app/assets/javascripts/govuk_publishing_components/vendor/json2.js
431
- - app/assets/javascripts/govuk_publishing_components/vendor/magna-charta.min.js
432
433
  - app/assets/javascripts/govuk_publishing_components/vendor/modernizr.js
433
434
  - app/assets/javascripts/govuk_publishing_components/vendor/polyfills/closest.js
434
435
  - app/assets/javascripts/govuk_publishing_components/vendor/polyfills/indexOf.js
@@ -1,4 +0,0 @@
1
- /*! Magna Charta - v3.0.0 - 2012-12-04
2
- * https://github.com/alphagov/magna-charta
3
- */
4
- (function(e){var t=function(){this.init=function(t,n){var r={outOf:65,applyOnInit:!0,toggleText:"Toggle between chart and table",autoOutdent:!1,outdentAll:!1};this.options=e.extend({},r,n);var i=function(){var e,t=3,n=document.createElement("div"),r=n.getElementsByTagName("i");do n.innerHTML="<!--[if gt IE "+ ++t+"]><i></i><![endif]-->";while(t<10&&r[0]);return t>4?t:e}();return this.ENABLED=!(i&&i<8),this.$table=t,this.$graph=e("<div/>").attr("aria-hidden","true"),this.$graph.attr("class",this.$table.attr("class")).addClass("mc-chart"),this.options.stacked=this.$table.hasClass("mc-stacked"),this.options.negative=this.$table.hasClass("mc-negative"),this.options.multiple=!this.options.stacked&&(this.$table.hasClass("mc-multiple")||this.$table.find("tbody tr").first().find("td").length>2),this.options.autoOutdent=this.options.autoOutdent||this.$table.hasClass("mc-auto-outdent"),this.options.outdentAll=this.options.outdentAll||this.$table.hasClass("mc-outdented"),this.options.multiple&&this.$graph.addClass("mc-multiple"),this.options.hasCaption=!!this.$table.find("caption").length,this.ENABLED&&(this.apply(),this.options.applyOnInit||this.toggle()),this}};t.prototype.construct={},t.prototype.construct.thead=function(){var t=e("<div />",{"class":"mc-thead"}),n=e("<div />",{"class":"mc-tr"}),r="";return this.$table.find("th").each(function(t,n){r+='<div class="mc-th">',r+=e(n).html(),r+="</div>"}),n.append(r),t.append(n),t},t.prototype.construct.tbody=function(){var t=e("<div />",{"class":"mc-tbody"}),n="";return this.$table.find("tbody tr").each(function(n,r){var i=e("<div />",{"class":"mc-tr"}),s="";e(r).find("td").each(function(t,n){s+='<div class="mc-td">',s+=e(n).html(),s+="</div>"}),i.append(s),t.append(i)}),t},t.prototype.construct.caption=function(){var e=this.$table.find("caption");return e.clone()},t.prototype.construct.toggleLink=function(){var t=this;return e("<a />",{href:"#","class":"mc-toggle-link",text:this.options.toggleText}).on("click",function(e){t.toggle(e)})},t.prototype.constructChart=function(){var e=this.construct.thead.call(this),t=this.construct.tbody.call(this),n=this.construct.toggleLink.call(this);if(this.options.hasCaption){var r=this.construct.caption.call(this);this.$graph.append(r)}this.$table.before(n),this.$graph.append(e),this.$graph.append(t)},t.prototype.apply=function(){this.ENABLED&&(this.constructChart(),this.addClassesToHeader(),this.calculateMaxWidth(),this.applyWidths(),this.insert(),this.$table.addClass("visually-hidden"),this.applyOutdent())},t.prototype.toggle=function(e){this.$graph.toggle(),this.$table.toggleClass("visually-hidden"),e&&e.preventDefault()},t.prototype.utils={isFloat:function(e){return!isNaN(parseFloat(e))},stripValue:function(e){var t=new RegExp("\\,|£|%|[a-z]","gi");return e.replace(t,"")},returnMax:function(e){var t=0;for(var n=0;n<e.length;n++)e[n]>t&&(t=e[n]);return t},isNegative:function(e){return e<0}},t.prototype.addClassesToHeader=function(){var t=this.$graph.find(".mc-th").filter(":not(:first)");this.options.stacked&&(t.last().addClass("mc-stacked-header mc-header-total"),t=t.filter(":not(:last)")),t.addClass("mc-key-header").filter(":not(.mc-stacked-header)").each(function(t,n){e(n).addClass("mc-key-"+(t+1))})},t.prototype.calculateMaxWidth=function(){var t=this,n=[],r=0;this.$graph.find(".mc-tr").each(function(i,s){var o=e(s),u=o.find(".mc-td:not(:first)");if(t.options.stacked){var a=u.last().addClass("mc-stacked-total");u=u.filter(":not(:last)")}o.find(".mc-td:first").addClass("mc-key-cell");var f=0;u.each(function(i,s){var o=e(s).addClass("mc-bar-cell").addClass("mc-bar-"+(i+1)),u=t.utils.stripValue(o.text());if(t.utils.isFloat(u)){var a=parseFloat(u,10),l=Math.abs(a);a===0&&o.addClass("mc-bar-zero"),t.options.negative&&(t.utils.isNegative(a)?(o.addClass("mc-bar-negative"),l>r&&(r=l)):o.addClass("mc-bar-positive")),a=l,t.options.stacked?f+=a:(f=a,n.push(a))}}),t.options.stacked&&n.push(f)});var i={};return i.max=parseFloat(t.utils.returnMax(n),10),i.single=parseFloat(this.options.outOf/i.max,10),this.options.negative&&(i.marginLeft=parseFloat(r,10)*i.single,i.maxNegative=parseFloat(r,10)),i},t.prototype.applyWidths=function(){this.dimensions=this.calculateMaxWidth();var t=this;this.$graph.find(".mc-tr").each(function(n,r){var i=e(r),s=i.find(".mc-bar-cell:not(.mc-bar-zero)").length;i.find(".mc-bar-cell").each(function(n,r){var i=e(r),s=parseFloat(t.utils.stripValue(i.text()),10),o=s*t.dimensions.single,u=Math.abs(s),a=Math.abs(o);if(t.options.negative)if(i.hasClass("mc-bar-positive"))i.css("margin-left",t.dimensions.marginLeft+"%");else if(u<t.dimensions.maxNegative){var f=(t.dimensions.maxNegative-u)*t.dimensions.single;i.css("margin-left",f+"%")}i.wrapInner("<span />"),i.css("width",a+"%")})})},t.prototype.insert=function(){this.$table.after(this.$graph)},t.prototype.applyOutdent=function(){var t=this,n=this.$graph.find(".mc-bar-cell");this.$graph.find(".mc-bar-cell").each(function(n,r){var i=e(r),s=parseFloat(t.utils.stripValue(i.text()),10),o=i.children("span"),u=o.width()+10,a=i.width(),f=parseFloat(i[0].style.width,10),l=i.height();t.options.stacked?u>a&&s>0&&i.addClass("mc-value-overflow"):(s===0&&i.addClass("mc-bar-outdented"),t.options.autoOutdent&&u>a||t.options.outdentAll?(i.addClass("mc-bar-outdented"),o.css({"margin-left":"100%",display:"inline-block"})):i.addClass("mc-bar-indented"))})},e.magnaCharta=function(e,n){return(new t).init(e,n)}})(jQuery);