govuk_tech_docs 6.2.2 → 6.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ea5b48a595e28d761a1c50fcfb4533eeba24c00b5fcaa0dd2a00b03b46dc026
4
- data.tar.gz: 1e41564f09c3e49afd2683f68e99b58f00f31037527f04786e0ac98c728660c7
3
+ metadata.gz: 87a42820b4c7571de0db48c86a823c8510520cfd91e7504e33b82d503eaad139
4
+ data.tar.gz: 826755aa09f87263317723aead5ef82cd456b74863f5492c72eea512099d5737
5
5
  SHA512:
6
- metadata.gz: 6fd2247414abdada48e407277b7c03521f8810662bd0c6699ee8615363ab09b3a6e657a2a865dbc4d963fadf3763719f8d34de10b3074ef35ead7d949d471b91
7
- data.tar.gz: 0a580c8cf43aaecaa36281dda8adfa6687cd22589334f6cc43e1f0cbd7ccc58e28d322fe99adcc482d883df373dd5270425a02de778b0deec1865031decf2567
6
+ metadata.gz: e3e3f3da335130b1241dd526bc04bf17b9f14c6ed41aec60d4447b847ec6cb2e762a29983edcc4ee251e7adb944f5bd7f8331f147e3c3bd9cf5890867d50d552
7
+ data.tar.gz: 0512cb5a6002f61c3ec370e77d95b2c008001ebd2a1686f216d7b8cafe1cc97c1a13e40855d0a4eeba5ba27c1d983a743b9f1413a12d8ef263a4591785a19a9b
@@ -15,7 +15,7 @@ jobs:
15
15
  - name: 'Checkout Repository'
16
16
  uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17
17
  - name: 'Dependency Review'
18
- uses: actions/dependency-review-action@2031cfc080254a8a887f58cffee85186f0e49e48 #4.9.0
18
+ uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 #5.0.0
19
19
  with:
20
20
  # If it's a PR, use the target branch. If it's a push, use 'main'.
21
21
  base-ref: ${{ github.event.pull_request.base.ref || 'main' }}
@@ -20,7 +20,7 @@ jobs:
20
20
  with:
21
21
  show-progress: false
22
22
 
23
- - uses: ruby/setup-ruby@c4e5b1316158f92e3d49443a9d58b31d25ac0f8f # v1.306.0
23
+ - uses: ruby/setup-ruby@6aaa311d81eba98ae12eaffbcb63296ace0efcde # v1.307.0
24
24
  with:
25
25
  ruby-version: '3'
26
26
 
@@ -57,7 +57,7 @@ jobs:
57
57
  node-version-file: '.nvmrc'
58
58
  cache: 'npm'
59
59
 
60
- - uses: ruby/setup-ruby@c4e5b1316158f92e3d49443a9d58b31d25ac0f8f # v1.306.0
60
+ - uses: ruby/setup-ruby@6aaa311d81eba98ae12eaffbcb63296ace0efcde # v1.307.0
61
61
  with:
62
62
  ruby-version: '3'
63
63
  bundler-cache: true
@@ -26,7 +26,7 @@ jobs:
26
26
  node-version-file: '.nvmrc'
27
27
  cache: 'npm'
28
28
 
29
- - uses: ruby/setup-ruby@c4e5b1316158f92e3d49443a9d58b31d25ac0f8f # v1.306.0
29
+ - uses: ruby/setup-ruby@6aaa311d81eba98ae12eaffbcb63296ace0efcde # v1.307.0
30
30
  with:
31
31
  ruby-version: ${{ matrix.ruby }}
32
32
  bundler-cache: true
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 6.2.3
2
+
3
+ - [Fix TOC sidebar not scrolling to active item on page load](https://github.com/alphagov/tech-docs-gem/pull/480)
4
+
1
5
  ## 6.2.2
2
6
 
3
7
  - Update [govuk_tech_docs.gemspec](govuk_tech_docs.gemspec) to only run `npm` if `npm` is installed. Allows gem versions scans to complete properly.
@@ -2,13 +2,11 @@
2
2
  'use strict'
3
3
 
4
4
  Modules.InPageNavigation = function InPageNavigation () {
5
- var $tocPane
6
- var $contentPane
7
- var $tocItems
8
- var $targets
5
+ let $contentPane
6
+ let $tocItems
7
+ let $targets
9
8
 
10
9
  this.start = function start ($element) {
11
- $tocPane = $element.find('.app-pane__toc')
12
10
  $contentPane = $element.find('.app-pane__content')
13
11
  $tocItems = $('.js-toc-list').find('a')
14
12
  $targets = $contentPane.find('[id]')
@@ -29,7 +27,7 @@
29
27
  } else {
30
28
  // Store the initial position so that we can restore it even if we
31
29
  // never scroll.
32
- handleInitialLoadEvent()
30
+ window.requestAnimationFrame(handleInitialLoadEvent)
33
31
  }
34
32
  }
35
33
  }
@@ -41,7 +39,7 @@
41
39
  }
42
40
 
43
41
  function handleInitialLoadEvent () {
44
- var fragment = fragmentForTargetElement()
42
+ let fragment = fragmentForTargetElement()
45
43
 
46
44
  if (!fragment) {
47
45
  fragment = fragmentForFirstElementInView()
@@ -51,7 +49,7 @@
51
49
  }
52
50
 
53
51
  function handleScrollEvent () {
54
- var fragment = fragmentForFirstElementInView()
52
+ const fragment = fragmentForFirstElementInView()
55
53
 
56
54
  storeCurrentPositionInHistoryApi(fragment)
57
55
  highlightActiveItemInToc(fragment)
@@ -70,8 +68,8 @@
70
68
  function highlightActiveItemInToc (fragment) {
71
69
  // Navigation items for single page navigation don't necessarily include the path name, but
72
70
  // navigation items for multipage navigation items do include it. This checks for either case.
73
- var $activeTocItem = $tocItems.filter(function (_) {
74
- var url = new URL($(this).attr('href'), window.location.href)
71
+ let $activeTocItem = $tocItems.filter(function (_) {
72
+ const url = new URL($(this).attr('href'), window.location.href)
75
73
  return url.href === window.location.href
76
74
  })
77
75
 
@@ -79,35 +77,19 @@
79
77
  // Check to see if any nav items contain just the path name.
80
78
  if (!$activeTocItem.get(0)) {
81
79
  $activeTocItem = $tocItems.filter(function (_) {
82
- var url = new URL($(this).attr('href'), window.location.href)
80
+ const url = new URL($(this).attr('href'), window.location.href)
83
81
  return url.hash === '' && url.pathname === window.location.pathname
84
82
  })
85
83
  }
86
84
  if ($activeTocItem.get(0)) {
87
85
  $tocItems.removeClass('toc-link--in-view')
88
86
  $activeTocItem.addClass('toc-link--in-view')
89
- scrollTocToActiveItem($activeTocItem)
87
+ scrollTocToActiveItem($activeTocItem.get(0))
90
88
  }
91
89
  }
92
90
 
93
- function scrollTocToActiveItem ($activeTocItem) {
94
- var paneHeight = $tocPane.height()
95
- var linkTop = $activeTocItem.position().top
96
- var linkBottom = linkTop + $activeTocItem.outerHeight()
97
-
98
- var offset = null
99
-
100
- if (linkTop < 0) {
101
- offset = linkTop
102
- } else if (linkBottom >= paneHeight) {
103
- offset = -(paneHeight - linkBottom)
104
- } else {
105
- return
106
- }
107
-
108
- var newScrollTop = $tocPane.scrollTop() + offset
109
-
110
- $tocPane.scrollTop(newScrollTop)
91
+ function scrollTocToActiveItem (activeTocElement) {
92
+ activeTocElement.scrollIntoView({ block: 'nearest', inline: 'nearest' })
111
93
  }
112
94
 
113
95
  function fragmentForTargetElement () {
@@ -115,14 +97,14 @@
115
97
  }
116
98
 
117
99
  function fragmentForFirstElementInView () {
118
- var result = null
100
+ let result = null
119
101
 
120
102
  $($targets.get().reverse()).each(function checkIfInView (index) {
121
103
  if (result) {
122
104
  return
123
105
  }
124
106
 
125
- var $this = $(this)
107
+ const $this = $(this)
126
108
 
127
109
  if (Math.floor($this.position().top) <= 0) {
128
110
  result = $this
@@ -1,3 +1,3 @@
1
1
  module GovukTechDocs
2
- VERSION = "6.2.2".freeze
2
+ VERSION = "6.2.3".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_tech_docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.2
4
+ version: 6.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service