govuk_publishing_components 21.63.0 → 21.63.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,9 +9,4 @@ $(document).ready(function () {
9
9
  'use strict'
10
10
 
11
11
  window.GOVUK.modules.start()
12
-
13
- // Static has a Toggle module in here we have a GemToggle module, we can't
14
- // easily change govspeak to use GemToggle but we can use the GemToggle module
15
- var gemToggle = new window.GOVUK.Modules.GemToggle()
16
- gemToggle.start($('[data-module=toggle]'))
17
12
  })
@@ -1 +1,2 @@
1
+ // = require_tree ./vendor/polyfills/
1
2
  // = require_tree ./lib
@@ -1,15 +1,14 @@
1
- /* eslint-env jquery */
2
1
  /*
3
2
  Toggle the display of elements
4
3
 
5
- Use as follows:
4
+ Basic use:
6
5
 
7
6
  <div data-module="gem-toggle">
8
- <a href="#" data-controls="target" data-expanded="true">
9
- Show more
7
+ <a href="#" data-controls="target1" data-expanded="false">
8
+ Show/hide
10
9
  </a>
11
- <div id="target">
12
- Content to be toggled
10
+ <div id="target1" class="js-hidden">
11
+ Content hidden on page load
13
12
  </div>
14
13
  </div>
15
14
 
@@ -22,89 +21,151 @@
22
21
  the `js-hidden` class to the element you wish to hide in
23
22
  your template, the module will not do this for you.
24
23
 
25
- `data-controls` can contain more than one element, space
26
- separated.
27
-
28
24
  Use `data-toggle-class` on the parent element to set the
29
25
  class that is toggled. Defaults to `js-hidden`.
30
26
 
27
+ Content shown by default:
28
+
29
+ <div data-module="gem-toggle">
30
+ <a href="#" data-controls="target2" data-expanded="true">
31
+ Show/hide
32
+ </a>
33
+ <div id="target2">
34
+ Content shown on page load
35
+ </div>
36
+ </div>
37
+
38
+ Change text when clicked:
39
+
40
+ <div data-module="gem-toggle">
41
+ <a href="#" data-controls="target3" data-expanded="true" data-toggled-text="Show more">
42
+ Show less
43
+ </a>
44
+ <div id="target3">
45
+ Content shown on page load, toggle text changes depending on state
46
+ </div>
47
+ </div>
48
+
31
49
  Use `data-toggled-text` on the trigger element to set the
32
50
  text shown when the element is toggled. Defaults to not
33
51
  changing.
34
52
 
53
+ Show/hide multiple elements:
54
+
55
+ <div data-module="gem-toggle">
56
+ <a href="#" data-controls="target4 target5" data-expanded="false">
57
+ Show/hide
58
+ </a>
59
+ <div id="target4" class="js-hidden">
60
+ Content hidden on page load
61
+ </div>
62
+ <div id="target5" class="js-hidden">
63
+ Content hidden on page load
64
+ </div>
65
+ </div>
66
+
67
+ `data-controls` can contain more than one element, space
68
+ separated.
69
+
70
+ With tracking:
71
+
72
+ <div data-module="gem-toggle">
73
+ <a href="#" data-controls="target6" data-expanded="true" data-track-category="category" data-track-action="action" data-toggled-text="Show more">
74
+ Show less
75
+ </a>
76
+ <div id="target6">
77
+ Content shown on page load, tracked when expanded and collapsed
78
+ </div>
79
+ </div>
80
+
35
81
  Use `data-track-category` and `data-track-action` together
36
- to enable analytics on the element. The label will be
82
+ to enable analytics on the element. The track label will be
37
83
  determined based on the text present within the element
38
84
  at the time it was clicked.
39
85
  */
40
-
86
+ window.GOVUK = window.GOVUK || {}
41
87
  window.GOVUK.Modules = window.GOVUK.Modules || {};
42
88
 
43
89
  (function (Modules) {
44
- 'use strict'
45
-
46
- Modules.GemToggle = function () {
47
- this.start = function ($el) {
48
- var toggleSelector = '[data-controls][data-expanded]'
49
- var toggleClass = $el.attr('data-toggle-class') || 'js-hidden'
50
- var trackable = '[data-track-category][data-track-action]'
51
-
52
- $el.on('click', toggleSelector, toggle)
53
- $el.find(toggleSelector).each(addAriaAttrs)
54
-
55
- // Add the ARIA attributes with JavaScript
56
- // If the JS fails and there's no interactive elements, having
57
- // no aria attributes is an accurate representation.
58
- function addAriaAttrs () {
59
- var $toggle = $(this)
60
- $toggle.attr('role', 'button')
61
- $toggle.attr('aria-controls', $toggle.data('controls'))
62
- $toggle.attr('aria-expanded', $toggle.data('expanded'))
63
-
64
- var $targets = getTargetElements($toggle)
65
- $targets.attr('aria-live', 'polite')
66
- $targets.attr('role', 'region')
67
- $toggle.data('$targets', $targets)
68
- }
90
+ function GemToggle () { }
69
91
 
70
- function toggle (event) {
71
- var $toggle = $(event.target)
72
- var expanded = $toggle.attr('aria-expanded') === 'true'
73
- var $targets = $toggle.data('$targets')
74
-
75
- if (expanded) {
76
- $toggle.attr('aria-expanded', false)
77
- $targets.addClass(toggleClass)
78
- } else {
79
- $toggle.attr('aria-expanded', true)
80
- $targets.removeClass(toggleClass)
81
- }
92
+ GemToggle.prototype.start = function ($module) {
93
+ this.$module = $module[0]
94
+ this.$module.toggleTrigger = this.$module.querySelector('[data-controls][data-expanded]')
82
95
 
83
- var toggledText = $toggle.data('toggled-text')
84
- if (typeof toggledText === 'string') {
85
- $toggle.data('toggled-text', $toggle.text())
86
- $toggle.text(toggledText)
87
- }
96
+ if (this.$module.toggleTrigger) {
97
+ this.$module.toggleClass = this.$module.getAttribute('data-toggle-class') || 'js-hidden'
88
98
 
89
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent && $toggle.is(trackable)) {
90
- track($toggle)
91
- }
99
+ this.$module.isTrackable = this.$module.toggleTrigger.hasAttribute('data-track-category') && this.$module.toggleTrigger.hasAttribute('data-track-action')
92
100
 
93
- event.preventDefault()
101
+ if (this.$module.isTrackable) {
102
+ this.$module.trackCategory = this.$module.toggleTrigger.getAttribute('data-track-category')
103
+ this.$module.trackAction = this.$module.toggleTrigger.getAttribute('data-track-action')
94
104
  }
95
105
 
96
- function getTargetElements ($toggle) {
97
- var ids = $toggle.attr('aria-controls').split(' ')
98
- var selector = '#' + ids.join(', #')
106
+ this.addAriaAttrs()
107
+ this.toggleOnClick()
108
+ }
109
+ }
110
+
111
+ // Add the ARIA attributes with JavaScript
112
+ // If the JS fails and there's no interactive elements, having
113
+ // no aria attributes is an accurate representation.
114
+ GemToggle.prototype.addAriaAttrs = function () {
115
+ this.$module.toggleTrigger.setAttribute('role', 'button')
116
+ this.$module.toggleTrigger.setAttribute('aria-controls', this.$module.toggleTrigger.getAttribute('data-controls'))
117
+ this.$module.toggleTrigger.setAttribute('aria-expanded', this.$module.toggleTrigger.getAttribute('data-expanded'))
118
+ this.$module.targets = this.getTargetElements()
119
+
120
+ for (var i = 0; i < this.$module.targets.length; i++) {
121
+ this.$module.targets[i].setAttribute('aria-live', 'polite')
122
+ this.$module.targets[i].setAttribute('role', 'region')
123
+ }
124
+ }
99
125
 
100
- return $el.find(selector)
126
+ GemToggle.prototype.getTargetElements = function () {
127
+ var ids = this.$module.toggleTrigger.getAttribute('aria-controls').split(' ')
128
+ var selector = '#' + ids.join(', #')
129
+
130
+ return this.$module.querySelectorAll(selector)
131
+ }
132
+
133
+ GemToggle.prototype.toggleOnClick = function () {
134
+ var that = this
135
+
136
+ this.$module.toggleTrigger.addEventListener('click', function (event) {
137
+ event.preventDefault()
138
+ var expanded = this.getAttribute('aria-expanded') === 'true'
139
+
140
+ if (expanded) {
141
+ this.setAttribute('aria-expanded', false)
142
+ for (var i = 0; i < that.$module.targets.length; i++) {
143
+ that.$module.targets[i].classList.add(that.$module.toggleClass)
144
+ }
145
+ } else {
146
+ this.setAttribute('aria-expanded', true)
147
+ for (var j = 0; j < that.$module.targets.length; j++) {
148
+ that.$module.targets[j].classList.remove(that.$module.toggleClass)
149
+ }
101
150
  }
102
151
 
103
- function track ($toggle) {
104
- var options = { label: $toggle.data('toggled-text') || $toggle.text() }
152
+ var toggledText = this.getAttribute('data-toggled-text')
105
153
 
106
- window.GOVUK.analytics.trackEvent($toggle.data('track-category'), $toggle.data('track-action'), options)
154
+ if (typeof toggledText === 'string') {
155
+ this.setAttribute('data-toggled-text', this.innerText)
156
+ this.innerText = toggledText
107
157
  }
108
- }
158
+
159
+ if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent && that.$module.isTrackable) {
160
+ that.track()
161
+ }
162
+ })
109
163
  }
164
+
165
+ GemToggle.prototype.track = function () {
166
+ var options = { label: this.$module.toggleTrigger.getAttribute('data-toggled-text') || this.$module.toggleTrigger.innerText }
167
+ window.GOVUK.analytics.trackEvent(this.$module.trackCategory, this.$module.trackAction, options)
168
+ }
169
+
170
+ Modules.GemToggle = GemToggle
110
171
  })(window.GOVUK.Modules)
@@ -0,0 +1,23 @@
1
+ // https://plainjs.com/javascript/traversing/get-closest-element-by-selector-39/
2
+ // matches polyfill
3
+ this.Element && function(ElementPrototype) {
4
+ ElementPrototype.matches = ElementPrototype.matches ||
5
+ ElementPrototype.matchesSelector ||
6
+ ElementPrototype.webkitMatchesSelector ||
7
+ ElementPrototype.msMatchesSelector ||
8
+ function(selector) {
9
+ var node = this, nodes = (node.parentNode || node.document).querySelectorAll(selector), i = -1;
10
+ while (nodes[++i] && nodes[i] != node);
11
+ return !!nodes[i];
12
+ }
13
+ }(Element.prototype);
14
+
15
+ // closest polyfill
16
+ this.Element && function(ElementPrototype) {
17
+ ElementPrototype.closest = ElementPrototype.closest ||
18
+ function(selector) {
19
+ var el = this;
20
+ while (el.matches && !el.matches(selector)) el = el.parentNode;
21
+ return el.matches ? el : null;
22
+ }
23
+ }(Element.prototype);
@@ -0,0 +1,9 @@
1
+ // https://gist.github.com/heathcliff/7161329
2
+ if (!Array.prototype.indexOf) {
3
+ Array.prototype.indexOf = function(obj, start) {
4
+ for (var i = (start || 0), j = this.length; i < j; i++) {
5
+ if (this[i] === obj) { return i }
6
+ }
7
+ return -1
8
+ }
9
+ }
@@ -9,6 +9,12 @@
9
9
  @include govuk-font($size: 24, $weight: bold);
10
10
  }
11
11
 
12
- .gem-c-panel__prepend ~ .govuk-panel__title {
12
+ .gem-c-panel__prepend ~ .govuk-panel__title-text {
13
13
  margin-bottom: govuk-spacing(3);
14
14
  }
15
+
16
+ .gem-c-panel__append,
17
+ .gem-c-panel__prepend,
18
+ .govuk-panel__title-text {
19
+ display: block;
20
+ }
@@ -12,7 +12,10 @@
12
12
  <div class="component-markdown">
13
13
  <%= raw(@component_example.html_description) %>
14
14
  </div>
15
- <h2 class="component-doc-h2">How it looks</h2>
15
+ <h2 class="component-doc-h2">
16
+ How it looks
17
+ <small>(<a href="<%= component_preview_path(@component_doc.id, @component_example.id) %>" class="govuk-link">preview</a>)</small>
18
+ </h2>
16
19
  <%= render partial: "govuk_publishing_components/component_guide/component_doc/preview", locals: { component_doc: @component_doc, example: @component_example } %>
17
20
 
18
21
  <h2 class="component-doc-h2">How to call this example</h2>
@@ -29,7 +29,9 @@
29
29
  </div>
30
30
  </div>
31
31
 
32
- <h2 class="component-doc-h2">How it looks
32
+ <h2 class="component-doc-h2">
33
+ <a href="<%= component_example_path(@component_doc.id, "default") %>" class="govuk-link">How it looks</a>
34
+ <small>(<a href="<%= component_preview_path(@component_doc.id, "default") %>" class="govuk-link">preview</a>)</small>
33
35
  <small>(<a href="<%= component_preview_all_path(@component_doc.id) %>" class="govuk-link">preview all</a>)</small>
34
36
  </h2>
35
37
  <%= render "govuk_publishing_components/component_guide/component_doc/preview", component_doc: @component_doc, example: @component_doc.example %>
@@ -66,7 +66,7 @@
66
66
  </div>
67
67
 
68
68
  <div class="gem-c-cookie-banner__confirmation govuk-width-container" tabindex="-1">
69
- <p class="gem-c-cookie-banner__confirmation-message"><%= confirmation_message %></p>
69
+ <p class="gem-c-cookie-banner__confirmation-message" role="alert"><%= confirmation_message %></p>
70
70
  <button class="gem-c-cookie-banner__hide-button" data-hide-cookie-banner="true" data-module="track-click" data-track-category="cookieBanner" data-track-action="Hide cookie banner">Hide</button>
71
71
  </div>
72
72
  </div>
@@ -4,22 +4,24 @@
4
4
  append ||= false
5
5
  %>
6
6
  <div class="gem-c-panel govuk-panel govuk-panel--confirmation">
7
- <% if prepend %>
8
- <div class="gem-c-panel__prepend">
9
- <%= prepend %>
10
- </div>
11
- <% end %>
12
7
  <h2 class="govuk-panel__title">
13
- <%= title %>
8
+ <% if prepend %>
9
+ <span class="gem-c-panel__prepend">
10
+ <%= prepend %>
11
+ </span>
12
+ <% end %>
13
+ <span class="govuk-panel__title-text">
14
+ <%= title %>
15
+ </span>
16
+ <% if append %>
17
+ <span class="gem-c-panel__append">
18
+ <%= append %>
19
+ </span>
20
+ <% end %>
14
21
  </h2>
15
22
  <% if description %>
16
23
  <div class="govuk-panel__body">
17
24
  <%= description %>
18
25
  </div>
19
26
  <% end %>
20
- <% if append %>
21
- <div class="gem-c-panel__append">
22
- <%= append %>
23
- </div>
24
- <% end %>
25
27
  </div>
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "21.63.0".freeze
2
+ VERSION = "21.63.1".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.0
4
+ version: 21.63.1
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-21 00:00:00.000000000 Z
11
+ date: 2020-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -430,6 +430,8 @@ files:
430
430
  - app/assets/javascripts/govuk_publishing_components/vendor/json2.js
431
431
  - app/assets/javascripts/govuk_publishing_components/vendor/magna-charta.min.js
432
432
  - app/assets/javascripts/govuk_publishing_components/vendor/modernizr.js
433
+ - app/assets/javascripts/govuk_publishing_components/vendor/polyfills/closest.js
434
+ - app/assets/javascripts/govuk_publishing_components/vendor/polyfills/indexOf.js
433
435
  - app/assets/stylesheets/component_guide/application.scss
434
436
  - app/assets/stylesheets/component_guide/print.scss
435
437
  - app/assets/stylesheets/govuk_publishing_components/_all_components.scss