-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from ConvivioTeam/GTD-3-multipage-navigation
GTD-3 Multipage Navigation
- Loading branch information
Showing
20 changed files
with
426 additions
and
29 deletions.
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.