forked from albertattard/java-boot-camp
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Albert Attard
committed
Jun 12, 2020
1 parent
ed16050
commit 77b27fc
Showing
7 changed files
with
131 additions
and
6 deletions.
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,23 @@ | ||
<!-- https://www.aleksandrhovhannisyan.com/blog/dev/how-to-add-a-copy-to-clipboard-button-to-your-jekyll-blog/ --> | ||
<div class="code-header"> | ||
{% if include.file %} | ||
<div class="file-name-container"> | ||
<span class="file-name" | ||
aria-label="File name: {{ include.file }}"> | ||
{{ include.file }} | ||
</span> | ||
</div> | ||
{% endif %} | ||
{% unless include.copyable == false %} | ||
<div class="copy-code-container"> | ||
<button class="copy-code-button" | ||
aria-label="Copy code block to your clipboard" | ||
data-code="{{ include.code | escape }}" | ||
onclick="copyCode" | ||
></button> | ||
</div> | ||
{% endunless %} | ||
</div> | ||
```{{ include.lang }} | ||
{{ include.code }} | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
.code-header { | ||
display: flex; | ||
background-color: #3b3b3b; | ||
border-top-left-radius: 5px; | ||
border-top-right-radius: 5px; | ||
flex-wrap: wrap; | ||
justify-content: flex-end; | ||
padding: 12px 20px; | ||
margin-bottom: calc(-1 * calc(1em + 0.5vw) + -1px); | ||
margin-top: 0.5em; | ||
z-index: 2; | ||
} | ||
|
||
.code-header .file-name-container { | ||
display: flex; | ||
align-items: center; | ||
flex: 2; | ||
justify-content: flex-start; | ||
} | ||
|
||
.code-header .file-name { | ||
color: #bcbcbc; | ||
font-size: 1.1em; | ||
font-weight: 400; | ||
font-family: monospace, monospace; | ||
margin: 0; | ||
padding-bottom: 1em; | ||
word-break: break-all; | ||
transition: color ease 0.3s; | ||
} | ||
|
||
.copy-code-container { | ||
display: flex; | ||
justify-content: flex-end; | ||
padding-bottom: 1.5em; | ||
} | ||
|
||
.copy-code-button { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
border: none; | ||
cursor: pointer; | ||
font-size: 1rem; | ||
background-color: #616161; | ||
color: #e7e7e7; | ||
padding: 0.4em 0.5em; | ||
border-radius: 5px; | ||
|
||
&::before { | ||
content: "Copy"; | ||
} | ||
|
||
&::after { | ||
margin-left: 4px; | ||
content: "📋"; | ||
width: 1em; | ||
} | ||
|
||
// This class will be toggled via JavaScript | ||
&.copied { | ||
&::before { | ||
content: "Copied!"; | ||
} | ||
|
||
&::after { | ||
content: "✔️"; | ||
} | ||
} | ||
} | ||
|
||
.copy-code-button:hover { | ||
color: black; | ||
background-color: #adadad; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const copyCode = (clickEvent) => { | ||
console.log("clicked...") | ||
// const copyCodeButton = clickEvent.target; | ||
// const tempTextArea = document.createElement('textarea'); | ||
// tempTextArea.textContent = copyCodeButton.getAttribute('data-code'); | ||
// document.body.appendChild(tempTextArea); | ||
// | ||
// const selection = document.getSelection(); | ||
// selection.removeAllRanges(); | ||
// tempTextArea.select(); | ||
// document.execCommand('copy'); | ||
// selection.removeAllRanges(); | ||
// document.body.removeChild(tempTextArea); | ||
// | ||
// copyCodeButton.classList.add('copied'); | ||
// setTimeout(() => { | ||
// copyCodeButton.classList.remove('copied'); | ||
// }, 2000); | ||
}; | ||
|
||
// document.querySelectorAll('.copy-code-button').forEach((copyCodeButton) => { | ||
// copyCodeButton.addEventListener('click', copyCode); | ||
// }); |