-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GTD-3 Multipage Navigation #27
Merged
jonathanglassman
merged 36 commits into
alphagov:master
from
ConvivioTeam:GTD-3-multipage-navigation
Jul 3, 2018
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
d766f66
GTD-14: A WIP proof of concept for the multipage navigation
lewisnyman f7385b9
GTD-14: Print H1 tags from frontmatter
lewisnyman aec7f33
GTD-14: Moved the h1s back into the markdown content They are require…
lewisnyman 48381db
GTD-14: Modfied the table of contents generator so it prepends the pa…
lewisnyman 8cd8ffe
GTD-14: Keep the fragment for H1 links because this still needs to wo…
lewisnyman 4bbcd3c
GTD-14: Implemention of weight frontmatter to sort navigation items
lewisnyman 2d62b65
GTD-14: Catch pages where weight frontmatter is not defined and sort …
lewisnyman c15333e
GTD-14: Do not generate the current page content twice when parsing f…
lewisnyman 7f5a686
GTD-14: Update the in-view javascript code so it works with the new u…
lewisnyman 415fab3
GTD-14: Proof of concept interaction for collapsible navigation
lewisnyman f182c0c
GTD-14: Search each top level nav item and children for an exact href…
lewisnyman 607c1e0
GTD-14: Automatically open collapsed navigation sections if you scrol…
lewisnyman 7418c34
GTD-14: Add some basic affordances for open/closed navigation headings
lewisnyman d4b9dac
GTD-14: Only iterate through the top level pages in the navigation, f…
lewisnyman a1bb48a
GTD-3: Improve the accessibility of the collapsible TOC navigation
lewisnyman f73c3b8
GTD-3: Add weight frontmatter documentation
lewisnyman 6af07c3
GTD-3: Avoid parsing the heading structure of redirect pages
lewisnyman 7368edb
GTD-3: Add focus styling to toc toggle button
lewisnyman dfb1828
GTD-3: Fixing tests
lewisnyman ebca17c
GTD-3 Moved multiple page tree navigation into a helper
lewisnyman 8d725bd
GTD-3: Added a unit test for multiple page navigation
lewisnyman 0461085
GTD-3: Ensure multipage nav still supports single page sites
lewisnyman cc3d4a9
GTD-3: Added an integration test for multipage navigation
lewisnyman 0c716e7
GTD-3: Tweaked the alignment of the toggle icons
lewisnyman 3ff59a2
GTD-3: Replaced the +- text with arrow icons based on Stephen's feedback
lewisnyman a9fc850
GTD-3: Fix broken text toggle for screen readers
lewisnyman 7619da7
GTD-3: A few spacing tweaks for mobile devices
lewisnyman b065dd4
GTD-3: Add multipage_nav option
lewisnyman 4507fdc
GTD-3: Moved resource selection logic into helper a fixed tests.
lewisnyman 12186c3
GTD-3: Added support for nested page structures
lewisnyman 01b1780
GTD-3: Ensure navigation text and collapsible toggle doesn't overlap
lewisnyman 0f4b485
GTD-3: Automatically expand navigation items when on their child pages
lewisnyman ea7c538
GTD-3: Added an exception root page fpr the active trail check for co…
lewisnyman 13e5572
GTD-3: Tweak the active navigation item code to support nested pages
lewisnyman 9e99df6
GTD-3: Split collapsible navigation into a seperate javascript module…
lewisnyman e83ef00
GTD-3: Cleaned up whitespace and updated tests to match nested page code
lewisnyman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
(function($, Modules) { | ||
'use strict'; | ||
|
||
Modules.CollapsibleNavigation = function () { | ||
|
||
var $contentPane; | ||
var $nav; | ||
var $topLevelItems; | ||
var $headings; | ||
var $listings; | ||
|
||
var $openLink; | ||
var $closeLink; | ||
|
||
this.start = function ($element) { | ||
$contentPane = $('.app-pane__content'); | ||
$nav = $element; | ||
$topLevelItems = $nav.find('> ul > li'); | ||
$headings = $topLevelItems.find('> a'); | ||
$listings = $topLevelItems.find('> ul'); | ||
|
||
// Attach collapsible heading functionality,on mobile and desktop | ||
collapsibleHeadings(); | ||
openActiveHeading(); | ||
$contentPane.on('scroll', _.debounce(openActiveHeading, 100, { maxWait: 100 })); | ||
|
||
}; | ||
|
||
function collapsibleHeadings() { | ||
for (var i = $topLevelItems.length - 1; i >= 0; i--) { | ||
var $topLevelItem = $($topLevelItems[i]); | ||
var $heading = $topLevelItem.find('> a'); | ||
var $listing = $topLevelItem.find('> ul'); | ||
// Only add collapsible functionality if there are children. | ||
if ($listing.length == 0) { | ||
continue; | ||
} | ||
$topLevelItem.addClass('collapsible'); | ||
$listing.addClass('collapsible__body') | ||
.attr('aria-expanded', 'false'); | ||
$heading.addClass('collapsible__heading') | ||
.after('<button class="collapsible__toggle"><span class="collapsible__toggle-label">Expand ' + $heading.text() + '</span><span class="collapsible__toggle-icon" aria-hidden="true"></button>') | ||
$topLevelItem.on('click', '.collapsible__toggle', function(e) { | ||
e.preventDefault(); | ||
var $parent = $(this).parent(); | ||
toggleHeading($parent); | ||
}); | ||
} | ||
} | ||
|
||
function toggleHeading($topLevelItem) { | ||
var isOpen = $topLevelItem.hasClass('is-open'); | ||
var $heading = $topLevelItem.find('> a'); | ||
var $body = $topLevelItem.find('collapsible__body'); | ||
var $toggleLabel = $topLevelItem.find('.collapsible__toggle-label'); | ||
|
||
$topLevelItem.toggleClass('is-open', !isOpen); | ||
$body.attr('aria-expanded', isOpen ? 'true' : 'false'); | ||
$toggleLabel.text(isOpen ? 'Expand ' + $heading.text() : 'Collapse ' + $heading.text()); | ||
} | ||
|
||
function openActiveHeading() { | ||
var $activeElement; | ||
var currentPath = window.location.pathname; | ||
var isActiveTrail = '[href*="' + currentPath + '"]'; | ||
// Add an exception for the root page, as every href includes / | ||
if(currentPath == '/') { | ||
isActiveTrail = '[href="' + currentPath + window.location.hash + '"]' | ||
} | ||
for (var i = $topLevelItems.length - 1; i >= 0; i--) { | ||
var $element = $($topLevelItems[i]); | ||
var $heading = $element.find('> a'); | ||
// Check if this item href matches | ||
if($heading.is(isActiveTrail)) { | ||
$activeElement = $element; | ||
break; | ||
} | ||
// Otherwise check the children | ||
var $children = $element.find('li > a'); | ||
var $matchingChildren = $children.filter(isActiveTrail); | ||
if ($matchingChildren.length) { | ||
$activeElement = $element; | ||
break; | ||
} | ||
} | ||
if($activeElement && !$activeElement.hasClass('is-open')) { | ||
toggleHeading($activeElement); | ||
} | ||
} | ||
|
||
|
||
}; | ||
})(jQuery, window.GOVUK.Modules); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Collapsible JS component styling, made for the navigation tree. | ||
// These classes are added in table-of-contents.js. | ||
// They should not be applied without the JS. | ||
|
||
.collapsible { | ||
position: relative; | ||
} | ||
.collapsible__body { | ||
display: none; | ||
.collapsible.is-open & { | ||
display: block | ||
} | ||
} | ||
.collapsible__toggle { | ||
position: absolute; | ||
top: 0; | ||
right: -25px; | ||
width: 50px; | ||
height: 40px; | ||
overflow: hidden; | ||
text-indent: -999em; | ||
border: 0; | ||
background: 0; | ||
color: inherit; | ||
padding: 0; | ||
&:focus { | ||
outline: 3px solid $focus-colour; | ||
} | ||
} | ||
.collapsible__toggle-icon { | ||
position: absolute; | ||
top: 0; | ||
right: 30px; | ||
&::after { | ||
content: ''; | ||
display: block; | ||
background: no-repeat file-url('arrow-down.svg') center center; | ||
background-size: 18px auto; | ||
width: 20px; | ||
height: 40px; | ||
} | ||
.collapsible.is-open &::after { | ||
background-image: file-url('arrow-up.svg'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This confused me a bit because a higher weight in search results often means that things will end up higher in the results. What would you think of flipping the logic and naming this
navigation_priority
?Big 👍 for documenting the option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that seems more explicit. I'll ask @jonathanglassman for his thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with either. "Weight = heavier sinks to the bottom" made sense to me, but navigation priority also makes sense. I would teach it as "smaller numbers = higher up the TOC" so as long as people don't think that higher numbers mean a higher priority in the TOC, we should be ok. If I had to make a choice I would keep it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I see your point, it would be nice to have something that just makes sense without an explanation. It's hard to come up with a scale that's intuitive.
Jon and I had a quick chat this morning, and decided to stick with weight for now and he really connected with the analogy. However, we want to push this out wider to other writers and see if they get confused by this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had time to look at the PR as a whole yet, but just wanted to "weigh in" on this discussion...
I would interpret weight in the same way as @tijmenb - as in: more weight = more important = more prominent.
I would maybe call it something like
order
ornavigation_order
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(navigation_)priority
would be good.(navigation_)order
may be vague 🤔