From 9b3e03896e8efd3f2db73cd10a631909bbbb1d76 Mon Sep 17 00:00:00 2001 From: "Mark M. Florida" <markflorida@wustl.edu> Date: Thu, 3 Nov 2016 01:44:57 -0500 Subject: [PATCH] Update for hashchange event to handle multiple hash parts - necessary to select a tab when page is loaded via ajax using the url hash. --- .../webapp/xnat-templates/screens/Page.vm | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/webapp/xnat-templates/screens/Page.vm b/src/main/webapp/xnat-templates/screens/Page.vm index 72998018..f0e0f738 100644 --- a/src/main/webapp/xnat-templates/screens/Page.vm +++ b/src/main/webapp/xnat-templates/screens/Page.vm @@ -37,12 +37,26 @@ <script> - XNAT.app.customPage.container = $('#view-page'); - XNAT.app.customPage.getPage(); + (function(){ - window.onhashchange = function(){ - XNAT.app.customPage.getPage(); - } + var sampleUrl = '/page/#/foo/#tab=bar/#panel=baz' + + // save the value for the initial page that's loaded + var page = getUrlHashValue('#/', '/#'); + + XNAT.app.customPage.container = $('#view-page'); + XNAT.app.customPage.getPage(['', '/#']); + + $(window).on('hashchange', function(e){ + e.preventDefault(); + var newPage = getUrlHashValue('#/', '/#'); + // only get a new page if the page part has changed + if (newPage !== page) { + XNAT.app.customPage.getPage([newPage, '/#']); + } + }) + + })(); </script> -- GitLab