Skip to content

Commit

Permalink
Add missing copy JS function for markdown pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Dec 13, 2023
1 parent b751f1a commit 283e290
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions MyApp/wwwroot/mjs/app.mjs
Expand Up @@ -16,6 +16,19 @@ export async function remount() {
})
}

/* used in :::sh and :::nuget CopyContainerRenderer */
globalThis.copy = function (e) {
e.classList.add('copying')
let $el = document.createElement("textarea")
let text = (e.querySelector('code') || e.querySelector('p')).innerHTML
$el.innerHTML = text
document.body.appendChild($el)
$el.select()
document.execCommand("copy")
document.body.removeChild($el)
setTimeout(() => e.classList.remove('copying'), 3000)
}

document.addEventListener('DOMContentLoaded', () =>
Blazor.addEventListener('enhancedload', () => {
remount()
Expand Down

0 comments on commit 283e290

Please sign in to comment.