Skip to content

Commit

Permalink
Moved clipboard to vanilla JS
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-17 committed Oct 21, 2024
1 parent b280061 commit bfc6e58
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
5 changes: 0 additions & 5 deletions Gibbon.Git.Server/Views/Repositories/Detail.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,3 @@
</div>
</fieldset>
</div>

@section scripts
{
<script>new Clipboard('.copy-to-clip-button');</script>
}
1 change: 0 additions & 1 deletion Gibbon.Git.Server/Views/Repositories/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,4 @@

@section scripts {
<script src="~/js/RepositoryGroupToggle.js" defer="defer"></script>
<script>new Clipboard('.copy-to-clip-button');</script>
}
4 changes: 2 additions & 2 deletions Gibbon.Git.Server/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@
<script src="~/lib/js/jquery.validate.js"></script>
<script src="~/lib/js/jquery.validate.unobtrusive.js"></script>
<script src="~/lib/js/highlight.pack.js"></script>
<script src="~/lib/js/clipboard.min.js"></script>
<script src="~/js/clipboard.js"></script>
</environment>
<environment include="Production">
<script src="~/lib/js/jquery.min.js"></script>
<script src="~/lib/js/jquery.validate.min.js"></script>
<script src="~/lib/js/jquery.validate.unobtrusive.min.js"></script>
<script src="~/lib/js/highlight.pack.js"></script>
<script src="~/lib/js/clipboard.min.js"></script>
<script src="~/js/clipboard.js"></script>
</environment>
@await RenderSectionAsync("scripts", required: false)
</body>
Expand Down
19 changes: 19 additions & 0 deletions Gibbon.Git.Server/wwwroot/js/clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
document.addEventListener('DOMContentLoaded', function () {
initClipboard();
});

function initClipboard() {
document.body.addEventListener('click', function (event) {
const button = event.target.closest('[data-clipboard-text]');
if (button) {
const textToCopy = button.getAttribute('data-clipboard-text');
navigator.clipboard.writeText(textToCopy)
.then(() => {
// Success
})
.catch(err => {
console.error('Failed to copy!', err);
});
}
});
}
7 changes: 0 additions & 7 deletions Gibbon.Git.Server/wwwroot/lib/js/clipboard.min.js

This file was deleted.

0 comments on commit bfc6e58

Please sign in to comment.