mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-05 23:43:42 +00:00
Watch for hash change for tabs
This commit is contained in:
parent
97fdf72346
commit
1362da710b
1 changed files with 13 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue