overleaf/services/web/public/coffee/directives/bookmarkableTabset.coffee

31 lines
832 B
CoffeeScript
Raw Normal View History

2018-09-24 09:43:12 -04:00
define [
"base"
], (App) ->
App.directive "bookmarkableTabset", ($location, _) ->
restrict: "A"
require: "tabset"
link: (scope, el, attrs, tabset) ->
scope.$applyAsync () ->
hash = $location.hash()
if hash?
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
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