File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import 'bootstrap-select';
2323// Utilities
2424import './src/utils/accordion' ;
2525import './src/utils/autoComplete' ;
26+ import './src/utils/copyToken.js' ;
2627import './src/utils/externalLink' ;
2728import './src/utils/modalSearch' ;
2829import './src/utils/outOfFocus' ;
Original file line number Diff line number Diff line change 1+ const initCopyToken = ( ) => {
2+ document . addEventListener ( 'click' , function ( e ) {
3+ const button = e . target . closest ( '#copy-token-btn' ) ;
4+ if ( ! button ) return ;
5+
6+ e . preventDefault ( ) ;
7+
8+ // Prevent spam clicking
9+ if ( button . disabled ) return ;
10+
11+ const tokenInput = document . getElementById ( 'api-token-val' ) ;
12+ if ( ! tokenInput ) return ;
13+
14+ const originalHTML = button . innerHTML ;
15+
16+ // Disable immediately
17+ button . disabled = true ;
18+
19+ navigator . clipboard . writeText ( tokenInput . value ) . then ( ( ) => {
20+ // Replace button contents with check icon
21+ button . innerHTML = '<i class="fa fa-circle-check" aria-hidden="true"></i>' ;
22+
23+ // Restore after 2s
24+ setTimeout ( ( ) => {
25+ button . innerHTML = originalHTML ;
26+ button . disabled = false ;
27+ } , 2000 ) ;
28+ } ) . catch ( ( ) => {
29+ button . disabled = false ;
30+ alert ( 'Failed to copy token' ) ;
31+ } ) ;
32+ } ) ;
33+ } ;
34+
35+ initCopyToken ( ) ;
You can’t perform that action at this time.
0 commit comments