-
Notifications
You must be signed in to change notification settings - Fork 17
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 #2583 from alphagov/migrate-service-manual-frontends
Support rendering of service manual document types
- Loading branch information
Showing
129 changed files
with
2,446 additions
and
9 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 156 additions & 0 deletions
156
app/assets/javascripts/modules/highlight-active-section-heading.js
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,156 @@ | ||
window.GOVUK = window.GOVUK || {} | ||
window.GOVUK.Modules = window.GOVUK.Modules || {}; | ||
|
||
(function (Modules) { | ||
function HighlightActiveSectionHeading ($module) { | ||
this.$module = $module | ||
this._hasResized = true | ||
this._hasScrolled = true | ||
this._interval = 50 | ||
this.anchorIDs = [] | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.init = function () { | ||
window.addEventListener('resize', function () { this._hasResized = true }.bind(this)) | ||
window.addEventListener('scroll', function () { this._hasScrolled = true }.bind(this)) | ||
|
||
setInterval(this.checkResize.bind(this), this._interval) | ||
setInterval(this.checkScroll.bind(this), this._interval) | ||
|
||
this.anchors = this.$module.querySelectorAll('.js-page-contents a') | ||
this.getAnchors() | ||
|
||
this.checkResize() | ||
this.checkScroll() | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.checkResize = function () { | ||
if (this._hasResized) { | ||
this._hasResized = false | ||
this._hasScrolled = true | ||
} | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.checkScroll = function () { | ||
if (this._hasScrolled) { | ||
this._hasScrolled = false | ||
var windowDimensions = this.getWindowDimensions() | ||
if (windowDimensions.width <= 768) { | ||
this.removeActiveItem() | ||
} else { | ||
this.updateActiveNavItem() | ||
} | ||
} | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.getWindowDimensions = function () { | ||
return { | ||
height: window.innerHeight, | ||
width: window.innerWidth | ||
} | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.getAnchors = function () { | ||
for (var i = 0; i < this.anchors.length; i++) { | ||
var anchorID = this.anchors[i].getAttribute('href') | ||
// e.g. anchorIDs['#meeting-the-digital-service-standard', '#understand-your-users', '#research-continually'] | ||
this.anchorIDs.push(anchorID) | ||
} | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.updateActiveNavItem = function () { | ||
var windowVerticalPosition = this.getWindowPositions() | ||
var footerPosition = this.getFooterPosition() | ||
|
||
for (var i = 0; i < this.anchors.length; i++) { | ||
var theID = this.anchorIDs[i] | ||
var theNextID = this.anchorIDs[i + 1] | ||
|
||
var $theID = document.getElementById(theID.substring(1)) // remove the # at the start | ||
var $theNextID = theNextID ? document.getElementById(theNextID.substring(1)) : null // remove the # at the start | ||
|
||
var headingPosition = this.getHeadingPosition($theID) | ||
if (!headingPosition) { | ||
return | ||
} | ||
|
||
headingPosition = headingPosition - 53 // fix the offset from top of page | ||
|
||
if (theNextID) { | ||
var nextHeadingPosition = this.getNextHeadingPosition($theNextID) | ||
} | ||
|
||
var distanceBetweenHeadings = this.getDistanceBetweenHeadings(headingPosition, nextHeadingPosition) | ||
var isPastHeading | ||
|
||
if (distanceBetweenHeadings) { | ||
isPastHeading = (windowVerticalPosition >= headingPosition && windowVerticalPosition < (headingPosition + distanceBetweenHeadings)) | ||
} else { | ||
// when distanceBetweenHeadings is false (as there isn't a next heading) | ||
isPastHeading = (windowVerticalPosition >= headingPosition && windowVerticalPosition < footerPosition) | ||
} | ||
|
||
if (isPastHeading) { | ||
this.setActiveItem(theID) | ||
} | ||
} | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.getFooterPosition = function () { | ||
var footer = document.querySelector('.govuk-footer') | ||
if (footer) { | ||
return this.getElementPosition(footer) | ||
} | ||
} | ||
|
||
// these two functions call getElementPosition because the test needs to individually | ||
// override them - otherwise we could combine these four functions into one | ||
HighlightActiveSectionHeading.prototype.getHeadingPosition = function (element) { | ||
return this.getElementPosition(element) | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.getNextHeadingPosition = function (element) { | ||
return this.getHeadingPosition(element) | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.getElementPosition = function (element) { | ||
if (element) { | ||
var rect = element.getBoundingClientRect() | ||
var offset = { | ||
top: rect.top + window.scrollY, | ||
left: rect.left + window.scrollX | ||
} | ||
return offset.top | ||
} | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.getDistanceBetweenHeadings = function (headingPosition, nextHeadingPosition) { | ||
var distanceBetweenHeadings = (nextHeadingPosition - headingPosition) | ||
return distanceBetweenHeadings | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.setActiveItem = function (theID) { | ||
for (var i = 0; i < this.anchors.length; i++) { | ||
var href = this.anchors[i].getAttribute('href') | ||
if (href === theID) { | ||
this.anchors[i].classList.add('active') | ||
} else { | ||
this.anchors[i].classList.remove('active') | ||
} | ||
} | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.removeActiveItem = function () { | ||
for (var i = 0; i < this.anchors.length; i++) { | ||
this.anchors[i].classList.remove('active') | ||
} | ||
} | ||
|
||
HighlightActiveSectionHeading.prototype.getWindowPositions = function () { | ||
var doc = document.documentElement | ||
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0) | ||
return top | ||
} | ||
|
||
Modules.HighlightActiveSectionHeading = HighlightActiveSectionHeading | ||
})(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.app-full-width { | ||
#global-header-bar { // stylelint-disable-line selector-max-id | ||
display: none; | ||
} | ||
} | ||
|
||
// stylelint-disable declaration-no-important | ||
.app-\!-full-width-override { | ||
margin: auto !important; | ||
max-width: none !important; | ||
} |
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,11 @@ | ||
.app-change-history__latest-change { | ||
dd { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
} | ||
|
||
.app-change-history__change-note { | ||
color: $govuk-secondary-text-colour; | ||
white-space: pre-line; | ||
} |
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,19 @@ | ||
.app-collection { | ||
border-bottom: 1px solid $govuk-border-colour; | ||
margin-bottom: govuk-spacing(3); | ||
padding-bottom: govuk-spacing(3); | ||
|
||
@include govuk-media-query($from: tablet) { | ||
margin-bottom: govuk-spacing(9); | ||
padding-bottom: govuk-spacing(6); | ||
} | ||
|
||
&:last-child { | ||
border-bottom: none; | ||
margin-bottom: 0; | ||
} | ||
|
||
&__description { | ||
color: $govuk-secondary-text-colour; | ||
} | ||
} |
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,6 @@ | ||
.app-community-contact { | ||
@include govuk-media-query($from: tablet) { | ||
text-align: right; | ||
padding-top: govuk-spacing(8); | ||
} | ||
} |
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,7 @@ | ||
.govspeak-wrapper { | ||
padding-top: .9375em; | ||
|
||
@include govuk-media-query($from: tablet) { | ||
padding-top: 1.875em; | ||
} | ||
} |
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,25 @@ | ||
.app-hero { | ||
background-color: $govuk-brand-colour; | ||
color: govuk-colour("white"); | ||
margin-bottom: govuk-spacing(3); | ||
position: relative; | ||
top: -1px; | ||
|
||
@include govuk-media-query($from: tablet) { | ||
margin-bottom: govuk-spacing(6); | ||
} | ||
|
||
a:link, | ||
a:visited { | ||
@include govuk-typography-weight-bold; | ||
} | ||
} | ||
|
||
.app-hero-lead { | ||
line-height: 1.35; | ||
} | ||
|
||
.app-hero__heading--inverse, | ||
.app-hero__body--inverse { | ||
color: govuk-colour("white"); | ||
} |
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,20 @@ | ||
.notice { | ||
clear: both; | ||
@include responsive-bottom-margin; | ||
padding: govuk-spacing(3); | ||
|
||
border: 5px solid $govuk-brand-colour; | ||
|
||
@include govuk-media-query($from: tablet) { | ||
padding: govuk-spacing(4); | ||
} | ||
|
||
&__title { | ||
@include govuk-font(36, $weight: bold); | ||
margin-bottom: govuk-spacing(2); | ||
} | ||
|
||
&__description { | ||
@include govuk-font(19); | ||
} | ||
} |
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,18 @@ | ||
.app-page-contents { | ||
&__list li { | ||
margin-left: govuk-spacing(0); | ||
padding-right: govuk-spacing(3); | ||
|
||
&:before { | ||
content: "– "; | ||
display: inline-block; | ||
padding-right: govuk-spacing(1); | ||
} | ||
} | ||
|
||
// Styles required by GOVUK.HighlightActiveNavItem JS | ||
&__list .active { | ||
letter-spacing: 0; | ||
font-weight: bold; | ||
} | ||
} |
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,23 @@ | ||
.app-page-header { | ||
&__intro { | ||
p { | ||
@include govuk-text-colour; | ||
@include govuk-font($size: 19); | ||
@include govuk-responsive-margin(4, "bottom"); | ||
} | ||
|
||
a { | ||
@include govuk-link-common; | ||
@include govuk-link-style-default; | ||
} | ||
} | ||
|
||
&__heading { | ||
margin-bottom: govuk-spacing(3); | ||
|
||
@include govuk-media-query($from: tablet) { | ||
margin-bottom: govuk-spacing(7) + govuk-spacing(1); | ||
margin-top: govuk-spacing(7) + govuk-spacing(1); | ||
} | ||
} | ||
} |
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,3 @@ | ||
.panel { | ||
border-top: 1px solid $govuk-border-colour; | ||
} |
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,14 @@ | ||
.related { | ||
@include govuk-media-query($from: tablet) { | ||
border-top: 1px solid $govuk-border-colour; | ||
} | ||
} | ||
|
||
.related-item { | ||
&__email-link { | ||
padding-left: 25px; | ||
font-weight: bold; | ||
background: image-url("service-manual/mail-icon-x2.png") 0 40% no-repeat; | ||
background-size: 20px 14px; | ||
} | ||
} |
Oops, something went wrong.