mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-06 04:52:21 +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"
|
restrict: "A"
|
||||||
require: "tabset"
|
require: "tabset"
|
||||||
link: (scope, el, attrs, tabset) ->
|
link: (scope, el, attrs, tabset) ->
|
||||||
scope.$applyAsync () ->
|
linksToTabs = document.querySelectorAll(".link-to-tab");
|
||||||
hash = $location.hash()
|
_clickLinkToTab = (event) ->
|
||||||
|
_makeActive(event.currentTarget.getAttribute("href").replace('#', ''))
|
||||||
|
|
||||||
|
_makeActive = (hash) ->
|
||||||
if hash? and hash != ""
|
if hash? and hash != ""
|
||||||
matchingTab = _.find tabset.tabs, (tab) ->
|
matchingTab = _.find tabset.tabs, (tab) ->
|
||||||
tab.bookmarkableTabId == hash
|
tab.bookmarkableTabId == hash
|
||||||
|
@ -14,6 +17,14 @@ define [
|
||||||
matchingTab.select()
|
matchingTab.select()
|
||||||
el.children()[0].scrollIntoView({ behavior: "smooth" })
|
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) ->
|
App.directive "bookmarkableTab", ($location) ->
|
||||||
restrict: "A"
|
restrict: "A"
|
||||||
require: "tab"
|
require: "tab"
|
||||||
|
@ -25,6 +36,3 @@ define [
|
||||||
tabScope.$watch "active", (isActive, wasActive) ->
|
tabScope.$watch "active", (isActive, wasActive) ->
|
||||||
if isActive and !wasActive and $location.hash() != tabId
|
if isActive and !wasActive and $location.hash() != tabId
|
||||||
$location.hash tabId
|
$location.hash tabId
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue