mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Watch for hash change for tabs
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user