mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #944 from sharelatex/jel-linkable-tabs
Linkable tabs directive
This commit is contained in:
commit
96b24a80ca
2 changed files with 40 additions and 0 deletions
|
@ -0,0 +1,38 @@
|
|||
define [
|
||||
"base"
|
||||
], (App) ->
|
||||
App.directive "bookmarkableTabset", ($location, _) ->
|
||||
restrict: "A"
|
||||
require: "tabset"
|
||||
link: (scope, el, attrs, tabset) ->
|
||||
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
|
||||
if matchingTab?
|
||||
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"
|
||||
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) ->
|
||||
if isActive and !wasActive and $location.hash() != tabId
|
||||
$location.hash tabId
|
|
@ -24,6 +24,7 @@ define [
|
|||
"main/affiliations/controllers/UserAffiliationsController"
|
||||
"main/affiliations/factories/UserAffiliationsDataService"
|
||||
"main/keys"
|
||||
"main/cms/blog"
|
||||
"main/cms/index"
|
||||
"analytics/AbTestingManager"
|
||||
"directives/asyncForm"
|
||||
|
@ -36,6 +37,7 @@ define [
|
|||
"directives/selectAll"
|
||||
"directives/maxHeight"
|
||||
"directives/creditCards"
|
||||
"directives/bookmarkableTabset"
|
||||
"services/queued-http"
|
||||
"services/validateCaptcha"
|
||||
"filters/formatDate"
|
||||
|
|
Loading…
Reference in a new issue