Skip to content

Commit cdb4f6a

Browse files
committed
Add copyable module and use it for accessions
1 parent 39a1739 commit cdb4f6a

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

app/javascript/packs/application.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ import "packs/autocomplete";
2727
import "packs/dictionary";
2828
import "packs/network";
2929
import "packs/styling";
30+
import "packs/copyable";
3031

app/javascript/packs/copyable.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
$(document).on("turbolinks:load", function() {
2+
$(".copyable:not(:has(.copyer))").each(function() {
3+
var elem = $(this);
4+
var cont = elem.text().replace(/\s+/gm, " ");
5+
var copied = $(
6+
'<span style="display: none;" class="small">' +
7+
'Copied to the clipboard</span>'
8+
);
9+
var btn = $(
10+
'<a class="badge badge-pill badge-primary mx-2 copyer" type="button">' +
11+
'<i class="fas fa-copy mr-1"> </i> Copy</a>'
12+
);
13+
btn.on("click", function() {
14+
navigator.clipboard.writeText(cont);
15+
copied.fadeIn(200).delay(800).fadeOut(800);
16+
});
17+
elem.append(btn);
18+
elem.append(copied);
19+
});
20+
});
21+

app/views/names/_citation.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
<% end %>
139139

140140
<dt><%= fa_icon('barcode') %> Canonical URL</dt>
141-
<dd>
141+
<dd class="copyable">
142142
<%= @name.seqcode_url %>
143143
</dd>
144144
</dl>

app/views/registers/_citation.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="row pl-3">
1818
<dl class="col-md-7">
1919
<dt><%= fa_icon(:barcode) %> SeqCode Registry Accession</dt>
20-
<dd><%= @register.acc_url %></dd>
20+
<dd class="copyable"><%= @register.acc_url %></dd>
2121

2222
<dt><%= fa_icon('clipboard-check') %> Status</dt>
2323
<dd>
@@ -52,7 +52,7 @@
5252

5353
<% if @register.validated? %>
5454
<dt><%= fa_icon('book-open') %> How to cite</dt>
55-
<dd>
55+
<dd class="copyable">
5656
<%= @register.user.display_name %>
5757
(<%= @register.validated_at.year %>).
5858
<%= @register.propose_title.gsub(/\.\z/, '') %>.

0 commit comments

Comments
 (0)