govuk_tech_docs 6.6.0 → 6.6.0.2.rc

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: f5035007e52803cd8c363d3edb9edef4eb6d539af99ac7057a95620f4ca16af6
4
- data.tar.gz: caf5e336a81016120b725c7a2220c2b94296aa75cda9082952bfb934e06e68c7
3
+ metadata.gz: d6e328084d2f13b8f8e68129ba49e81d665d6ec8f72ee36124744b3d59ee2746
4
+ data.tar.gz: 677f49e76228b855545387d892f598e99dab171faf26f4bb4b57fb334ad02d39
5
5
  SHA512:
6
- metadata.gz: 9611da809f7c47179e93561f679e2fb130a6957bb6aa64ce26aa0baadcc125a2911f83d0c4ae9b48e78bc947155457d5e16599226cb1b8f710bf275a458babf6
7
- data.tar.gz: 0a209c6d34f05bce7bd71ee769bc212ebbca961cdbe5e1f586b1aa95fa79f772142cc68c8c5c5dc24dd0bf7330b31b43d149030916675714d09efecb8d83dfd5
6
+ metadata.gz: 4e027b5f33816e9e0e892acb272bd70326d761fda26c3b3d92b7f56a085d5bebf81060e60d1bf31f12580c23dc5f1f87bb4c13ead563189f2c2650309c67f16c
7
+ data.tar.gz: 2df2a47ac7fc68b6231ff86abaef8c229c1ffac8bf9ef71980e6a1997f8d433492fa9ff6034f654f37288d04122c6c64a7b68596c5dcc7a25d7251acca262b12
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## Unreleased changes
2
2
 
3
+ ## 6.6.0.2.rc
4
+ - Fix missing top-level pages in multipage navigation when a custom `http_prefix` is configured ([issue 488](https://github.com/alphagov/tech-docs-gem/issues/488)).
5
+
6
+ ## 6.6.0.1
7
+
8
+ - Fix sticky TOC fighting page scroll: keep the active nav item visible by scrolling only the sidebar pane, not the window, so a long table of contents no longer blocks reaching the footer
9
+ - Keep the sidebar divider running down to the footer when the page is shorter than the table of contents
10
+ - Fix desktop sidebar scrolling after the `.app-pane` wrapper was removed: keep the table of contents sticky and independently scrollable while the page (and full-width footer) scroll normally ([related to pull request 513](https://github.com/alphagov/tech-docs-gem/pull/513))
11
+
3
12
  ## 6.6.0
4
13
 
5
14
  - Use GOV.UK front end to `6.6.0`
@@ -14,6 +14,9 @@
14
14
  // Attach collapsible heading functionality,on mobile and desktop
15
15
  collapsibleHeadings()
16
16
  openActiveHeading()
17
+ // Page scroll is on the window (sticky TOC layout); keep listening in case
18
+ // a consumer still scrolls .app-pane__content independently.
19
+ $(window).on('scroll', _.debounce(openActiveHeading, 100, { maxWait: 100 }))
17
20
  $contentPane.on('scroll', _.debounce(openActiveHeading, 100, { maxWait: 100 }))
18
21
  }
19
22
 
@@ -11,7 +11,9 @@
11
11
  $tocItems = $('.js-toc-list').find('a')
12
12
  $targets = $contentPane.find('[id]')
13
13
 
14
- $contentPane.on('scroll', _.debounce(handleScrollEvent, 100, { maxWait: 100 }))
14
+ // Scroll happens on the window now that the layout no longer uses a
15
+ // viewport-locked .app-pane with overflow scrolling on .app-pane__content.
16
+ $(window).on('scroll', _.debounce(handleScrollEvent, 100, { maxWait: 100 }))
15
17
 
16
18
  if (Modernizr.history) {
17
19
  // Popstate is triggered when using the back button to navigate 'within'
@@ -34,7 +36,7 @@
34
36
 
35
37
  function restoreScrollPosition (state) {
36
38
  if (state && typeof state.scrollTop !== 'undefined') {
37
- $contentPane.scrollTop(state.scrollTop)
39
+ window.scrollTo(0, state.scrollTop)
38
40
  }
39
41
  }
40
42
 
@@ -58,7 +60,7 @@
58
60
  function storeCurrentPositionInHistoryApi (fragment) {
59
61
  if (Modernizr.history && fragment) {
60
62
  history.replaceState(
61
- { scrollTop: $contentPane.scrollTop() },
63
+ { scrollTop: window.scrollY || window.pageYOffset },
62
64
  '',
63
65
  fragment
64
66
  )
@@ -88,8 +90,37 @@
88
90
  }
89
91
  }
90
92
 
93
+ // Scroll only within the sticky TOC pane. Avoid Element.scrollIntoView —
94
+ // it can also scroll the window, which fights page scroll toward the footer
95
+ // when the sticky sidebar is leaving the viewport.
91
96
  function scrollTocToActiveItem (activeTocElement) {
92
- activeTocElement.scrollIntoView({ block: 'nearest', inline: 'nearest' })
97
+ const scrollParent = getScrollableAncestor(activeTocElement)
98
+ if (!scrollParent) {
99
+ return
100
+ }
101
+
102
+ const parentRect = scrollParent.getBoundingClientRect()
103
+ const elementRect = activeTocElement.getBoundingClientRect()
104
+
105
+ if (elementRect.top < parentRect.top) {
106
+ scrollParent.scrollTop -= parentRect.top - elementRect.top
107
+ } else if (elementRect.bottom > parentRect.bottom) {
108
+ scrollParent.scrollTop += elementRect.bottom - parentRect.bottom
109
+ }
110
+ }
111
+
112
+ function getScrollableAncestor (element) {
113
+ let parent = element.parentElement
114
+
115
+ while (parent && parent !== document.body && parent !== document.documentElement) {
116
+ const overflowY = window.getComputedStyle(parent).overflowY
117
+ if (overflowY === 'auto' || overflowY === 'scroll') {
118
+ return parent
119
+ }
120
+ parent = parent.parentElement
121
+ }
122
+
123
+ return null
93
124
  }
94
125
 
95
126
  function fragmentForTargetElement () {
@@ -106,7 +137,7 @@
106
137
 
107
138
  const $this = $(this)
108
139
 
109
- if (Math.floor($this.position().top) <= 0) {
140
+ if (Math.floor($this[0].getBoundingClientRect().top) <= 0) {
110
141
  result = $this
111
142
  }
112
143
  })
@@ -2,49 +2,36 @@
2
2
  $toc-width: 330px;
3
3
 
4
4
  .flexbox, .flexboxtweener {
5
-
6
- body {
7
- overflow: hidden;
8
- }
9
-
10
- .app-pane {
11
- display: flex;
12
- flex-direction: column;
13
- overflow: hidden;
14
- height: 100vh;
15
- }
16
-
17
- .app-pane__header {
18
- display: flex;
19
- flex-direction: column;
20
- flex: 1 0 auto;
21
-
22
- > * {
23
- flex: 1 0 auto;
24
- }
25
- }
26
-
5
+ // Document scroll (not a locked viewport pane) so the full-width footer can
6
+ // sit after the content and scroll into view. The TOC stays visible via
7
+ // position: sticky and scrolls independently when taller than the viewport.
27
8
  .app-pane__body {
28
9
  display: flex;
29
- flex: 1 1 100%;
30
- min-height: 0;
10
+ align-items: flex-start;
31
11
  position: relative;
32
-
33
- > * {
34
- overflow-x: scroll;
35
- -webkit-overflow-scrolling: touch;
36
- -ms-overflow-style: none;
37
- }
38
12
  }
39
13
 
40
14
  .app-pane__toc {
41
15
  flex: 0 0 auto;
42
16
  width: $toc-width;
43
- border-right: 1px solid govuk-functional-colour(border);
17
+ position: sticky;
18
+ top: 0;
19
+ align-self: flex-start;
20
+ max-height: 100vh;
21
+ overflow-x: hidden;
22
+ overflow-y: auto;
23
+ -webkit-overflow-scrolling: touch;
24
+ -ms-overflow-style: none;
44
25
  }
45
26
 
46
27
  .app-pane__content {
47
28
  flex: 1 1 auto;
29
+ align-self: stretch;
30
+ min-width: 0;
31
+ overflow: visible;
32
+ // The row is as tall as the TOC. Stretch this column so the divider
33
+ // reaches the footer when the page is shorter than the sidebar.
34
+ border-left: 1px solid govuk-functional-colour(border);
48
35
  }
49
36
  }
50
37
 
@@ -30,14 +30,17 @@ module GovukTechDocs
30
30
  .to_a
31
31
  end
32
32
 
33
- def select_top_level_html_files(resources)
33
+ def select_top_level_html_files(resources, config = nil)
34
+ http_prefix = config&.[](:http_prefix).to_s
35
+ home_url = http_prefix.end_with?("/") ? http_prefix : "#{http_prefix}/"
36
+
34
37
  resources
35
- .select { |r| r.path.end_with?(".html") && (r.parent.nil? || r.parent.url == "/") }
38
+ .select { |r| r.path.end_with?(".html") && (r.parent.nil? || r.parent.url == home_url) }
36
39
  end
37
40
 
38
41
  def multi_page_table_of_contents(resources, current_page, config, current_page_html = nil, include_child_resources: true)
39
42
  resources = sort_resources_stably(
40
- select_top_level_html_files(resources),
43
+ select_top_level_html_files(resources, config),
41
44
  )
42
45
 
43
46
  render_page_tree(resources, current_page, config, current_page_html, include_child_resources:)
@@ -1,3 +1,3 @@
1
1
  module GovukTechDocs
2
- VERSION = "6.6.0".freeze
2
+ VERSION = "6.6.0.2.rc".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.6.0
4
+ version: 6.6.0.2.rc
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service