Skip to content

Commit 1e87fdf

Browse files
author
illya nizyev
committed
Merge pull request #546 from apinf/feature/466-copy-to-clipboard-btn
Feature/466 copy to clipboard btn - closes #466
2 parents 806d6c9 + 9c37c1a commit 1e87fdf

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

.meteor/packages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@ spacebars
8585
check
8686
useraccounts:iron-routing
8787
pahans:inline-help
88+
zenorocha:clipboard

.meteor/versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,6 @@ yogiben:autoform-modals@0.3.8
177177
yogiben:helpers@0.0.6
178178
yogiben:mixpanel@0.0.7
179179
yogiben:pretty-email@0.0.6
180+
zenorocha:clipboard@1.4.2
180181
zimme:active-route@2.3.2
181182
zimme:iron-router-active@1.0.4

both/collections/users.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Schemas.UserProfile = new SimpleSchema({
88
optional: true
99
},
1010
apiKey: {
11-
label: 'API key (optional)',
11+
label: 'API key',
1212
type: String,
1313
regEx: /^[a-z0-9A-Z]{40}$/,
1414
optional: true,

client/views/profile/profile.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,31 @@ AutoForm.hooks({
88
}
99
}
1010
});
11+
12+
Template.profile.rendered = function () {
13+
14+
// initializes button
15+
var copyButton = $("<a class=\"btn btn-default btn-xs\" id=\"copyApi\"> Copy API to clipboard</a>");
16+
17+
// get input field that holds api key
18+
var apiKeyField = $("input[name='profile.apiKey']");
19+
20+
// gets id attribute value from input field
21+
var apiKeyFieldId = apiKeyField.attr('id');
22+
23+
// attaches new attribute with input field id to a button,
24+
// data-clipboard-target attr is required for clipboard.js to work
25+
copyButton.attr("data-clipboard-target", "#" + apiKeyFieldId);
26+
27+
// appends the actual button object next to input field
28+
apiKeyField.next().append(copyButton);
29+
30+
// initializes copy-to-clipboard functionality
31+
new Clipboard("#copyApi");
32+
33+
// adds listener to button and notifies user if text is copied
34+
copyButton.on("click", function () {
35+
copyButton.text("Copied!");
36+
});
37+
38+
};

client/views/profile/profile.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#copyApi{
2+
margin-top: 0.62em;
3+
}

0 commit comments

Comments
 (0)