File tree Expand file tree Collapse file tree 5 files changed +34
-1
lines changed
Expand file tree Collapse file tree 5 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -85,3 +85,4 @@ spacebars
8585check
8686useraccounts:iron-routing
8787pahans:inline-help
88+ zenorocha:clipboard
Original file line number Diff line number Diff line change @@ -177,5 +177,6 @@ yogiben:autoform-modals@0.3.8
177177yogiben:helpers@0.0.6
178178yogiben:mixpanel@0.0.7
179179yogiben:pretty-email@0.0.6
180+ zenorocha:clipboard@1.4.2
180181zimme:active-route@2.3.2
181182zimme:iron-router-active@1.0.4
Original file line number Diff line number Diff 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 - z 0 - 9 A - Z ] { 40 } $ / ,
1414 optional : true ,
Original file line number Diff line number Diff 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+ } ;
Original file line number Diff line number Diff line change 1+ #copyApi {
2+ margin-top : 0.62em ;
3+ }
You can’t perform that action at this time.
0 commit comments