Skip to content

Commit 31a5c9a

Browse files
committed
Merge remote-tracking branch 'upstream/pr/570'
2 parents fd7fb05 + 0a92a14 commit 31a5c9a

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

app/styles/crate.scss

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,35 @@
241241
color: white;
242242
padding: 20px;
243243
}
244-
244+
button, button:active {
245+
padding:5px 0;
246+
background-color: #FFFFFF;
247+
border: none;
248+
width: 60px;
249+
}
250+
button:hover{
251+
background: #edebdd;
252+
}
245253
@media only screen and (min-width: 500px) {
246254
.action { @include flex(2); display: block; }
247255
code { @include flex(8); }
248256
}
249257
}
258+
.copy-result {
259+
text-align:right;
250260

261+
span {
262+
font-size:80%;
263+
font-weight:bold;
264+
}
265+
.copy-success {
266+
color:$link-color;
267+
}
268+
.copy-failure {
269+
color:red;
270+
}
271+
272+
}
251273
.last-update {
252274
color: $main-color-light;
253275
font-size: 90%;

app/templates/crate/version.hbs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@
5757
{{/if}}
5858
<div class='install'>
5959
<div class='action'>Cargo.toml</div>
60-
<code>{{ crate.name }} = "{{ currentVersion.num }}"</code>
60+
<code id="crate-toml">{{ crate.name }} = "{{ currentVersion.num }}"</code>
61+
<button id="crate-download-button" data-clipboard-action="copy" data-clipboard-target="#crate-toml">
62+
<img src="/assets/copy.svg" alt="Copy to clipboard" height="25px" />
63+
</button>
64+
</div>
65+
<div class="copy-result">
66+
<span id="copy-notification"></span>
6167
</div>
6268
</div>
6369
<div class='authorship'>
@@ -271,3 +277,39 @@
271277
</div>
272278
</div>
273279
{{/if}}
280+
281+
<script type="text/javascript">
282+
if (!Clipboard.isSupported()) {
283+
document.getElementById('crate-download-button').classList.add('hidden');
284+
}
285+
286+
var clipboard = new Clipboard('#crate-download-button');
287+
var notificationElement = document.getElementById('copy-notification');
288+
clipboard.on('success', function(e) {
289+
var successText = 'Copied !';
290+
291+
e.clearSelection();
292+
notificationElement.classList.add('copy-success')
293+
notificationElement.textContent = successText;
294+
fadeOffElement(notificationElement, 2000);
295+
});
296+
clipboard.on('error', function(e) {
297+
var failureText = 'An error occured. Please use CTRL+C.';
298+
299+
notificationElement.classList.add('copy-failure')
300+
notificationElement.textContent = failureText;
301+
fadeOffElement(notificationElement, 2000);
302+
});
303+
304+
function fadeOffElement(element, delay) {
305+
setTimeout(function() {
306+
resetElement(element);
307+
}, delay);
308+
}
309+
310+
function resetElement(element) {
311+
element.innerHTML = '';
312+
element.className = '';
313+
}
314+
315+
</script>

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"moment": "2.17.1",
99
"moment-timezone": "0.5.11",
1010
"normalize-css": "5.0.0",
11-
"pretender": "1.4.2"
11+
"pretender": "1.4.2",
12+
"clipboard": "1.6.0"
1213
}
1314
}

ember-cli-build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ module.exports = function(defaults) {
2222

2323
app.import('bower_components/moment/moment.js');
2424
app.import('bower_components/normalize-css/normalize.css');
25-
25+
app.import('bower_components/clipboard/dist/clipboard.js');
2626
return app.toTree();
2727
};

public/assets/copy.svg

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)