13
13
v-bind:value =" markdownBadge"
14
14
wrap =" off"
15
15
></textarea >
16
- <button role =" button" onclick =" console.log('not implemented yet')" >Copy</button >
16
+ <div class =" col" >
17
+ <button
18
+ role =" button"
19
+ v-on:click =" copyButtonClickHandler" >
20
+ Copy
21
+ </button >
22
+ <div class =" copied-text" >
23
+ copied
24
+ </div >
25
+ </div >
17
26
</div >
18
27
19
28
<h3 >
27
36
v-bind:value =" rstBadge"
28
37
wrap =" off"
29
38
></textarea >
30
- <button role =" button" onclick =" console.log('not implemented yet')" >Copy</button >
39
+ <div class =" col" >
40
+ <button
41
+ role =" button"
42
+ v-on:click =" copyButtonClickHandler" >
43
+ Copy
44
+ </button >
45
+ <div class =" copied-text" >
46
+ copied
47
+ </div >
48
+ </div >
31
49
</div >
32
50
33
51
<h3 >
41
59
v-bind:value =" htmlBadge"
42
60
wrap =" off"
43
61
></textarea >
44
- <button role =" button" onclick =" console.log('not implemented yet')" >Copy</button >
62
+ <div class =" col" >
63
+ <button
64
+ role =" button"
65
+ v-on:click =" copyButtonClickHandler" >
66
+ Copy
67
+ </button >
68
+ <div class =" copied-text" >
69
+ copied
70
+ </div >
71
+ </div >
45
72
</div >
46
73
47
74
</div >
@@ -59,12 +86,38 @@ const appBaseUrl = ref('');
59
86
60
87
const htmlBadge = computed (() => ` <a href="${href .value }?${fairQueryParams .value }">\n `
61
88
+ ` <img src="${appBaseUrl .value }badge.svg" `
62
- + ` alt="${alt }">\n </a> ` );
89
+ + ` alt="${alt }">\n </a>\n ` );
63
90
const markdownBadge = computed (() => ` [] `
64
- + ` (${href .value }?${fairQueryParams .value }) ` );
91
+ + ` (${href .value }?${fairQueryParams .value })\n ` );
65
92
const rstBadge = computed (() => ` .. image:: ${appBaseUrl .value }badge.svg\n `
66
93
+ ` :target: ${href .value }?${fairQueryParams .value }\n `
67
- + ` :alt: ${alt } ` );
94
+ + ` :alt: ${alt }\n ` );
95
+
96
+ const copyButtonClickHandler = (event : Event ) => {
97
+ if (event .target === null ) {
98
+ return ;
99
+ }
100
+ const button = event .target as HTMLInputElement ;
101
+ if (button .parentElement === null ) {
102
+ return ;
103
+ }
104
+ if (button .parentElement .previousElementSibling === null ) {
105
+ return ;
106
+ }
107
+ const textArea = button .parentElement .previousElementSibling as HTMLInputElement ;
108
+ const text = textArea .value ;
109
+ navigator .clipboard .writeText (text );
110
+ if (button .nextElementSibling === null ) {
111
+ return ;
112
+ }
113
+ const feedbackString = button .nextElementSibling as HTMLElement ;
114
+ feedbackString .classList .remove (' transparent' );
115
+ feedbackString .classList .add (' opaque' );
116
+ setTimeout (() => {
117
+ feedbackString .classList .remove (' opaque' );
118
+ feedbackString .classList .add (' transparent' );
119
+ }, 1000 );
120
+ };
68
121
69
122
onMounted (() => {
70
123
href .value = ` ${window .location .origin }/${window .location .pathname .split (' /' ).filter (e => e !== ' ' ).join (' /' )} ` ;
@@ -96,7 +149,15 @@ textarea {
96
149
.row {
97
150
display : flex ;
98
151
flex-direction : row ;
99
- flex-wrap : nowrap
152
+ flex-wrap : nowrap ;
153
+ }
154
+
155
+ .col {
156
+ align-items : center ;
157
+ display : flex ;
158
+ flex-direction : column ;
159
+ flex-wrap : nowrap ;
160
+ justify-content : center ;
100
161
}
101
162
102
163
button {
@@ -122,4 +183,19 @@ button:disabled {
122
183
opacity : 0.5 ;
123
184
}
124
185
186
+ .copied-text {
187
+ font-size : 80% ;
188
+ margin-left : 2em ;
189
+ margin-right : 1em ;
190
+ opacity : 0 ;
191
+ }
192
+
193
+ .copied-text.opaque {
194
+ opacity : 1 ;
195
+ transition : opacity 0s ;
196
+ }
197
+ .copied-text.transparent {
198
+ opacity : 0 ;
199
+ transition : opacity 2s ;
200
+ }
125
201
</style >
0 commit comments