1
0
mirror of synced 2025-12-25 11:03:37 -05:00

Merge pull request #7409 from github/repo-sync

repo sync
This commit is contained in:
Octomerger Bot
2021-06-16 08:57:08 +10:00
committed by GitHub
2 changed files with 11 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import Cookies from 'js-cookie'
import { preserveAnchorNodePosition } from 'scroll-anchoring'
import { sendEvent, EventType } from './events'
@@ -29,7 +30,9 @@ export default function displayToolSpecificContent() {
event.preventDefault()
const target = event.target as HTMLElement
highlightTabForTool(target.dataset.tool || '')
showToolSpecificContent(target.dataset.tool || '', toolElements)
preserveAnchorNodePosition(document, () => {
showToolSpecificContent(target.dataset.tool || '', toolElements)
})
// Save this preference as a cookie.
Cookies.set('toolPreferred', target.dataset.tool || '', { sameSite: 'strict', secure: true })
@@ -76,7 +79,8 @@ function getDefaultTool(detectedTools: Array<string>): string {
// If there is a default tool and the tool is present on this page
const defaultToolEl = document.querySelector('[data-default-tool]') as HTMLElement
const defaultToolValue = defaultToolEl.dataset.defaultTool
const defaultToolValue = defaultToolEl ? defaultToolEl.dataset.defaultTool : ''
if (defaultToolValue && detectedTools.includes(defaultToolValue)) {
return defaultToolValue
}

5
javascripts/scroll-anchoring.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
declare module 'scroll-anchoring' {
export function findAnchorNode(document: Document): Node | undefined
export function preserveAnchorNodePosition<T>(document: Document, callback: () => Promise<T> | T): Promise<T>
export function preservePosition<T>(anchorNode: Node, callback: () => Promise<T> | T): Promise<T>
}