Skip to content

Commit

Permalink
added copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnWoodman committed Nov 29, 2020
1 parent 9f8ee12 commit 92584d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion _includes/bin_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h3>What you have:</h3>
<tbody>
{% for file in site.wadcoms %}
<tr>
<td><div class="bin-name"><a href="{{ file.url }}" style="text-decoration: none; color: DarkGreen;">{% include get_code.html page_test=file %}</a></div><p style="margin-top: -12px;">{% include filter_list.html bin=file %}</p></td>
<td><div class="bin-name"><a href="{{ file.url }}" id="{{ file.url }}" style="text-decoration: none; color: DarkGreen;">{% include get_code.html page_test=file %}</a><a href="javascript:void(0)" onClick="copyFunction('{{ file.url }}')" style="float: right;"><img src="/assets/copy-button.svg" alt="Copy" title="Copy" id="{{ file.url }}_img"/></a></div><p style="margin-top: -12px;">{% include filter_list.html bin=file %}</p></td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -49,6 +49,18 @@ <h3>What you have:</h3>

<script>

function copyFunction(file_url) {
var copyCommand = document.getElementById(file_url);

navigator.clipboard.writeText(copyCommand.innerText).then(() => {
document.getElementById(file_url + "_img").alt = "Copied";
document.getElementById(file_url + "_img").title = "Copied";
}, () => {
console.log("copy failed");
});

}

function handleChange(checkbox, label) {
if (checkbox.checked == true) {
document.getElementById(label).className = 'match';
Expand Down
5 changes: 5 additions & 0 deletions assets/copy-button.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 92584d0

Please sign in to comment.