govuk_publishing_components 71.0.0 → 71.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/components/contents-list-with-body.js +96 -92
  3. data/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js +128 -57
  4. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/table-scroll.js +18 -19
  5. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_tables.scss +14 -38
  6. data/app/views/govuk_publishing_components/components/_metadata.html.erb +17 -2
  7. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +1 -0
  8. data/app/views/govuk_publishing_components/components/docs/metadata.yml +13 -1
  9. data/config/locales/ar.yml +1 -0
  10. data/config/locales/az.yml +1 -0
  11. data/config/locales/be.yml +1 -0
  12. data/config/locales/bg.yml +1 -0
  13. data/config/locales/bn.yml +1 -0
  14. data/config/locales/cs.yml +1 -0
  15. data/config/locales/cy.yml +1 -0
  16. data/config/locales/da.yml +1 -0
  17. data/config/locales/de.yml +1 -0
  18. data/config/locales/dr.yml +1 -0
  19. data/config/locales/el.yml +1 -0
  20. data/config/locales/en.yml +1 -0
  21. data/config/locales/es-419.yml +1 -0
  22. data/config/locales/es.yml +1 -0
  23. data/config/locales/et.yml +1 -0
  24. data/config/locales/fa.yml +1 -0
  25. data/config/locales/fi.yml +1 -0
  26. data/config/locales/fr.yml +1 -0
  27. data/config/locales/gd.yml +1 -0
  28. data/config/locales/gu.yml +1 -0
  29. data/config/locales/he.yml +1 -0
  30. data/config/locales/hi.yml +1 -0
  31. data/config/locales/hr.yml +1 -0
  32. data/config/locales/hu.yml +1 -0
  33. data/config/locales/hy.yml +1 -0
  34. data/config/locales/id.yml +1 -0
  35. data/config/locales/is.yml +1 -0
  36. data/config/locales/it.yml +1 -0
  37. data/config/locales/ja.yml +1 -0
  38. data/config/locales/ka.yml +1 -0
  39. data/config/locales/kk.yml +1 -0
  40. data/config/locales/ko.yml +1 -0
  41. data/config/locales/ku.yml +1 -0
  42. data/config/locales/ky.yml +1 -0
  43. data/config/locales/lt.yml +1 -0
  44. data/config/locales/lv.yml +1 -0
  45. data/config/locales/ms.yml +1 -0
  46. data/config/locales/mt.yml +1 -0
  47. data/config/locales/ne.yml +1 -0
  48. data/config/locales/nl.yml +1 -0
  49. data/config/locales/no.yml +1 -0
  50. data/config/locales/pa-pk.yml +1 -0
  51. data/config/locales/pa.yml +1 -0
  52. data/config/locales/pl.yml +1 -0
  53. data/config/locales/ps.yml +1 -0
  54. data/config/locales/pt.yml +1 -0
  55. data/config/locales/ro.yml +1 -0
  56. data/config/locales/ru.yml +1 -0
  57. data/config/locales/si.yml +1 -0
  58. data/config/locales/sk.yml +1 -0
  59. data/config/locales/sl.yml +1 -0
  60. data/config/locales/so.yml +1 -0
  61. data/config/locales/sq.yml +1 -0
  62. data/config/locales/sr.yml +1 -0
  63. data/config/locales/sv.yml +1 -0
  64. data/config/locales/sw.yml +1 -0
  65. data/config/locales/ta.yml +1 -0
  66. data/config/locales/th.yml +1 -0
  67. data/config/locales/ti.yml +1 -0
  68. data/config/locales/tk.yml +1 -0
  69. data/config/locales/tr.yml +1 -0
  70. data/config/locales/uk.yml +1 -0
  71. data/config/locales/ur.yml +1 -0
  72. data/config/locales/uz.yml +1 -0
  73. data/config/locales/vi.yml +1 -0
  74. data/config/locales/zh-hk.yml +1 -0
  75. data/config/locales/zh-tw.yml +1 -0
  76. data/config/locales/zh.yml +1 -0
  77. data/lib/govuk_publishing_components/presenters/machine_readable/has_part_schema.rb +1 -3
  78. data/lib/govuk_publishing_components/version.rb +1 -1
  79. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74db3ccfb835e4b5298212da9a2fbcdd6c6df533a174622e62ef8c09f838e163
4
- data.tar.gz: 6c8d9fba438b66e7f71191021547d009ffffff268061665ee7b3b7701888aef1
3
+ metadata.gz: b52ceb254eb609759602cb6bc0e2a6b5db708b5934acd2d533ce0c719da617fb
4
+ data.tar.gz: 6560960dcd97afd22c9a79035cd0342d711ec9495272eba304e7d4ec82a315ae
5
5
  SHA512:
6
- metadata.gz: 6a304e13a7a304c5851f17efc0e6920589401ebe9943f16837b0e548a3ca80d9f4468ddb6b3d5114506ab0cfd1cd90f34e619f01591f31df4420eddb4f6b22ad
7
- data.tar.gz: d0814535e7016e51788030010ad2cc7b6a490a138e81ccca427e3dc80cb9e143dfceb3792593571ec8c94da87ad536930b3cb55bf3542d3fdfc45a801b64aa9c
6
+ metadata.gz: d6cb5790d20ba98d55bc3a62481f468fc3b54eea9022c44dc9dbbf7d26571fc83a721c02fbcc7e3fbaa0f7298c4d493874e96a1254574a6c98652186f0fbba3f
7
+ data.tar.gz: 6ecbb506695215fb52444d463c8be8354906b4ee986059ed1929d98840c9d5501ea43918a692b9b78a83af990991ee1d899d8371778d0215624fbe2a9578659c
@@ -1,113 +1,117 @@
1
- /*
2
- This module will cause a child in the target element to:
3
- - hide when the top of the target element is visible;
4
- - stick to the bottom of the window while the parent element is in view;
5
- - stick to the bottom of the target when the user scrolls past the bottom.
6
-
7
- Use 'data-module="contents-list-with-body"' to instantiate, and add
8
- `[data-sticky-element]` to the child you want to position.
9
- */
10
-
1
+ /* global IntersectionObserver */
11
2
  (function (Modules) {
12
- function ContentsListWithBody (element) {
13
- this.wrapper = element
14
- this.stickyElement = this.wrapper.querySelector('[data-sticky-element]')
15
- this.hasResized = true
16
- this.hasScrolled = true
17
- this.interval = 50
18
- this.windowVerticalPosition = 1
19
- this.startPosition = 0
20
- this.stopPosition = 0
21
- }
3
+ class ContentsListWithBody {
4
+ /**
5
+ * @param {HTMLElement} $module
6
+ */
7
+ constructor ($module) {
8
+ /** @type {HTMLElement} */
9
+ this.$module = $module
22
10
 
23
- ContentsListWithBody.prototype.init = function () {
24
- if (!this.stickyElement) return
11
+ /** @type {HTMLElement | null} */
12
+ this.stickyElement = this.$module.querySelector('[data-sticky-element]')
25
13
 
26
- window.onresize = this.onResize.bind(this)
27
- window.onscroll = this.onScroll.bind(this)
28
- setInterval(this.checkResize.bind(this), this.interval)
29
- setInterval(this.checkScroll.bind(this), this.interval)
30
- this.checkResize()
31
- this.checkScroll()
32
- this.stickyElement.classList.add('gem-c-contents-list-with-body__sticky-element--enabled')
33
- }
14
+ /** @type {HTMLElement | null} */
15
+ this.topSentinel = this.$module.querySelector('.gem-c-contents-list-with-body__list-container')
34
16
 
35
- ContentsListWithBody.prototype.getWindowDimensions = function () {
36
- return {
37
- height: window.innerHeight,
38
- width: window.innerWidth
39
- }
40
- }
17
+ /** @type {HTMLDivElement | null} */
18
+ this.bottomSentinel = null
41
19
 
42
- ContentsListWithBody.prototype.getWindowPositions = function () {
43
- return {
44
- scrollTop: window.scrollY
45
- }
46
- }
20
+ /** @type {IntersectionObserver | null} */
21
+ this.topObserver = null
47
22
 
48
- ContentsListWithBody.prototype.onResize = function () {
49
- this.hasResized = true
50
- }
23
+ /** @type {IntersectionObserver | null} */
24
+ this.bottomObserver = null
51
25
 
52
- ContentsListWithBody.prototype.onScroll = function () {
53
- this.hasScrolled = true
54
- }
26
+ /** @type {string} */
27
+ this.enabledClass = 'gem-c-contents-list-with-body__sticky-element--enabled'
55
28
 
56
- ContentsListWithBody.prototype.checkResize = function () {
57
- if (this.hasResized) {
58
- this.hasResized = false
59
- this.hasScrolled = true
29
+ /** @type {string} */
30
+ this.stuckToWindowClass = 'gem-c-contents-list-with-body__sticky-element--stuck-to-window'
60
31
 
61
- var windowDimensions = this.getWindowDimensions()
62
- var elementHeight = this.wrapper.offsetHeight || parseFloat(this.wrapper.style.height.replace('px', ''))
63
- this.startPosition = this.wrapper.offsetTop
64
- this.stopPosition = this.wrapper.offsetTop + elementHeight - windowDimensions.height
32
+ /** @type {string} */
33
+ this.hiddenClass = 'gem-c-contents-list-with-body__sticky-element--hidden'
65
34
  }
66
- }
67
35
 
68
- ContentsListWithBody.prototype.checkScroll = function () {
69
- if (this.hasScrolled) {
70
- this.hasScrolled = false
36
+ /**
37
+ * Initialise the contents list with body component
38
+ */
39
+ init () {
40
+ if (!this.stickyElement || !this.topSentinel) return
71
41
 
72
- this.windowVerticalPosition = this.getWindowPositions().scrollTop
42
+ // Ensure the sticky element starts hidden before we check for intersection observer support
43
+ this.stickyElement.classList.add(this.hiddenClass)
73
44
 
74
- this.updateVisibility()
75
- this.updatePosition()
76
- }
77
- }
45
+ if (!('IntersectionObserver' in window)) {
46
+ return
47
+ }
78
48
 
79
- ContentsListWithBody.prototype.updateVisibility = function () {
80
- var isPastStart = this.startPosition < this.windowVerticalPosition
81
- if (isPastStart) {
82
- this.show()
83
- } else {
84
- this.hide()
49
+ this.stickyElement.classList.add(this.enabledClass)
50
+ this.createBottomSentinel(this.stickyElement)
51
+ this.setupObservers(this.stickyElement)
85
52
  }
86
- }
87
53
 
88
- ContentsListWithBody.prototype.updatePosition = function () {
89
- var isPastEnd = this.stopPosition < this.windowVerticalPosition
90
- if (isPastEnd) {
91
- this.stickToParent()
92
- } else {
93
- this.stickToWindow()
54
+ /**
55
+ * Create and insert a bottom sentinel tripwire onto the page before the sticky element.
56
+ * This is used to determine when the sticky element should be docked to the bottom of
57
+ * the parent container instead of sticking to the window.
58
+ *
59
+ * @param {HTMLElement} stickyElement
60
+ */
61
+ createBottomSentinel (stickyElement) {
62
+ const stickyElementParent = stickyElement.parentElement
63
+ if (!stickyElementParent) return
64
+
65
+ this.bottomSentinel = document.createElement('div')
66
+ this.bottomSentinel.className = 'gem-c-contents-list-with-body__bottom-sentinel'
67
+ this.bottomSentinel.setAttribute('aria-hidden', 'true')
68
+ this.bottomSentinel.style.height = '1px'
69
+ this.bottomSentinel.style.width = '100%'
70
+ this.bottomSentinel.style.pointerEvents = 'none'
71
+ this.bottomSentinel.style.visibility = 'hidden'
72
+
73
+ stickyElementParent.insertBefore(this.bottomSentinel, stickyElement)
94
74
  }
95
- }
96
-
97
- ContentsListWithBody.prototype.stickToWindow = function () {
98
- this.stickyElement.classList.add('gem-c-contents-list-with-body__sticky-element--stuck-to-window')
99
- }
100
75
 
101
- ContentsListWithBody.prototype.stickToParent = function () {
102
- this.stickyElement.classList.remove('gem-c-contents-list-with-body__sticky-element--stuck-to-window')
103
- }
104
-
105
- ContentsListWithBody.prototype.show = function () {
106
- this.stickyElement.classList.remove('gem-c-contents-list-with-body__sticky-element--hidden')
107
- }
108
-
109
- ContentsListWithBody.prototype.hide = function () {
110
- this.stickyElement.classList.add('gem-c-contents-list-with-body__sticky-element--hidden')
76
+ /**
77
+ * Set up IntersectionObservers to monitor top and bottom boundaries
78
+ *
79
+ * @param {HTMLElement} stickyElement
80
+ */
81
+ setupObservers (stickyElement) {
82
+ if (!this.topSentinel || !this.bottomSentinel) return
83
+
84
+ this.topObserver = new IntersectionObserver((entries) => {
85
+ entries.forEach((entry) => {
86
+ // Handle showing/hiding the sticky element based on the contents block position.
87
+ // !entry.isIntersecting: Element is completely outside the viewport
88
+ // entry.boundingClientRect.top < 0: Coordinates become negative when scrolled off the top of the screen
89
+ // Required for initial load (e.g. mobile with tall header content) where isIntersecting is false
90
+ // because the contents have not yet entered the viewport from below
91
+ const isPastContents = !entry.isIntersecting && entry.boundingClientRect.top < 0
92
+
93
+ isPastContents
94
+ ? stickyElement.classList.remove(this.hiddenClass)
95
+ : stickyElement.classList.add(this.hiddenClass)
96
+ })
97
+ })
98
+
99
+ this.bottomObserver = new IntersectionObserver((entries) => {
100
+ entries.forEach((entry) => {
101
+ // Handle sticking to the viewport or docking to the bottom of the parent container based on the bottom sentinel position.
102
+ // entry.boundingClientRect.top <= window.innerHeight: True when the sentinel has reached the bottom of the screen
103
+ // or scrolled past above it (e.g. deep into in the footer)
104
+ const isAtBottom = entry.boundingClientRect.top <= window.innerHeight
105
+
106
+ isAtBottom
107
+ ? stickyElement.classList.remove(this.stuckToWindowClass)
108
+ : stickyElement.classList.add(this.stuckToWindowClass)
109
+ })
110
+ })
111
+
112
+ this.topObserver.observe(this.topSentinel)
113
+ this.bottomObserver.observe(this.bottomSentinel)
114
+ }
111
115
  }
112
116
 
113
117
  Modules.ContentsListWithBody = ContentsListWithBody
@@ -1,68 +1,139 @@
1
- /* global XMLHttpRequest */
1
+ /* global fetch, DOMException, AbortController */
2
2
  (function (Modules) {
3
- function SinglePageNotificationButton ($module) {
4
- this.$module = $module
5
- this.basePath = this.$module.querySelector('input[name="base_path"]').value
6
- this.buttonLocation = this.$module.getAttribute('data-button-location')
7
- this.buttonVisibleClass = 'gem-c-single-page-notification-button--visible'
8
-
9
- this.personalisationEndpoint = '/api/personalisation/check-email-subscription?base_path=' + this.basePath
10
- // This attribute is passed through to the personalisation API to ensure the updated button has the same button_location for analytics
11
- if (this.buttonLocation) this.personalisationEndpoint += '&button_location=' + this.buttonLocation
12
- }
3
+ class SinglePageNotificationButton {
4
+ constructor ($module) {
5
+ /** @type {HTMLDivElement} */
6
+ this.$module = $module
7
+
8
+ /** @type {HTMLInputElement | null} */
9
+ this.basePathInput = this.$module.querySelector('input[name="base_path"]')
10
+
11
+ /** @type {HTMLButtonElement | null} */
12
+ this.button = this.$module.querySelector('.gem-c-button__outline--notification')
13
+
14
+ /** @type {string | null} */
15
+ this.buttonLocation = this.$module.getAttribute('data-button-location')
16
+
17
+ /** @type {string | null} */
18
+ this.customSubscribeText = this.$module.getAttribute('data-button-text-subscribe')
19
+
20
+ /** @type {string | null} */
21
+ this.customUnsubscribeText = this.$module.getAttribute('data-button-text-unsubscribe')
22
+
23
+ /** @type {string} */
24
+ this.buttonVisibleClass = 'gem-c-single-page-notification-button--visible'
25
+
26
+ /** @type {number | null} */
27
+ this.fetchRequestTimeoutId = null
28
+ }
13
29
 
14
- SinglePageNotificationButton.prototype.init = function () {
15
- var xhr = new XMLHttpRequest()
16
- xhr.open('GET', this.personalisationEndpoint, true)
17
- // if XHR to the personalisation endpoint is taking an incredibly long time to complete, we are better off leaving the button in its default unpersonalised state. Content changing before the user's eyes while they are browsing can be jarring and should be avoided.
18
- xhr.timeout = 10000
19
-
20
- xhr.ontimeout = function () {
21
- this.makeVisible(this.$module)
22
- }.bind(this)
23
-
24
- xhr.onreadystatechange = function () {
25
- if (xhr.readyState === 4) {
26
- if (xhr.status === 200) {
27
- var responseText = xhr.responseText
28
- // if response text exists and is JSON parse-able, parse the response and update the button html
29
- if (responseText && this.responseIsJSON(responseText)) {
30
- var active = JSON.parse(responseText).active
31
-
32
- var customSubscribeText = this.$module.getAttribute('data-button-text-subscribe')
33
- var customUnsubscribeText = this.$module.getAttribute('data-button-text-unsubscribe')
34
- // Only set custom button text if both text items are provided
35
- var customText = customSubscribeText && customUnsubscribeText
36
-
37
- // If response returns active, user has subscribed to notifications
38
- if (active === true) {
39
- if (customText) {
40
- this.$module.querySelector('.gem-c-button__outline--notification').textContent = customUnsubscribeText
41
- }
42
- } else {
43
- if (customText) {
44
- this.$module.querySelector('.gem-c-button__outline--notification').textContent = customSubscribeText
45
- }
46
- }
47
- }
30
+ /**
31
+ * Initialise the single page notification button
32
+ *
33
+ */
34
+ async init () {
35
+ try {
36
+ if (this.button === null) {
37
+ throw new Error('Button required')
48
38
  }
39
+
40
+ if (this.basePathInput === null) {
41
+ throw new Error('Base path required')
42
+ }
43
+
44
+ const personalisationEndpoint = this.getPersonalisationEndpoint(this.basePathInput.value, this.buttonLocation)
45
+ const personalisationData = await this.getPersonalisationData(personalisationEndpoint, 10000)
46
+ const customButtonText = this.getCustomButtonText(personalisationData.active, this.customSubscribeText, this.customUnsubscribeText)
47
+
48
+ if (customButtonText) {
49
+ this.button.textContent = customButtonText
50
+ }
51
+ } catch (error) {
52
+ console.error(error)
53
+ } finally {
49
54
  this.makeVisible(this.$module)
55
+ clearTimeout(this.fetchRequestTimeoutId)
50
56
  }
51
- }.bind(this)
52
- xhr.send()
53
- }
57
+ }
58
+
59
+ /**
60
+ * Get the personalisation data endpoint
61
+ *
62
+ * @param {string} basePath The base path to use
63
+ * @param {string | null} buttonLocation This attribute is passed through to the personalisation API to ensure the updated button has the same button_location for analytics
64
+ * @returns {string} The personalisation endpoint to use
65
+ */
66
+ getPersonalisationEndpoint (basePath, buttonLocation) {
67
+ const checkEmailSubscriptionEndpoint = '/api/personalisation/check-email-subscription'
54
68
 
55
- SinglePageNotificationButton.prototype.responseIsJSON = function (string) {
56
- try {
57
- JSON.parse(string)
58
- } catch (e) {
59
- return false
69
+ if (buttonLocation) {
70
+ return `${checkEmailSubscriptionEndpoint}?base_path=${basePath}&button_location=${buttonLocation}`
71
+ }
72
+
73
+ return `${checkEmailSubscriptionEndpoint}?base_path=${basePath}`
60
74
  }
61
- return true
62
- }
63
75
 
64
- SinglePageNotificationButton.prototype.makeVisible = function (target) {
65
- target.classList.add(this.buttonVisibleClass)
76
+ /**
77
+ * Fetch data from the personalisation endpoint for checking if an email subscription is active
78
+ *
79
+ * @param {string} personalisationEndpoint The personalisation URL to fetch data from
80
+ * @param {number} timer Set the time in milliseconds when the fetch request should abort
81
+ * @returns {Promise<EmailSubscriptionData>}
82
+ * @throws {DOMException} if the request times out
83
+ * @throws {Error} if the request response is not ok
84
+ */
85
+ async getPersonalisationData (personalisationEndpoint, timer) {
86
+ const abortController = new AbortController()
87
+ this.fetchRequestTimeoutId = setTimeout(() => abortController.abort(new DOMException('Timeout', 'AbortError')), timer)
88
+
89
+ const response = await fetch(personalisationEndpoint, {
90
+ headers: { Accept: 'application/json' },
91
+ signal: abortController.signal
92
+ })
93
+
94
+ if (!response.ok) {
95
+ throw new Error(`Response status: ${response.status}`)
96
+ }
97
+
98
+ return await response.json()
99
+ }
100
+
101
+ /**
102
+ * Make the single page notification button visible
103
+ *
104
+ * @param {HTMLDivElement} module The element to add the visible class to
105
+ */
106
+ makeVisible (module) {
107
+ module.classList.add(this.buttonVisibleClass)
108
+ }
109
+
110
+ /**
111
+ * Get custom button text depending on whether the email subscription is active
112
+ *
113
+ * @param {boolean} activeState If the user has an email subscription to the page
114
+ * @param {string} customSubscribeText The custom subscribe text used when the activeState is false
115
+ * @param {string} customUnsubscribeText The custom subscribe text used when the activeState is true
116
+ * @returns {string | undefined} Returns the custom button text to use or `undefined` if the custom button text cannot be determined
117
+ */
118
+ getCustomButtonText (activeState, customSubscribeText, customUnsubscribeText) {
119
+ if (typeof activeState !== 'boolean') return
120
+ // Only set custom button text if both text items are provided
121
+ if (!customSubscribeText || !customUnsubscribeText) {
122
+ return
123
+ }
124
+
125
+ if (activeState === true) return customUnsubscribeText
126
+ if (activeState === false) return customSubscribeText
127
+ }
66
128
  }
129
+
67
130
  Modules.SinglePageNotificationButton = SinglePageNotificationButton
68
131
  })(window.GOVUK.Modules)
132
+
133
+ /**
134
+ * @typedef {object} EmailSubscriptionData
135
+ * @property {string} base_path the base_path parameter
136
+ * @property {boolean} active whether the email subscription is active
137
+ *
138
+ * @see {@link https://docs.publishing.service.gov.uk/repos/account-api/api.html#get-apipersonalisationcheck-email-subscription}
139
+ */
@@ -1,3 +1,4 @@
1
+ /* global ResizeObserver */
1
2
  (function (GOVUK) {
2
3
  'use strict'
3
4
 
@@ -17,15 +18,26 @@
17
18
  this.windowResized()
18
19
  }, 10)
19
20
 
21
+ // for all browsers
20
22
  window.onresize = () => {
21
- if (this.windowResizeTimeout) {
22
- clearTimeout(this.windowResizeTimeout)
23
- }
23
+ this.detectSizeChange()
24
+ }
25
+
26
+ // for Firefox with 'zoom text only' (does not trigger onresize)
27
+ const resizeObserver = new ResizeObserver(() => {
28
+ this.detectSizeChange()
29
+ })
30
+ resizeObserver.observe(this.tables[0])
31
+ }
24
32
 
25
- this.windowResizeTimeout = setTimeout(function () {
26
- this.windowResized()
27
- }.bind(this), 500)
33
+ TableScroll.prototype.detectSizeChange = function () {
34
+ if (this.windowResizeTimeout) {
35
+ clearTimeout(this.windowResizeTimeout)
28
36
  }
37
+
38
+ this.windowResizeTimeout = setTimeout(function () {
39
+ this.windowResized()
40
+ }.bind(this), 300)
29
41
  }
30
42
 
31
43
  TableScroll.prototype.windowResized = function () {
@@ -63,7 +75,6 @@
63
75
  scrollBar.append(scrollBarChild)
64
76
  table.before(scrollBar)
65
77
  scrollBar.scrollLeft = table.scrollLeft
66
- this.updateLeftRight(table)
67
78
 
68
79
  scrollBar.onscroll = () => {
69
80
  if (this.preventScrolling) {
@@ -72,7 +83,6 @@
72
83
  }
73
84
  this.preventScrolling = true
74
85
  table.scrollLeft = scrollBar.scrollLeft
75
- this.updateLeftRight(table)
76
86
  }
77
87
 
78
88
  table.onscroll = () => {
@@ -82,21 +92,10 @@
82
92
  }
83
93
  this.preventScrolling = true
84
94
  scrollBar.scrollLeft = table.scrollLeft
85
- this.updateLeftRight(table)
86
95
  }
87
96
  })
88
97
  }
89
98
 
90
- TableScroll.prototype.updateLeftRight = function (table) {
91
- if ((table.scrollWidth - table.scrollLeft) < (table.offsetWidth + 1)) {
92
- table.parentElement.className = 'tablewrapper tablewrapper--active tablewrapper--end'
93
- } else if (table.scrollLeft < 1) {
94
- table.parentElement.className = 'tablewrapper tablewrapper--active tablewrapper--start'
95
- } else {
96
- table.parentElement.className = 'tablewrapper tablewrapper--active'
97
- }
98
- }
99
-
100
99
  TableScroll.prototype.destroyElements = function () {
101
100
  const scrollBars = this.element.querySelectorAll('.govspeak-table-scrollbar')
102
101
  scrollBars.forEach(bar => {
@@ -56,48 +56,24 @@
56
56
  }
57
57
 
58
58
  .tablewrapper {
59
- position: relative;
60
- }
61
-
62
- .tablewrapper--active {
63
- &::before,
64
- &::after {
65
- content: "";
66
- position: absolute;
67
- top: 24px;
68
- width: 10px;
69
- bottom: 20px;
70
- background: rgb(0, 0, 0, 0.1);
71
- border-color: $govuk-border-colour;
72
- border-width: 5px;
73
- }
74
-
75
- &::before {
76
- left: 0;
77
- border-left-style: solid;
78
- border-radius: 0 15px 15px 0;
79
- }
80
-
81
- &::after {
82
- right: 0;
83
- border-right-style: solid;
84
- border-radius: 15px 0 0 15px;
85
- }
86
- }
87
-
88
- .tablewrapper--start {
89
- &::before {
90
- display: none;
91
- }
92
- }
93
-
94
- .tablewrapper--end {
95
- &::after {
96
- display: none;
59
+ table {
60
+ background:
61
+ linear-gradient(90deg, govuk-functional-colour('body-background') 30%, rgb(255, 255, 255, 0)), // this covers the left
62
+ linear-gradient(90deg, rgb(255,255,255,0), govuk-functional-colour('body-background') 70%) 100% 100%, // this covers the right
63
+ linear-gradient(90deg, rgb(0, 0, 0, 0.2), rgb(255, 255, 255, 0)), // this should show when you can scroll left
64
+ linear-gradient(90deg, rgb(255, 255, 255, 0), rgb(0, 0, 0, 0.2)) 100% 100%; // this should show when you can scroll right
65
+ background-repeat: no-repeat;
66
+ background-color: govuk-functional-colour('body-background');
67
+ background-size: 50px 100%, 50px 100%, 14px 100%, 14px 100%;
68
+ background-attachment: local, local, scroll, scroll;
97
69
  }
98
70
  }
99
71
 
100
72
  .govspeak-table-scrollbar {
73
+ position: sticky;
74
+ background: govuk-functional-colour('body-background');
75
+ z-index: 1;
76
+ top: 0;
101
77
  overflow-x: scroll;
102
78
  overflow-y: hidden;
103
79
  height: 20px;
@@ -23,7 +23,6 @@
23
23
  component_helper.add_class("gem-c-metadata")
24
24
  component_helper.add_class("direction-#{direction}") if local_assigns.include?(:direction)
25
25
  component_helper.add_class("gem-c-metadata--border-top") if border_top
26
- component_helper.set_id("full-publication-update-history") if page_history.any?
27
26
 
28
27
  if inverse
29
28
  component_helper.add_class("gem-c-metadata--inverse")
@@ -38,6 +37,12 @@
38
37
  type: "content history",
39
38
  section: "Top",
40
39
  }.to_json unless disable_ga4
40
+ see_all_link_ga4_object = {
41
+ event_name: "navigation",
42
+ type: "content history",
43
+ section: "Top",
44
+ index_section: 1,
45
+ }.to_json unless disable_ga4
41
46
 
42
47
  render_component = true if from.any? || part_of.any? || history || first_published || last_updated || page_history.any? || other
43
48
  %>
@@ -78,6 +83,16 @@
78
83
  <dt class="gem-c-metadata__term"><%= t("components.metadata.last_updated") %>:</dt>
79
84
  <dd class="gem-c-metadata__definition">
80
85
  <%= last_updated %>
86
+ <% if local_assigns.include?(:see_updates_link) %>
87
+ &#8212;
88
+ <a href="#full-publication-update-history" class="govuk-!-display-none-print"
89
+ <% unless disable_ga4 %>
90
+ data-module="ga4-link-tracker"
91
+ data-ga4-link="<%= see_all_link_ga4_object %>"
92
+ <% end %>>
93
+ <%= t("components.metadata.see_all_updates") %>
94
+ </a>
95
+ <% end %>
81
96
  <% if page_history.any? %>
82
97
  <div class="gem-c-metadata__details-wrapper">
83
98
  <%= render "govuk_publishing_components/components/details", {
@@ -87,7 +102,7 @@
87
102
  ga4_attributes: page_history_details_ga4,
88
103
  disable_ga4: disable_ga4,
89
104
  } do %>
90
- <ol class="gem-c-metadata__change-history">
105
+ <ol class="gem-c-metadata__change-history" id="full-publication-update-history">
91
106
  <% page_history.each do |change| %>
92
107
  <li class="gem-c-metadata__change-history-item">
93
108
  <time class="gem-c-metadata__change-date" datetime="<%= change[:timestamp] %>"><%= change[:display_time] %></time>
@@ -1128,6 +1128,7 @@ examples:
1128
1128
  </tbody>
1129
1129
  </table>
1130
1130
  wide_table:
1131
+ description: Wide tables are enhanced with two features to help users navigate. Left/right indicators are added to show that more content is available to the sides, and a secondary scrollbar is added at the top of the table, that remains at the top of the page as the table is scrolled downwards. This allows users to scroll left/right at any point, which is useful where tables are taller than their browser.
1131
1132
  data:
1132
1133
  block: |
1133
1134
  <table>
@@ -26,10 +26,22 @@ examples:
26
26
  data:
27
27
  border_top: true
28
28
  from: <a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>
29
- published_and_updated:
29
+ published_and_last_updated:
30
30
  data:
31
31
  first_published: 14 June 2014
32
32
  last_updated: 10 September 2015
33
+ last_updated_and_link_to_see_details:
34
+ description: |
35
+ If a `last_updated` value exists and `see_updates_link` is set to true, a "See all updates" link will be shown.
36
+
37
+ The link's href will be set to `#full-publication-update-history` to match the ID of the page history displayed in a second metadata component at the bottom of the page (for example on [Set up a Driver CPC training centre](https://www.gov.uk/guidance/set-up-a-driver-cpc-training-centre)).
38
+
39
+ Clicking on this link will jump to the page history at the bottom of the page. Because the ID is contained within a details element, it will also automatically open that element so that the page history is visible.
40
+
41
+ On this component guide page, clicking the link will jump to the example below, and open the details element there.
42
+ data:
43
+ last_updated: 10 September 2015
44
+ see_updates_link: true
33
45
  display_page_history:
34
46
  description: |
35
47
  This will set up an expandable section on the page, with a top border, to let users toggle the display of the page history. It also includes a hidden H2 heading of 'Updates to this page'. This heading will not be included if one is passed to the component using the `title` option.
@@ -160,6 +160,7 @@ ar:
160
160
  last_updated: التحديث الأخير
161
161
  part_of: جزء من
162
162
  published: تاريخ النشر
163
+ see_all_updates: اطلع على كل التحديثات
163
164
  show_all_updates: إظهار كل التحديثات
164
165
  modal_dialogue:
165
166
  close_modal: إغلاق مربع الحوار المشروط
@@ -157,6 +157,7 @@ az:
157
157
  last_updated: Son yenilənmə
158
158
  part_of: Hissə
159
159
  published: Dərc edilib
160
+ see_all_updates: Bütün yeniləmələrə baxın
160
161
  show_all_updates: bütün yeniləmələri göstər
161
162
  modal_dialogue:
162
163
  close_modal: Modal dialoqu bağla