Skip to content

Commit f9c13b4

Browse files
author
Thierry Boileau
committed
add copy button
1 parent fb76d25 commit f9c13b4

File tree

227 files changed

+7609
-784
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+7609
-784
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 16.14.0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* The regular "copy" icon from Font Awesome.
3+
* https://fontawesome.com/icons
4+
*
5+
* @var {string}
6+
*/
7+
export const faCopyRegular = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M384 336l-192 0c-8.8 0-16-7.2-16-16l0-256c0-8.8 7.2-16 16-16l140.1 0L400 115.9 400 320c0 8.8-7.2 16-16 16zM192 384l192 0c35.3 0 64-28.7 64-64l0-204.1c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1L192 0c-35.3 0-64 28.7-64 64l0 256c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64L0 448c0 35.3 28.7 64 64 64l192 0c35.3 0 64-28.7 64-64l0-32-48 0 0 32c0 8.8-7.2 16-16 16L64 464c-8.8 0-16-7.2-16-16l0-256c0-8.8 7.2-16 16-16l32 0 0-48-32 0z"/></svg>`
8+
9+
/**
10+
* The solid "copy" icon from Font Awesome.
11+
* https://fontawesome.com/icons
12+
*
13+
* @var {string}
14+
*/
15+
export const faCopySolid = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M208 0L332.1 0c12.7 0 24.9 5.1 33.9 14.1l67.9 67.9c9 9 14.1 21.2 14.1 33.9L448 336c0 26.5-21.5 48-48 48l-192 0c-26.5 0-48-21.5-48-48l0-288c0-26.5 21.5-48 48-48zM48 128l80 0 0 64-64 0 0 256 192 0 0-32 64 0 0 48c0 26.5-21.5 48-48 48L48 512c-26.5 0-48-21.5-48-48L0 176c0-26.5 21.5-48 48-48z"/></svg>`
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import ClipboardJS from 'clipboard';
2+
import * as icons from './icons.js'
3+
4+
/**
5+
* Adds a copy-to-clipboard button to each container element as its first
6+
* child. The copy target is the button element's next sibling.
7+
*
8+
* @param {string} containerClass One of the classes in the container elements's class attribute.
9+
* @param {string} [buttonClass=copy-button] The button element's class attribute.
10+
*
11+
* @return {void}
12+
*/
13+
function addCopyToClipboardButtons(containerClass, buttonClass = 'copy-button') {
14+
const containers = document.querySelectorAll(`.${containerClass}`);
15+
16+
containers.forEach(container => {
17+
container.insertAdjacentHTML('afterbegin', `<button class="${buttonClass}">${icons.faCopyRegular}</button>`);
18+
});
19+
20+
const clipboard = new ClipboardJS(`.${buttonClass}`, {
21+
target: function(trigger) {
22+
return trigger.nextElementSibling;
23+
}
24+
});
25+
26+
clipboard.on('success', (e) => {
27+
if (e.action == 'copy') {
28+
setTimeout(() => {
29+
e.clearSelection();
30+
}, 1300);
31+
}
32+
});
33+
34+
clipboard.on('error', (e) => {
35+
console.error('ClipboardJS Error:', e.action, e.trigger);
36+
});
37+
}
38+
39+
export { addCopyToClipboardButtons }

assets/js/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { addCopyToClipboardButtons } from './copy-to-clipboard';
2+
3+
document.addEventListener('DOMContentLoaded', function() {
4+
addCopyToClipboardButtons('highlight');
5+
})

assets/jsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"paths": {
5+
"*": [
6+
"*"
7+
]
8+
}
9+
}
10+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

assets/_layouts/_default.scss renamed to assets/sass/_layouts/_default.scss

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,7 @@ pre code {
493493
}
494494
}
495495

496-
.download,
497-
.downloads-past {
496+
.download {
498497
select {
499498
appearance: none;
500499
background-image: url(../images/shared/select-toggle.png);
@@ -518,41 +517,10 @@ pre code {
518517
}
519518
}
520519

521-
.downloads-past {
522-
svg {
523-
max-width: 316px;
524-
}
525-
526-
form {
527-
max-width: 215px;
528-
529-
.m-button {
530-
margin-bottom: 20px;
531-
}
532-
533-
p {
534-
margin-bottom: 17px;
535-
}
536-
}
537-
538-
p>small {
539-
color: $mako;
540-
}
541-
}
542-
543520
.framework-index {
544521

545522
.icon-block {
546523
padding: 0 0 30px;
547-
548-
svg {
549-
width: 187px;
550-
height: auto;
551-
&.larger {
552-
width: 235px;
553-
height: auto;
554-
}
555-
}
556524
}
557525
}
558526

0 commit comments

Comments
 (0)