mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-30 14:24:11 +00:00
Merge pull request #2036 from overleaf/jel-footer-link
Support full URLs in link to tabs within the same page GitOrigin-RevId: 50f66c57b2b3e4771b9b9620af9417822956be0a
This commit is contained in:
parent
1b3f4033e7
commit
de60c3d25f
1 changed files with 14 additions and 22 deletions
|
@ -1,35 +1,22 @@
|
|||
/* eslint-disable
|
||||
max-len,
|
||||
no-undef,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS101: Remove unnecessary use of Array.from
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
define(['base'], function(App) {
|
||||
App.directive('bookmarkableTabset', ($location, _) => ({
|
||||
restrict: 'A',
|
||||
require: 'tabset',
|
||||
link(scope, el, attrs, tabset) {
|
||||
const _makeActive = function(hash) {
|
||||
if (hash != null && hash !== '') {
|
||||
if (hash && hash !== '') {
|
||||
const matchingTab = _.find(
|
||||
tabset.tabs,
|
||||
tab => tab.bookmarkableTabId === hash
|
||||
)
|
||||
if (matchingTab != null) {
|
||||
if (matchingTab) {
|
||||
matchingTab.select()
|
||||
return el.children()[0].scrollIntoView({ behavior: 'smooth' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return scope.$applyAsync(function() {
|
||||
scope.$applyAsync(function() {
|
||||
// for page load
|
||||
const hash = $location.hash()
|
||||
_makeActive(hash)
|
||||
|
@ -38,11 +25,16 @@ define(['base'], function(App) {
|
|||
// this needs to be within applyAsync because there could be a link
|
||||
// within a tab to another tab
|
||||
const linksToTabs = document.querySelectorAll('.link-to-tab')
|
||||
const _clickLinkToTab = event =>
|
||||
_makeActive(event.currentTarget.getAttribute('href').replace('#', ''))
|
||||
const _clickLinkToTab = event => {
|
||||
const hash = event.currentTarget
|
||||
.getAttribute('href')
|
||||
.split('#')
|
||||
.pop()
|
||||
_makeActive(hash)
|
||||
}
|
||||
|
||||
if (linksToTabs) {
|
||||
return Array.from(linksToTabs).map(link =>
|
||||
Array.from(linksToTabs).map(link =>
|
||||
link.addEventListener('click', _clickLinkToTab)
|
||||
)
|
||||
}
|
||||
|
@ -50,15 +42,15 @@ define(['base'], function(App) {
|
|||
}
|
||||
}))
|
||||
|
||||
return App.directive('bookmarkableTab', $location => ({
|
||||
App.directive('bookmarkableTab', $location => ({
|
||||
restrict: 'A',
|
||||
require: 'tab',
|
||||
link(scope, el, attrs, tab) {
|
||||
const tabScope = el.isolateScope()
|
||||
const tabId = attrs.bookmarkableTab
|
||||
if (tabScope != null && tabId != null && tabId !== '') {
|
||||
if (tabScope && tabId && tabId !== '') {
|
||||
tabScope.bookmarkableTabId = tabId
|
||||
return tabScope.$watch('active', function(isActive, wasActive) {
|
||||
tabScope.$watch('active', function(isActive, wasActive) {
|
||||
if (isActive && !wasActive && $location.hash() !== tabId) {
|
||||
return $location.hash(tabId)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue