Skip to content

Commit f3bccd7

Browse files
author
tyr
committed
Sends notification to the user if the copy was a success or failed
1 parent 74df7b4 commit f3bccd7

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

app/styles/crate.scss

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,26 @@
243243
button {
244244
padding:5px;
245245
}
246-
247246
@media only screen and (min-width: 500px) {
248247
.action { @include flex(2); display: block; }
249248
code { @include flex(8); }
250249
}
251250
}
251+
.copy-result {
252+
text-align:right;
253+
254+
span {
255+
font-size:80%;
256+
font-weight:bold;
257+
}
258+
.copy-success {
259+
color:$link-color;
260+
}
261+
.copy-failure {
262+
color:red;
263+
}
252264

265+
}
253266
.last-update {
254267
color: $main-color-light;
255268
font-size: 90%;

app/templates/crate/version.hbs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
<img src="/assets/copy.svg" alt="Copy to clipboard" height="25px" />
6363
</button>
6464
</div>
65+
<div class="copy-result">
66+
<span id="copy-notification"></span>
67+
</div>
6568
</div>
6669
<div class='authorship'>
6770
<div class='top'>
@@ -281,12 +284,23 @@
281284
}
282285
283286
var clipboard = new Clipboard('#crate-download-button');
287+
var notificationElement = document.getElementById('copy-notification');
284288
clipboard.on('success', function(e) {
289+
var successText = 'Copied !';
290+
285291
e.clearSelection();
286-
// TODO : Add a tooltip to notify the user that it's copied
292+
notificationElement.classList.add('copy-success')
293+
notificationElement.textContent = successText;
287294
});
288295
clipboard.on('error', function(e) {
289-
// TODO : Add a tooltip to notify the user that the copy failed, so he will have to use CTRL+C
296+
var failureText = 'An error occured. Please use CTRL+C.';
297+
298+
notificationElement.classList.add('copy-failure')
299+
notificationElement.textContent = failureText;
290300
});
291301
302+
window.setTimeout(function() {
303+
notificationElement.innerHTML = '';
304+
}, 2000);
305+
292306
</script>

0 commit comments

Comments
 (0)