29098c97a3550b6caa4eb9e84e51b2dcaf1f7137 max Fri Jul 8 01:54:43 2022 -0700 fixing copy button bug that must have been there forever, thanks to Chris who found it. refs #29713 diff --git src/hg/js/hgHubConnect.js src/hg/js/hgHubConnect.js index d45463b..c9125f2 100644 --- src/hg/js/hgHubConnect.js +++ src/hg/js/hgHubConnect.js @@ -94,55 +94,52 @@ } }); $('#hubSearchTerms').bind('keypress', function(e) { // binds listener to text field if (e.which === 13) { // listens for return key e.preventDefault(); // prevents return from also submitting whole form $('input[name="hubSearchButton"]').focus().click(); // clicks search button } }); $('#hubDbFilter').bind('keypress', function(e) { // binds listener to text field if (e.which === 13) { // listens for return key e.preventDefault(); // prevents return from also submitting whole form $('input[name="hubSearchButton"]').focus().click(); // clicks db filter button } }); $('.pasteIcon').bind('click', function(e) { - // The genome=hg19-part is stored in the <A> element two elements before the icon SVG: - // Because the HTML code generated by the CGI looks like this: + // The hgTracks link is in the <A> element two elements before the icon SVG: // <td> // <a class='hgTracksLink' href="hgTracks?hubUrl=https://hgwdev-kent.gi.ucsc.edu/~kent/t2t/hub/hub2.txt&genome=hub_25068_GCA_009914755&position=lastDbPos">GCA_009914755</a> // <input type="hidden" value="https://hgwdev-kent.gi.ucsc.edu/~kent/t2t/hub/hub2.txt"> - // <svg class="pasteIcon">...</svg> <--- this is e.target + // <svg class="pasteIcon">...</svg> <--- this is e.target of the click handler // </td> - var link = e.target.parentElement.getElementsByClassName("hgTracksLink")[0]; - var href = link.href; - var genomeArg = href.split("&")[1]; + var link = e.target.parentElement.getElementsByClassName("hgTracksLink")[0].href; + var inputEl = e.target.parentElement.getElementsByTagName("input")[0]; // the url is in the <input> element just before the SVG - var copyText = e.target.parentElement.getElementsByTagName("input")[0]; - var myBaseUrl = copyText.baseURI.split('?')[0]; - var hgTracksUrl = myBaseUrl.replace("hgHubConnect", "hgTracks"); - var oldVal = copyText.value; - copyText.value = hgTracksUrl+"?hubUrl="+copyText.value+"&"+genomeArg; - copyText.style.display = 'none'; - copyText.type = 'text'; - copyText.select(); - copyText.setSelectionRange(0, 99999); /* For mobile devices */ + var oldVal = inputEl.value; + // display:none does not work, see https://stackoverflow.com/questions/31593297/using-execcommand-javascript-to-copy-hidden-text-to-clipboard + inputEl.style = "position: absolute; left: -1000px; top: -1000px"; + inputEl.value = link; + inputEl.type = 'text'; + inputEl.select(); + inputEl.setSelectionRange(0, 99999); /* For mobile devices */ document.execCommand('copy'); - copyText.type = 'hidden'; - alert("Copied URL to clipboard"); - copyText.value = oldVal; + + inputEl.type = 'hidden'; + inputEl.value = oldVal; + alert("Copied Genome Browser hub connection URL to clipboard"); }); }); var hubSearchTree = (function() { var treeDiv; // Points to div we live in function hubSearchTreeContextMenuHandler (node, callback) { var nodeType = node.li_attr.nodetype; if (nodeType == 'track') { callback({ 'openConfig': { 'label' : 'Configure this track', 'action' : function () { window.open(node.li_attr.configlink, '_blank');