Skip to content

Commit 74df7b4

Browse files
author
tyr
committed
Issue #563.
A copy button is now displayed to the user if his browser supports ClipboardJS. Has to be discussed now : how to inform the user that the content has actually been yanked. - tooltip: from scratch, using another library ? - display a message in an existing element of the page: where, and how to render it nicely ?
1 parent 17638f0 commit 74df7b4

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

app/styles/crate.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@
240240
color: white;
241241
padding: 20px;
242242
}
243+
button {
244+
padding:5px;
245+
}
243246

244247
@media only screen and (min-width: 500px) {
245248
.action { @include flex(2); display: block; }

app/templates/crate/version.hbs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@
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>
6164
</div>
6265
</div>
6366
<div class='authorship'>
@@ -271,3 +274,19 @@
271274
</div>
272275
</div>
273276
{{/if}}
277+
278+
<script type="text/javascript">
279+
if (!Clipboard.isSupported()) {
280+
document.getElementById('crate-download-button').classList.add('hidden');
281+
}
282+
283+
var clipboard = new Clipboard('#crate-download-button');
284+
clipboard.on('success', function(e) {
285+
e.clearSelection();
286+
// TODO : Add a tooltip to notify the user that it's copied
287+
});
288+
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
290+
});
291+
292+
</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)