Skip to content

Commit 2adf802

Browse files
authored
Merge pull request #177 from w3c/feature/logo-hero-video
Feature/logo hero video
2 parents e6c771d + 714d948 commit 2adf802

30 files changed

+696
-154
lines changed

assets-src/js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {navigation} from "./main/navigation";
77
import {responsiveTables} from "./main/responsive-tables";
88
import {flashes} from "./main/flashes";
99
import {headingAnchors} from './main/heading-anchors';
10+
import {videoHero} from './main/video-hero';
1011

1112
function domLoadedActions() {
1213
accountMenu();
@@ -17,6 +18,7 @@ function domLoadedActions() {
1718
responsiveTables();
1819
flashes();
1920
headingAnchors();
21+
videoHero();
2022

2123
/* Create a navDoubleLevel object and initiate double-level navigation for a <ul> with the correct data-component attribute */
2224
const navDoubleIntro = document.querySelector('ul[data-component="nav-double-intro"]');

assets-src/js/main/video-hero.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
let videoHero = function () {
2+
/* My refactored code */
3+
var heroVid = document.querySelector('[data-video="hero"]');
4+
var heroVidControl = document.querySelector('[data-video-control="hero"]');
5+
6+
if (heroVid && heroVidControl) {
7+
// Remove native controls and show custom button
8+
heroVid.removeAttribute("controls");
9+
heroVidControl.removeAttribute("hidden");
10+
11+
// Media query for reduced motion preference
12+
var motionQuery = window.matchMedia("(prefers-reduced-motion)");
13+
14+
// Helper to update button text
15+
function updateButtonState(isPlaying) {
16+
const label = isPlaying ? heroVidControl.dataset.videoPause : heroVidControl.dataset.videoPlay;
17+
heroVidControl.querySelector("span").innerText = label;
18+
heroVidControl.classList.toggle("js-play-video", isPlaying);
19+
}
20+
21+
// Play video with error handling
22+
function playHeroVid() {
23+
heroVid.play().then(() => {
24+
updateButtonState(true);
25+
}).catch((error) => {
26+
console.warn("Video play failed:", error);
27+
updateButtonState(false);
28+
});
29+
}
30+
31+
// Pause video
32+
function pauseHeroVid() {
33+
heroVid.pause();
34+
updateButtonState(false);
35+
}
36+
37+
// Handle user motion preference
38+
function handleReduceMotionChanged() {
39+
if (motionQuery.matches) {
40+
pauseHeroVid();
41+
} else {
42+
playHeroVid();
43+
}
44+
}
45+
46+
// Attempt to autoplay
47+
var promise = heroVid.play();
48+
if (promise !== undefined) {
49+
promise
50+
.then(() => {
51+
updateButtonState(true);
52+
})
53+
.catch((error) => {
54+
console.warn("Autoplay was prevented:", error);
55+
updateButtonState(false);
56+
});
57+
}
58+
59+
// Media query listener
60+
motionQuery.addEventListener("change", handleReduceMotionChanged);
61+
handleReduceMotionChanged();
62+
63+
// Toggle video playback on control click
64+
document.addEventListener("click", function (event) {
65+
const button = event.target.closest('[data-video-control="hero"]');
66+
if (button) {
67+
if (heroVid.paused) {
68+
playHeroVid();
69+
} else {
70+
pauseHeroVid();
71+
}
72+
}
73+
});
74+
75+
// Unregister media query listener on page unload to prevent memory leaks
76+
window.addEventListener("beforeunload", () => {
77+
motionQuery.removeEventListener("change", handleReduceMotionChanged);
78+
});
79+
}
80+
}
81+
export {videoHero}

assets-src/styles/sass/00-settings/_colors.scss

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $teal: #39cccc;
2424
$aqua: #7fdbff;
2525
$blue: #0073d8;
2626
$navy: #001f3f;
27-
$purple: #920ba6;
27+
$purple: #75336c;
2828
$fuchsia: #f012be;
2929
$grey: #aaa;
3030
$mercury-grey: #e5e5e5;
@@ -38,21 +38,17 @@ $red: #e93737;
3838
$light-red: #ec7070;
3939
$coral: #fc7750;
4040
$light-coral: #fea78d;
41-
$deep-yellow: #f9c818;
4241
$yellow: #f9dc4a;
4342
$deep-green: #0a4343;
4443
$teal-green: #237978;
4544
$aqua: #1bc0d7;
4645
$light-blue: #cbe0fb;
47-
$sky-blue: #6bc8fe;
48-
$azure: #0075ff;
4946
$w3c-blue: #005a9c;
50-
$blue: #005797;
51-
$deep-blue: #024488;
47+
$deep-blue: #002a56;
5248
$pink: #ddb0c8;
5349
$light-pink: #eeccdc;
5450
$storm-gray: #545454;
55-
$twiki-gray: #bdbdbd;
51+
$twiki-gray: #cac9c9;
5652
$mist-gray: #f8f8fb;
5753

5854

@@ -63,12 +59,12 @@ $border-color: $twiki-gray;
6359
$input-border-color: $storm-gray;
6460
$focus-color: $yellow;
6561

66-
$link-color: $blue;
62+
$link-color: $w3c-blue;
6763
$link-color--visited: $purple;
6864
$link-color--hover: $deep-blue;
6965

7066
$success-color: #046704;
71-
$info-color: $w3c-blue;
67+
$info-color: $deep-blue;
7268
$warning-color: #c28605;
7369
$error-color: #a82615;
7470

assets-src/styles/sass/50-core-components/_cards.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040

4141
&.talk {
42-
border-color: $deep-yellow;
42+
border-color: $deep-blue;
4343
}
4444

4545
&.workshop {

assets-src/styles/sass/50-core-components/_evangelists.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131

3232
.component--evangelists__list {
33-
background-color: $w3c-blue;
33+
background-color: $deep-blue;
3434
border-radius: rem(6);
3535
color: $white;
3636
overflow: hidden;

assets-src/styles/sass/50-core-components/_hero.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,21 @@
5555
}
5656

5757
.hero .button {
58+
align-items: center;
5859
align-self: flex-start;
60+
display: inline-flex;
61+
justify-content: center;
62+
}
63+
64+
65+
.hero--video .sidebar__video {
66+
margin-inline: auto;
67+
max-inline-size: rem(500);
68+
position: relative;
69+
}
70+
71+
.hero--video video {
72+
display: block;
5973
}
6074

6175
.hero--listing {

assets-src/styles/sass/50-core-components/_logo.scss

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
\*------------------------------------*/
44

55
.logo {
6-
display: block;
7-
height: rem(44);
8-
position: relative;
9-
width: rem(66);
10-
11-
@include mq($bp-tab-large) {
12-
height: rem(52);
13-
width: rem(78);
14-
}
6+
display: block;
7+
position: relative;
8+
width: clamp(3.75rem, 2.51rem + 6.198vw, 7.5rem);
159
}
1610

1711
.logo--member {

assets-src/styles/sass/50-core-components/_navigation.scss

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,18 @@
77
}
88

99
#global-nav {
10-
border-bottom: solid 1px $border-color;
1110
display: block;
12-
padding-bottom: rem(18);
13-
padding-top: rem(18);
14-
15-
@include mq($max-width) {
16-
padding-bottom: 0;
17-
padding-top: rem(20);
18-
}
11+
padding-bottom: em(26);
12+
padding-top: em(26);
1913
}
2014

2115
.global-nav__inner {
2216
align-items: center;
2317
display: flex;
2418
flex-wrap: wrap;
19+
gap: em(48);
2520

2621
@include mq($max-width) {
27-
align-items: flex-end;
2822
flex-wrap: nowrap;
2923
position: relative;
3024
}
@@ -108,13 +102,11 @@ li.top-nav-item + li.top-nav-item {
108102
}
109103

110104
@include mq($max-width) {
111-
margin-inline-end: rem(25);
112-
padding-bottom: rem(5);
113105
position: relative;
114-
106+
115107
&::before {
116108
background-color: $w3c-blue;
117-
bottom: 0;
109+
bottom: rem(-3);
118110
content:'';
119111
display: none;
120112
height: rem(3);

assets-src/styles/sass/50-core-components/_quotes.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
.component--quote {
66
@include txt-saturn;
7-
color: $w3c-blue;
7+
color: $purple;
88
font-weight: bold;
99
margin-inline-end: 0;
1010
margin-inline-start: rem(10);
1111
padding: rem(20);
1212
position: relative;
1313

1414
&::before {
15-
background-color: $w3c-blue;
15+
background-color: $purple;
1616
border-radius: rem(5);
1717
left: rem(-10);
1818
width: rem(10);

assets-src/styles/sass/50-core-components/_slide.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
}
4141

4242
&::before {
43-
background-color: $w3c-blue;
43+
background-color: $purple;
4444
border-radius: rem(5);
4545
content: '';
4646
height: 100%;

0 commit comments

Comments
 (0)