-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new clipboard js file, added clipboard css, added link to clipboardJS…
… cdn to template
- Loading branch information
1 parent
9fb8b4d
commit 5d4002d
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
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,43 @@ | ||
// This file runs the Clipboard.js functionality | ||
document.querySelectorAll('div.listingblock').forEach((codeblock, index) => { | ||
codeblock.getElementsByTagName('pre')[0].insertAdjacentHTML("beforebegin", "<p class='clipboard-button-container'><span class='clipboard-button fa fa-clipboard'></span></p>"); | ||
document.getElementsByTagName('pre')[index].setAttribute('id',`clipboard-${index}`); | ||
}); | ||
|
||
document.querySelectorAll('span.clipboard-button').forEach((copybutton, index) => { | ||
copybutton.setAttribute('data-clipboard-target',`#clipboard-${index}`); | ||
}); | ||
|
||
var clipboard = new ClipboardJS('.clipboard-button', { | ||
text: function(target) { | ||
const targetId = target.getAttribute('data-clipboard-target').substr(1); | ||
const clipboardText = document.getElementById(targetId).innerText.replace(/\$\s/g, ""); | ||
|
||
if (clipboardText.slice(0, 2) === "# ") { | ||
return clipboardText.substr(2); | ||
} | ||
|
||
return clipboardText; | ||
} | ||
}); | ||
|
||
clipboard.on("success", function (e) { | ||
const triggerId = e.trigger.getAttribute("data-clipboard-target").substr(1); | ||
const triggerNode = document.getElementById(triggerId); | ||
|
||
const selection = window.getSelection(); | ||
selection.removeAllRanges(); | ||
|
||
const range = document.createRange(); | ||
range.selectNodeContents(triggerNode); | ||
selection.addRange(range); | ||
|
||
e.trigger.classList.toggle("fa-clipboard"); | ||
e.trigger.classList.toggle("fa-check"); | ||
|
||
setTimeout(function () { | ||
e.clearSelection(); | ||
e.trigger.classList.toggle("fa-clipboard"); | ||
e.trigger.classList.toggle("fa-check"); | ||
}, 2000); | ||
}); |
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