2eb840e2f6321346a970fc26e010158f57ff7602
max
  Mon Mar 25 07:21:48 2024 -0700
showing view counts in session list and adding the copy to clipboard button here, too, refs #33248

diff --git src/hg/js/utils.js src/hg/js/utils.js
index 0cb4979..c97ddcb 100644
--- src/hg/js/utils.js
+++ src/hg/js/utils.js
@@ -9,49 +9,62 @@
 
 var debug = false;
 
 /* Support these formats for range specifiers.  Note the ()'s around chrom,
  * start and end portions for substring retrieval: */
 var canonicalRangeExp = /^[\s]*([\w._#-]+)[\s]*:[\s]*([-0-9,]+)[\s]*[-_][\s]*([0-9,]+)[\s]*$/;
 var gbrowserRangeExp =  /^[\s]*([\w._#-]+)[\s]*:[\s]*([0-9,]+)[\s]*\.\.[\s]*([0-9,]+)[\s]*$/;
 var lengthRangeExp =    /^[\s]*([\w._#-]+)[\s]*:[\s]*([0-9,]+)[\s]*\+[\s]*([0-9,]+)[\s]*$/;
 var bedRangeExp =       /^[\s]*([\w._#-]+)[\s]+([0-9,]+)[\s]+([0-9,]+)[\s]*$/;
 var sqlRangeExp =       /^[\s]*([\w._#-]+)[\s]*\|[\s]*([0-9,]+)[\s]*\|[\s]*([0-9,]+)[\s]*$/;
 var singleBaseExp =     /^[\s]*([\w._#-]+)[\s]*:[\s]*([0-9,]+)[\s]*$/;
 
 function copyToClipboard(ev) {
     /* copy a piece of text to clipboard. event.target is some DIV or SVG that is an icon. 
      * The attribute data-target of this element is the ID of the element that contains the text to copy. 
+     * The text is either in the attribute data-copy or the innerText.
      * see C function printCopyToClipboardButton(iconId, targetId);
      * */
      
-    var targetId = ev.target.getAttribute("data-target");
+    ev.preventDefault();
+
+    var buttonEl = ev.target.closest("button"); // user can click SVG or BUTTON element
+
+    var targetId = buttonEl.getAttribute("data-target");
+    if (targetId===null)
+        targetId = ev.target.parentNode.getAttribute("data-target");
     var textEl = document.getElementById(targetId);
-    var text = textEl.innerText;
+    var text = textEl.getAttribute("data-copy");
+    if (text===null)
+        text = textEl.innerText;
 
     var textArea = document.createElement("textarea");
     textArea.value = text;
     // Avoid scrolling to bottom
     textArea.style.top = "0";
     textArea.style.left = "0";
     textArea.style.position = "fixed";
     document.body.appendChild(textArea);
     textArea.focus();
     textArea.select();
     document.execCommand('copy');
     document.body.removeChild(textArea);
-    ev.target.innerHTML = 'Copied';
+    if (buttonEl.innerHTML.includes("Clipboard"))
+        buttonEl.innerHTML = 'Copied';
+    else
+        buttonEl.innerHTML = 'OK';
+    ev.preventDefault();
 }
 
 function cfgPageOnVisChange(ev) {
     /* configuration page event listener when user changes visibility in dropdown */
     if (ev.target.value === 'hide')
         ev.target.classList.replace("normalText", "hiddenText");
     else
         ev.target.classList.replace("hiddenText", "normalText");
 }
 
 function cfgPageAddListeners() {
     /* add event listener to dropdowns */
     var els = document.querySelectorAll(".trackVis");
     for (var i=0; i < els.length; i++) {
         var el = els[i];