d6559deec30443e7d05fcb19f363d891780ad420
chmalee
  Fri Jul 12 11:34:48 2024 -0700
Wrap hgGene javascript in IIEF so that we avoid syntax errors about re-declared variables, refs #33216

diff --git src/hg/hgGene/hgGene.c src/hg/hgGene/hgGene.c
index 59c5928..8da0f36 100644
--- src/hg/hgGene/hgGene.c
+++ src/hg/hgGene/hgGene.c
@@ -523,51 +523,55 @@
     dyStringAppend(header, section->longLabel);
     webNewSection("%s",header->string);
     if (isOpen)
 	{
         long startTime = clock1000();
 	section->print(section, conn, geneId);
         section->printTime = clock1000() - startTime;
 	}
     else
 	{
 	printf("Press \"+\" in the title bar above to open this section.");
 	}
     dyStringFree(&header);
     }
 // add some simple javascript that can do the collapse/expand section buttons
+// this code needs to be wrapped in an immediately executable function so that
+// re-clicks don't complain about previously declared variables
 jsInlineF(""
+"(function() {\n"
 "function collapseSection() {\n"
 "    let toCollapse = this.parentNode.nextElementSibling;\n"
 "    let isHidden = toCollapse.style.display === \"none\";\n"
 "    if (isHidden) {\n"
 "        toCollapse.style = \"display: \";\n"
 "        this.src = \"../images/remove.gif\";\n"
 "        this.alt = \"-\";\n"
 "    } else {\n"
 "        this.src = \"../images/add.gif\";\n"
 "        toCollapse.style = \"display: none\";\n"
 "        this.alt = \"+\";\n"
 "    }\n"
 "}\n"
 "\n"
 "let btns = document.querySelectorAll(\"[id$=Btn]\");\n"
 "let i;\n"
 "for (i = 0; i < btns.length; i++) {\n"
 "    btn = btns[i];\n"
 "    btn.addEventListener('click', collapseSection);\n"
 "}\n"
+"})();\n"
 );
 }
 
 void printTiming(struct section *sectionList)
 /* Print timing for each section, if measureTiming is set */
 {
 if (!measureTiming)
     return;
 struct section *section;
 int total = 0;
 printf("<p><b>section, check time, print time, total</b><br>\n");
 for (section = sectionList; section != NULL; section = section->next)
     {
     boolean isOpen = sectionIsOpen(section);
     int sectionTime = section->checkTime + section->printTime;