Skip to content

Commit e6d3c1c

Browse files
committed
Styles, 404, playground link button
1 parent f1bfca8 commit e6d3c1c

File tree

7 files changed

+121
-1
lines changed

7 files changed

+121
-1
lines changed

docs/web/404.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# 404 Not found
1+
# 404 Page Not found
2+
3+
The page you’re looking for doesn’t exist or has been moved.
4+
5+
Please return to our [homepage](https://core-js.io/) to continue browsing.

website/package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dev": "vite"
77
},
88
"dependencies": {
9+
"@popperjs/core": "^2.11.8",
910
"@vitejs/plugin-legacy": "^7.1.0",
1011
"front-matter": "^4.0.2",
1112
"highlight.js": "^11.11.1",

website/src/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,9 @@
110110
</div>
111111
</div>
112112
</footer>
113+
<div id="tooltip" role="tooltip">
114+
<div id="tooltip-text"></div>
115+
<div id="tooltip-arrow" data-popper-arrow></div>
116+
</div>
113117
</body>
114118
</html>

website/src/js/playground.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* global Babel -- global scope directive */
33
import hljs from 'highlight.js/lib/core';
44
import javascript from 'highlight.js/lib/languages/javascript';
5+
import { createPopper } from '@popperjs/core';
56

67
hljs.registerLanguage('javascript', javascript);
78

@@ -28,6 +29,8 @@ function init() {
2829
const resultBlock = document.querySelector('.result');
2930
const backLinkBlock = document.querySelector('.back-link');
3031
const backLink = document.querySelector('.back-link a');
32+
const tooltip = document.querySelector('#tooltip');
33+
const tooltipText = document.querySelector('#tooltip-text');
3134

3235
if (!codeInput) return;
3336

@@ -199,6 +202,44 @@ function init() {
199202
);
200203
}
201204

205+
function copyToClipboard(text) {
206+
if (navigator.clipboard && window.isSecureContext) {
207+
return navigator.clipboard.writeText(text);
208+
} else {
209+
const textArea = document.createElement("textarea");
210+
textArea.value = text;
211+
textArea.style.position = "fixed";
212+
textArea.style.top = '0';
213+
textArea.style.left = '0';
214+
textArea.style.opacity = '0';
215+
document.body.appendChild(textArea);
216+
textArea.focus();
217+
textArea.select();
218+
219+
try {
220+
const successful = document.execCommand('copy');
221+
document.body.removeChild(textArea);
222+
if (successful) {
223+
return Promise.resolve();
224+
} else {
225+
return Promise.reject(new Error('Copy command was unsuccessful'));
226+
}
227+
} catch (err) {
228+
document.body.removeChild(textArea);
229+
return Promise.reject(err);
230+
}
231+
}
232+
}
233+
234+
function showTooltip(element, message, time = 3000) {
235+
tooltipText.innerHTML = message;
236+
tooltip.setAttribute('data-show', '');
237+
createPopper(element, tooltip, { placement: 'bottom' });
238+
setTimeout(() => {
239+
tooltip.removeAttribute('data-show');
240+
}, time);
241+
}
242+
202243
codeInput.addEventListener('input', () => {
203244
codeOutput.removeAttribute('data-highlighted');
204245
let val = codeInput.value;
@@ -231,6 +272,10 @@ function init() {
231272
e.preventDefault();
232273
pageParams.set('code', codeInput.value);
233274
globalThis.location.hash = pageParams.toString();
275+
copyToClipboard(globalThis.location.toString())
276+
.then(() => {
277+
showTooltip(linkButton, 'Link copied');
278+
});
234279
});
235280
});
236281

website/src/scss/app.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
@use "parts/footer";
1515
@use "parts/code";
1616
@use "parts/playground";
17+
@use "parts/tooltip";

website/src/scss/parts/tooltip.scss

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
@use "../includes/mixins" as *;
2+
@use "../includes/themed" as *;
3+
@use "../includes/themes" as *;
4+
@use "../includes/themify" as *;
5+
6+
#tooltip {
7+
font-weight: bold;
8+
padding: 4px 8px;
9+
border-radius: 4px;
10+
opacity: 0;
11+
transition: opacity 0.3s ease;
12+
@include themify($themes) {
13+
background: themed('font-color');
14+
color: themed('background-highlight');
15+
}
16+
17+
&[data-show] {
18+
opacity: 1;
19+
}
20+
21+
#tooltip-arrow,
22+
#tooltip-arrow::before {
23+
position: absolute;
24+
width: 8px;
25+
height: 8px;
26+
background: inherit;
27+
}
28+
29+
#tooltip-arrow {
30+
visibility: hidden;
31+
}
32+
33+
#tooltip-arrow::before {
34+
visibility: visible;
35+
content: '';
36+
transform: rotate(45deg);
37+
}
38+
39+
&[data-popper-placement^='top'] > #tooltip-arrow {
40+
bottom: -4px;
41+
}
42+
43+
&[data-popper-placement^='bottom'] > #tooltip-arrow {
44+
top: -4px;
45+
}
46+
47+
&[data-popper-placement^='left'] > #tooltip-arrow {
48+
right: -4px;
49+
}
50+
51+
&[data-popper-placement^='right'] > #tooltip-arrow {
52+
left: -4px;
53+
}
54+
}

0 commit comments

Comments
 (0)