Skip to content

Commit fa9019a

Browse files
committed
Add auto scheme handler and clean some code
1 parent 02db7cf commit fa9019a

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

assets/css/fr-index.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Fix using if() only for blink */
2-
body.blink h2 {
2+
body.blink #title {
33
width: if(
44
/* When viewport is smaller than 400px, apply the fix, else use the normal value */
55
/* Removes the menu button and margin widths a single time to account for longer text */
@@ -9,6 +9,6 @@ body.blink h2 {
99
}
1010

1111
/* Classic method for browser not supporting if */
12-
body.gecko h2, body.webkit h2 {
12+
body.gecko #title, body.webkit #title {
1313
width: calc(100vw - var(--body-margin) - var(--menu-icon-container-size));
1414
}

assets/css/global.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/* Values */
1010
--body-margin: 8px;
1111
--transition-speed: 300ms;
12-
--defaukt-radius: 8px;
12+
--default-radius: 0px;
1313
}
1414

1515
body {

assets/css/index.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ header.collapsed {
3838
border: none;
3939
outline: solid 2px #F6A6FC;
4040
transition: var(--transition-speed);
41+
border-radius: var(--default-radius);
4142
}
4243

4344
#navbar-menu-button.open {
@@ -79,9 +80,12 @@ header.collapsed {
7980
}
8081

8182
h2 {
82-
width: calc(100vw - 2*var(--body-margin) - 2*var(--menu-icon-container-size));
83-
text-align: center;
8483
font: normal 600 1.65em "Onest";
84+
text-align: center;
85+
}
86+
87+
#title {
88+
width: calc(100vw - 2*var(--body-margin) - 2*var(--menu-icon-container-size));
8589
}
8690

8791
#color-scheme-button {
@@ -96,6 +100,7 @@ h2 {
96100
outline: solid 2px #F6A6FC;
97101
transition: var(--transition-speed);
98102
position: relative;
103+
border-radius: var(--default-radius);
99104
}
100105

101106
#color-scheme-button::before {
@@ -108,6 +113,7 @@ h2 {
108113
height: var(--size);
109114
transition: var(--transition-speed);
110115
background: #F6A6FC75;
116+
border-radius: var(--default-radius);
111117
}
112118

113119
.color-scheme-icon {

assets/js/scripts.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
function getEngine() { // returns a string of the browser's engine bypassing its userAgent string
1+
const body = document.body;
2+
3+
// Browser engine handler
4+
function getEngine() { // returns a string of the browser's engine bypassing its userAgent string
25
const docStyle = document.documentElement.style;
3-
if (window.navigator.userAgentData) return 'Blink'; // only present in Chromium
6+
if (window.navigator.userAgentData) return 'Blink'; // only present in Chromium
47
if ('MozAppearance' in docStyle || window.netscape) return 'Gecko';
5-
if ('WebkitAppearance' in docStyle && !window.chrome) return 'WebKit'; // Chromium engine would return true to Webkit test, thus adding not window.chrome
6-
return 'Blink'; // default to Chromium engine
8+
if ('WebkitAppearance' in docStyle && !window.chrome) return 'WebKit'; // Chromium engine would return true to Webkit test, thus adding not window.chrome
9+
return 'Blink'; // default to Chromium engine
710
};
811

9-
document.body.classList.add(getEngine().toLowerCase()); // adds as a class the browser engine for easy specific fixes in CSS
12+
13+
body.classList.add(getEngine().toLowerCase()); // adds as a class the browser engine for easy specific fixes in CSS
14+
15+
// Color scheme handler
16+
function toggleScheme() { body.classList.toggle('dark'); };
17+
const colorSchemeQuery = window.matchMedia('(prefers-color-scheme: dark)');
18+
19+
if (colorSchemeQuery.matches) { toggleScheme(); }; // Initial toggle
20+
colorSchemeQuery.addEventListener('change', toggleScheme); // When browser preference changes
21+
document.getElementById("color-scheme-button").addEventListener('click', () => { toggleScheme(); }); // Handles scheme button clicks

en/index.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ <h2 id="portfolio">Portfolio</h2>
132132
onerror="this.onerror=null; this.src='../../assets/images/icons/missing.svg'; this.classList.add('icon-missing')"
133133
alt="">
134134
</button>
135-
136-
<script> // Toggles nav-lang and nav-links visibility from menu button
137-
const schemeButton = document.getElementById('color-scheme-button');
138-
schemeButton.addEventListener('click', () => {
139-
document.body.classList.toggle('dark');
140-
});
141-
</script>
142135
</footer>
143136

144137
</body>

fr/index.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ <h2 id="portfolio">Portfolio</h2>
132132
onerror="this.onerror=null; this.src='../../assets/images/icons/missing.svg'; this.classList.add('icon-missing')"
133133
alt="">
134134
</button>
135-
136-
<script> // Toggles nav-lang and nav-links visibility from menu button
137-
const schemeButton = document.getElementById('color-scheme-button');
138-
schemeButton.addEventListener('click', () => {
139-
document.body.classList.toggle('dark');
140-
});
141-
</script>
142135
</footer>
143136

144137
</body>

0 commit comments

Comments
 (0)