Watch for hash change for tabs

This commit is contained in:
Jessica Lawshe 2018-10-15 15:26:00 -05:00
parent 97fdf72346
commit 1362da710b

View file

@ -5,8 +5,11 @@ define [
restrict: "A"
require: "tabset"
link: (scope, el, attrs, tabset) ->
scope.$applyAsync () ->
hash = $location.hash()
linksToTabs = document.querySelectorAll(".link-to-tab");
_clickLinkToTab = (event) ->
_makeActive(event.currentTarget.getAttribute("href").replace('#', ''))
_makeActive = (hash) ->
if hash? and hash != ""
matchingTab = _.find tabset.tabs, (tab) ->
tab.bookmarkableTabId == hash
@ -14,6 +17,14 @@ 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)
App.directive "bookmarkableTab", ($location) ->
restrict: "A"
require: "tab"
@ -25,6 +36,3 @@ define [
tabScope.$watch "active", (isActive, wasActive) ->
if isActive and !wasActive and $location.hash() != tabId
$location.hash tabId