0d4cd5a2b5b893b073cee6fdbcc740503497e20b chmalee Tue Dec 12 11:58:31 2023 -0800 Fix hgSearch show/hide links to not remove event handlers when updating the text after click the link or icon, refs #31501 diff --git src/hg/js/hgSearch.js src/hg/js/hgSearch.js index 723bf6d..fe1d6f2 100644 --- src/hg/js/hgSearch.js +++ src/hg/js/hgSearch.js @@ -530,50 +530,53 @@ } }); } function showMoreResults() { let trackName = this.id.replace(/Results_.*/, ""); let isHidden = $("." + trackName + "_hidden")[0].style.display === "none"; let btnId = this.id.replace(/Link/, "Button"); _.each($("." + trackName + "_hidden"), function(hiddenLi) { if (isHidden) { hiddenLi.style = "display:"; } else { hiddenLi.style = "display: none"; } }); + let isIconClick = this.nodeName !== "A"; + let linkEl = null; + if (isIconClick) {linkEl = this.nextSibling.children[0];} if (isHidden) { - if (this.nextSibling) { + if (isIconClick) { // click on the '+' icon - newText = this.nextSibling.innerHTML.replace(/Show/,"Hide"); - this.nextSibling.innerHTML = newText; + newText = linkEl.textContent.replace(/Show/,"Hide"); + linkEl.textContent = newText; this.src = "../images/remove_sm.gif"; } else { // click on the link text - this.innerHTML = this.innerHTML.replace(/Show/,"Hide"); + this.textContent = this.textContent.replace(/Show/,"Hide"); let img = document.getElementById(btnId); img.src = "../images/remove_sm.gif"; } } else { - if (this.nextSibling) { + if (isIconClick) { // click on the '-' icon - newText = this.nextSibling.innerHTML.replace(/Hide/,"Show"); - this.nextSibling.innerHTML = newText; + newText = linkEl.textContent.replace(/Hide/,"Show"); + linkEl.textContent = newText; this.src = "../images/add_sm.gif"; } else { - this.innerHTML = this.innerHTML.replace(/Hide/,"Show"); + this.textContent = this.textContent.replace(/Hide/,"Show"); let img = document.getElementById(btnId); img.src = "../images/add_sm.gif"; } } } function collapseNode() { var toCollapse = this.parentNode.childNodes[3]; var isHidden = toCollapse.style.display === "none"; if (isHidden) { toCollapse.style = 'display:'; this.src = "../images/remove_sm.gif"; } else