-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,51 @@ | ||
/* eslint-env browser */ | ||
|
||
/* global ClipboardJS:false */ | ||
|
||
import ClipboardJS from 'clipboard'; | ||
|
||
const btnHtml = `<div class="bd-clipboard"> | ||
<button type="button" class="btn-clipboard" title="Copy to clipboard"> | ||
<svg class="bi" width="1em" height="1em" fill="currentColor"> | ||
<use xlink:href="#clipboard"/> | ||
</svg> | ||
</button> | ||
</div>`; | ||
|
||
document.querySelectorAll('div.highlight') | ||
.forEach((element) => { | ||
element.insertAdjacentHTML('beforebegin', btnHtml) | ||
}) | ||
|
||
const clipboard = new ClipboardJS('.btn-clipboard', { | ||
target: trigger => trigger.parentNode.nextElementSibling | ||
}) | ||
|
||
clipboard.on('success', (event) => { | ||
const iconFirstChild = event.trigger.querySelector('.bi').firstElementChild | ||
const namespace = 'http://www.w3.org/1999/xlink' | ||
const originalXhref = iconFirstChild.getAttributeNS(namespace, 'href') | ||
const originalTitle = event.trigger.title | ||
|
||
event.clearSelection() | ||
iconFirstChild.setAttributeNS(namespace, 'href', originalXhref.replace('clipboard', 'check2')) | ||
event.trigger.title = 'Copied!' | ||
|
||
setTimeout(() => { | ||
iconFirstChild.setAttributeNS(namespace, 'href', originalXhref) | ||
event.trigger.title = originalTitle | ||
}, 2000) | ||
}) | ||
|
||
/*clipboard.on('error', () => { | ||
const modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-' | ||
const fallbackMsg = 'Press ' + modifierKey + 'C to copy' | ||
const errorElement = document.getElementById('copy-error-callout') | ||
if (!errorElement) { | ||
return | ||
} | ||
errorElement.classList.remove('d-none') | ||
errorElement.insertAdjacentHTML('afterbegin', fallbackMsg) | ||
})*/ |
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,35 @@ | ||
// clipboard.js | ||
// | ||
// JS-based `Copy` buttons for code snippets. | ||
|
||
.bd-clipboard { | ||
position: relative; | ||
display: none; | ||
float: right; | ||
|
||
+ .highlight { | ||
margin-top: 0; | ||
} | ||
|
||
@media (min-width: 768px) { | ||
display: block; | ||
} | ||
} | ||
|
||
.btn-clipboard { | ||
position: absolute; | ||
top: .75em; | ||
right: .5em; | ||
z-index: 10; | ||
display: block; | ||
padding: .5em .75em .625em; | ||
line-height: 1; | ||
color: var(--bs-gray-900); | ||
background-color: var(--bs-gray-100); | ||
border: 0; | ||
border-radius: .25rem; | ||
|
||
&:hover { | ||
color: var(--bs-primary); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
{{- $bootstrapJs := resources.Get "/js/bootstrap.min.js" | resources.Copy "/assets/js/vendor/bootstrap.min.js" -}} | ||
<script async src="{{ $bootstrapJs.Permalink | relURL }}"></script> | ||
|
||
{{- $esbuildOptions := dict "targetPath" "/assets/js/lazyload.js" "target" "es2019" -}} | ||
{{- $esbuildOptions := dict "target" "es2019" -}} | ||
{{- $lazyloadOptions := dict "targetPath" "/assets/js/lazyload.js" -}} | ||
{{- $appOptions := dict "targetPath" "/assets/js/application.js" -}} | ||
|
||
{{- if eq hugo.Environment "production" -}} | ||
{{- $esbuildOptions = merge $esbuildOptions (dict "minify" "true") -}} | ||
{{- end -}} | ||
|
||
{{- $lazyload := resources.Get "js/lazyload.js" | js.Build $esbuildOptions }} | ||
{{- $lazyloadOptions = merge $esbuildOptions $lazyloadOptions -}} | ||
{{- $appOptions = merge $esbuildOptions $appOptions -}} | ||
{{- $lazyload := resources.Get "js/lazyload.js" | js.Build $lazyloadOptions -}} | ||
{{- $application := resources.Get "js/application.js" | js.Build $appOptions -}} | ||
|
||
<script async src="{{ $lazyload.RelPermalink | relURL }}"></script> | ||
<script async src="{{ $application.RelPermalink | relURL }}"></script> |