diff --git a/services/web/public/coffee/directives/bookmarkableTabset.coffee b/services/web/public/coffee/directives/bookmarkableTabset.coffee index d5b80f23d2..9e5f0be974 100644 --- a/services/web/public/coffee/directives/bookmarkableTabset.coffee +++ b/services/web/public/coffee/directives/bookmarkableTabset.coffee @@ -5,9 +5,6 @@ define [ restrict: "A" require: "tabset" link: (scope, el, attrs, tabset) -> - linksToTabs = document.querySelectorAll(".link-to-tab"); - _clickLinkToTab = (event) -> - _makeActive(event.currentTarget.getAttribute("href").replace('#', '')) _makeActive = (hash) -> if hash? and hash != "" @@ -17,14 +14,22 @@ define [ matchingTab.select() el.children()[0].scrollIntoView({ behavior: "smooth" }) - for link in linksToTabs - link.addEventListener("click", _clickLinkToTab) - scope.$applyAsync () -> # for page load hash = $location.hash() _makeActive(hash) + # for links within page to a tab + # this needs to be within applyAsync because there could be a link + # within a tab to another tab + linksToTabs = document.querySelectorAll(".link-to-tab"); + _clickLinkToTab = (event) -> + _makeActive(event.currentTarget.getAttribute("href").replace('#', '')) + + if linksToTabs + for link in linksToTabs + link.addEventListener("click", _clickLinkToTab) + App.directive "bookmarkableTab", ($location) -> restrict: "A" require: "tab"