6f3696eafb4b9006227c1d5f42f8ccd6ecb5705e chmalee Thu Sep 18 10:32:02 2025 -0700 Fix tab selection on hgHubConnect to update the url and make the page load the correct tab based on the url, refs Jonathan for the paper diff --git src/hg/js/hgHubConnect.js src/hg/js/hgHubConnect.js index 5d732b652cc..d3373badf65 100644 --- src/hg/js/hgHubConnect.js +++ src/hg/js/hgHubConnect.js @@ -1,15 +1,19 @@ +// "use strict"; +// Don't complain about line break before '||' etc: +/* jshint -W014 */ +/* jshint esversion: 8 */ function makeIframe(ev) { /* It's unusual to show script output in an iframe. But this solution has a few advantages: * - We can show a "waiting" message while the data loads * - The user knows where the results will appear, it looks like a dialog box and covers the page */ ev.stopPropagation(); var validateText = document.getElementById('validateHubUrl'); validateText.value=$.trim(validateText.value); var hubUrl = $('#validateHubUrl').val(); if(!validateUrl(hubUrl)) { alert('Invalid hub URL'); return; } hgsid = document.querySelector("input[name='hgsid']").value; @@ -59,36 +63,47 @@ }, function() { $(this).removeClass("hoverRow"); }); }); // initializes the tabs - with cookie option // cookie option requires jquery.cookie.js $(function() { $("#tabs").tabs({ active: localStorage.getItem("hubTab") !== null ? localStorage.getItem("hubTab") : 0, activate: function(event, ui) { localStorage.setItem("hubTab", ui.newTab.index()); }, }); - // activate tabs if the current URL ends with #dev or #conn + // activate tabs if the current URL ends with the appropriate tab name var tabName = window.location.hash; - if (tabName==="#dev") - $("#tabs").tabs("option", "active", 2); - if (tabName==="#conn") + if (tabName==="publicHubs") + $("#tabs").tabs("option", "active", 0); + if (tabName==="#conn" || tabName === "unlistedHubs") $("#tabs").tabs("option", "active", 1); + if (tabName==="#dev" || tabName === "hubDeveloper") + $("#tabs").tabs("option", "active", 2); + if (tabName==="#hubUpload") + $("#tabs").tabs("option", "active", 3); + + $("#tabs").tabs().on("tabsactivate", function(event, ui) { + const newHash = ui.newTab.find("a").attr("href"); + if (newHash) { + history.replaceState(null, null, newHash); + } + }); }); // creates keyup event; listening for return key press $(document).ready(function() { $('#loadSampleHub').bind('click', function(e) { $('#validateHubUrl').val("https://genome.ucsc.edu/goldenPath/help/examples/hubDirectory/hub.txt"); }); $('#hubUrl').bind('keypress', function(e) { // binds listener to url field if (e.which === 13) { // listens for return key e.preventDefault(); // prevents return from also submitting whole form if (validateUrl($('#hubUrl').val())) $('input[name="hubAddButton"]').focus().click(); // clicks AddHub button } });