Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clipboard copy button scrolling issue fix. #578

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ data/*
!*.keep
conf/generated.keystore
.bsp/
.vscode
33 changes: 18 additions & 15 deletions app/assets/css/modules/_clipboard.styl
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@

.prettyprint
position: relative
padding-top: 10px !important
padding-bottom: 10px !important

.copy-button
cursor: pointer;
border: 0;
font-size: 10px;
text-transform: uppercase;
font-weight: 500;
padding: 0 0 0 0;
color: green-dark;
background-color: transparent;
position: absolute;
top: 0;
right: 0;
.copy-button
align-self: end
padding: 10px 10px !important
background: #f7f7f7;
border: 1px solid;
border-radius: 8px
color: #447103
cursor: pointer
font-size: var(--font-size-s)
justify-self: end
position: absolute
right: 0
z-index: 999999

// This is a terrible hack, but prettify will try coloring the Copy button otherwise...
.copy-button:before
content: "Copy"

.documentation #content article
position: relative

58 changes: 26 additions & 32 deletions app/views/clipboard.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,34 @@

<script type="text/javascript" charset="utf-8" src="@routes.Assets.versioned("lib/clipboard.js/clipboard.js")"></script>
@views.html.helper.script(Symbol("type") -> "text/javascript") {
(function(){
var pre = document.getElementsByClassName('prettyprint');
for (var i = 0; i < pre.length; i++) {
var button = document.createElement('button');
button.className = 'copy-button';
(function(){
$(".prettyprint").before("<button class='copy-button'>Copy</button>");

pre[i].appendChild(button);
}
// Run Clipboard
var copyCode = new ClipboardJS('.copy-button', {
target: function(trigger) {
return trigger.nextElementSibling;
}
});

// Run Clipboard
var copyCode = new ClipboardJS('.copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
// On success:
copyCode.on('success', function(event) {
event.clearSelection();
event.trigger.textContent = ' Success';
window.setTimeout(function() {
event.trigger.textContent = 'Copy';
}, 2000);
});

// On success:
copyCode.on('success', function(event) {
event.clearSelection();
event.trigger.textContent = ' Success';
window.setTimeout(function() {
event.trigger.textContent = '';
}, 2000);
});
// On error (Safari):
// - Change the "Press Ctrl+C to copy"
// - Swap it to "Copy" in 2s.
copyCode.on('error', function(event) {
event.trigger.textContent = 'Press "Ctrl + C" to copy';
window.setTimeout(function() {
event.trigger.textContent = 'Copy';
}, 5000);
});

// On error (Safari):
// - Change the "Press Ctrl+C to copy"
// - Swap it to "Copy" in 2s.
copyCode.on('error', function(event) {
event.trigger.textContent = 'Press "Ctrl + C" to copy';
window.setTimeout(function() {
event.trigger.textContent = '';
}, 5000);
});

})();
})();
}
Loading