mirror of
https://github.com/emrusz/emrusz.git
synced 2025-04-11 18:40:35 -04:00
Enable code copy and search
This commit is contained in:
parent
28b21bab46
commit
ab284840d9
2 changed files with 4 additions and 51 deletions
|
@ -19,7 +19,7 @@ description: >- # this means to ignore newlines until "baseurl:"
|
||||||
Blog and portfolio for Em (Ethan) Ruszanowski.
|
Blog and portfolio for Em (Ethan) Ruszanowski.
|
||||||
github_username: emrusz
|
github_username: emrusz
|
||||||
minimal_mistakes_skin: dark
|
minimal_mistakes_skin: dark
|
||||||
search: false
|
search: true
|
||||||
|
|
||||||
# Build settings
|
# Build settings
|
||||||
markdown: kramdown
|
markdown: kramdown
|
||||||
|
@ -59,6 +59,7 @@ author:
|
||||||
name: "Em (Ethan) Ruszanowski"
|
name: "Em (Ethan) Ruszanowski"
|
||||||
avatar: "/assets/images/avatar.jpg"
|
avatar: "/assets/images/avatar.jpg"
|
||||||
bio: "Data engineer, polyglot developer, and RIT Computing and Information Technologies alum."
|
bio: "Data engineer, polyglot developer, and RIT Computing and Information Technologies alum."
|
||||||
|
location: "Rochester, NY"
|
||||||
links:
|
links:
|
||||||
- label: "Email"
|
- label: "Email"
|
||||||
icon: "fas fa-fw fa-envelope"
|
icon: "fas fa-fw fa-envelope"
|
||||||
|
@ -91,9 +92,6 @@ footer:
|
||||||
icon: "fas fa-fw fa-heartbeat"
|
icon: "fas fa-fw fa-heartbeat"
|
||||||
url: "https://status.rusz.dev"
|
url: "https://status.rusz.dev"
|
||||||
|
|
||||||
after_footer_scripts:
|
|
||||||
- assets/js/clipboard.js
|
|
||||||
|
|
||||||
social:
|
social:
|
||||||
type:
|
type:
|
||||||
names:
|
names:
|
||||||
|
@ -121,6 +119,8 @@ defaults:
|
||||||
layout: single
|
layout: single
|
||||||
author_profile: true
|
author_profile: true
|
||||||
|
|
||||||
|
enable_copy_code_button: true
|
||||||
|
|
||||||
category_archive:
|
category_archive:
|
||||||
type: liquid
|
type: liquid
|
||||||
path: /categories/
|
path: /categories/
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
* A nice little clipboard script provided by crykn. Thanks!
|
|
||||||
*/
|
|
||||||
|
|
||||||
function sleep(ms) {
|
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onClickEffect(btn, style) {
|
|
||||||
btn.removeClass("btn-light");
|
|
||||||
btn.addClass(style);
|
|
||||||
await sleep(250);
|
|
||||||
btn.removeClass(style);
|
|
||||||
btn.addClass("btn-light");
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
// Create butons
|
|
||||||
$(".page__content pre > code").each(function() {
|
|
||||||
$(this).parent().prepend(
|
|
||||||
$(document.createElement('button')).prop({
|
|
||||||
type: 'button',
|
|
||||||
innerHTML: '<i class="far fa-copy"></i>',
|
|
||||||
})
|
|
||||||
.attr('title', 'Copy to clipboard')
|
|
||||||
.addClass('btn')
|
|
||||||
.addClass('btn--primary')
|
|
||||||
.css('position', 'absolute')
|
|
||||||
.css('right', '1em')
|
|
||||||
// Click listener
|
|
||||||
.on('click', function() {
|
|
||||||
let codeElement = $(this).parent().children('code').first();
|
|
||||||
|
|
||||||
if (!codeElement) {
|
|
||||||
throw new Error("Unexpected error! No corresponding code block was found for this button.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Blink effect
|
|
||||||
onClickEffect($(this), "btn--success")
|
|
||||||
|
|
||||||
// Copy to clipoard function
|
|
||||||
navigator.clipboard.writeText($(codeElement).text()).then(() => true, () => true);
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Add table
Reference in a new issue