2018-09-24 09:43:12 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.directive "bookmarkableTabset", ($location, _) ->
|
|
|
|
restrict: "A"
|
|
|
|
require: "tabset"
|
|
|
|
link: (scope, el, attrs, tabset) ->
|
2018-10-15 16:26:00 -04:00
|
|
|
|
|
|
|
_makeActive = (hash) ->
|
2018-10-15 15:53:52 -04:00
|
|
|
if hash? and hash != ""
|
2018-09-24 09:43:12 -04:00
|
|
|
matchingTab = _.find tabset.tabs, (tab) ->
|
|
|
|
tab.bookmarkableTabId == hash
|
|
|
|
if matchingTab?
|
|
|
|
matchingTab.select()
|
2018-09-25 06:45:29 -04:00
|
|
|
el.children()[0].scrollIntoView({ behavior: "smooth" })
|
2018-09-24 09:43:12 -04:00
|
|
|
|
2018-10-15 16:26:00 -04:00
|
|
|
scope.$applyAsync () ->
|
|
|
|
# for page load
|
|
|
|
hash = $location.hash()
|
|
|
|
_makeActive(hash)
|
|
|
|
|
2018-10-25 11:07:37 -04:00
|
|
|
# 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)
|
|
|
|
|
2018-09-24 09:43:12 -04:00
|
|
|
App.directive "bookmarkableTab", ($location) ->
|
|
|
|
restrict: "A"
|
|
|
|
require: "tab"
|
|
|
|
link: (scope, el, attrs, tab) ->
|
|
|
|
tabScope = el.isolateScope()
|
|
|
|
tabId = attrs.bookmarkableTab
|
|
|
|
if tabScope? and tabId? and tabId != ""
|
|
|
|
tabScope.bookmarkableTabId = tabId
|
|
|
|
tabScope.$watch "active", (isActive, wasActive) ->
|
2018-09-25 06:45:29 -04:00
|
|
|
if isActive and !wasActive and $location.hash() != tabId
|
2018-09-24 09:43:12 -04:00
|
|
|
$location.hash tabId
|