This repository has been archived by the owner on Nov 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show guidance when subtitles aren't available (#140)
* add state to identify if video was started via autoplay * render guidance component on placeholder * style guidance banner * rejig things to handle video reloading on homepage * convert guidance to a class * style close button * WIP tests * hover state on close button * close banner after 5 seconds * wrap guidance in mixin * hide banner when it auto closes this way screen readers can still access it * add tests for guidance * link stright to video transcripts section * tidying * linting * use font smoothing to match the placeholder * remove need for o-buttons * clear timeout if banner removed early - prevents banner disappearing early when a skipped to the next video in a playlist before the previous banenr was hidden * implement listen once - `once` option not suppported by IE 11
- Loading branch information
1 parent
7e117b4
commit cb64aa7
Showing
7 changed files
with
283 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint class-methods-use-this: 0 */ | ||
|
||
const closeButton = (onClick) => { | ||
const button = document.createElement('button'); | ||
button.className = 'o-video__guidance__close'; | ||
button.addEventListener('click', e => { | ||
e.stopPropagation(); | ||
onClick(); | ||
}); | ||
return button; | ||
}; | ||
|
||
const container = (bannerMode) => { | ||
const containerEl = document.createElement('div'); | ||
containerEl.className = `o-video__guidance ${bannerMode ? 'o-video__guidance--banner' : ''}`; | ||
return containerEl; | ||
}; | ||
|
||
const link = () => { | ||
const linkEl = document.createElement('a'); | ||
linkEl.setAttribute('href', 'https://www.ft.com/accessibility#video-transcriptions'); | ||
linkEl.className = 'o-video__guidance__link'; | ||
linkEl.innerText = 'Subtitles unavailable'; | ||
linkEl.target = '_blank'; | ||
linkEl.addEventListener('click', e => e.stopPropagation()); | ||
return linkEl; | ||
}; | ||
|
||
class Guidance { | ||
|
||
constructor () { | ||
this.removeBanner = this.removeBanner.bind(this); | ||
this.hideBanner = this.hideBanner.bind(this); | ||
} | ||
|
||
createPlaceholder () { | ||
const containerEl = container(); | ||
containerEl.appendChild(link()); | ||
return containerEl; | ||
} | ||
|
||
createBanner () { | ||
this.banner = container(true); | ||
this.banner.appendChild(closeButton(this.removeBanner)); | ||
this.banner.appendChild(link()); | ||
|
||
this.timeout = setTimeout(this.hideBanner, 5000); | ||
|
||
return this.banner; | ||
} | ||
|
||
removeBanner () { | ||
if (this.banner) { | ||
this.banner.remove(); | ||
clearTimeout(this.timeout); | ||
} | ||
} | ||
|
||
hideBanner () { | ||
if (this.banner) { | ||
this.banner.classList.add('o-video__guidance--hidden'); | ||
} | ||
} | ||
} | ||
|
||
export default Guidance; |
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,80 @@ | ||
/// @access private | ||
/// Outputs styling for accessibility components | ||
|
||
@mixin _oVideoGuidance { | ||
$white: oColorsGetPaletteColor('white'); | ||
|
||
.o-video__guidance { | ||
@include oTypographySans(-1); | ||
background-color: oColorsMix($color: 'black', $background: 'transparent', $percentage: 75); | ||
padding: 10px 16px; | ||
// sass-lint:disable no-vendor-prefixes | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
// sass-lint:enable no-vendor-prefixes | ||
|
||
&--banner { | ||
padding: 6px; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
z-index: 2; | ||
} | ||
|
||
a { | ||
color: $white; | ||
text-decoration: none; | ||
} | ||
|
||
a:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
a:visited { | ||
text-decoration: none; | ||
} | ||
} | ||
|
||
.o-video__guidance--banner { | ||
.o-video__guidance__link { | ||
padding-left: 6px; | ||
top: -4px; | ||
position: relative; | ||
} | ||
} | ||
|
||
.o-video__guidance--hidden { | ||
visibility: hidden; | ||
} | ||
|
||
.o-video__guidance__link { | ||
@include oTypographyLinkCustom($white, $white); | ||
@include oTypographyLinkExternalIcon($white); | ||
color: $white; | ||
border-bottom: 0; | ||
} | ||
|
||
.o-video__guidance__close { | ||
@include oIconsGetIcon('cross', $color: $white, $container-width: 20px); | ||
border: 0; | ||
cursor: pointer; | ||
|
||
&:hover { | ||
background-color: oColorsMix($color: 'black', $background: 'white', $percentage: 75); | ||
} | ||
} | ||
|
||
.o-video--large { | ||
.o-video__play-cta--without-hint { | ||
.o-video__guidance { | ||
padding: 21px 16px; | ||
} | ||
} | ||
} | ||
|
||
.o-video__play-cta--with-hint { | ||
.o-video__guidance { | ||
padding: 10px 16px; | ||
} | ||
} | ||
} |
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.