Skip to content

Commit 9e0aef3

Browse files
committed
Merge branch 'copy-button-merge'
2 parents 205fd2d + f32d300 commit 9e0aef3

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

app/styles/crate.scss

+23-1
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+
cursor: pointer;
250+
}
251+
button:hover {
252+
background: #edebdd;
253+
}
245254
@media only screen and (min-width: 500px) {
246255
.action { @include flex(2); display: block; }
247256
code { @include flex(8); }
248257
}
249258
}
259+
.copy-result {
260+
text-align: right;
250261

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

app/templates/crate/version.hbs

+44-1
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,40 @@
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+
289+
clipboard.on('success', function(e) {
290+
var successText = 'Copied !';
291+
292+
e.clearSelection();
293+
notificationElement.classList.add('copy-success')
294+
notificationElement.textContent = successText;
295+
fadeOffElement(notificationElement, 2000);
296+
});
297+
298+
clipboard.on('error', function(e) {
299+
var failureText = 'An error occured. Please use CTRL+C.';
300+
301+
notificationElement.classList.add('copy-failure')
302+
notificationElement.textContent = failureText;
303+
fadeOffElement(notificationElement, 2000);
304+
});
305+
306+
function fadeOffElement(element, delay) {
307+
setTimeout(function() {
308+
resetElement(element);
309+
}, delay);
310+
}
311+
312+
function resetElement(element) {
313+
element.innerHTML = '';
314+
element.className = '';
315+
}
316+
</script>

bower.json

+2-1
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

+1-1
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

+3
Loading

0 commit comments

Comments
 (0)