-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from erichalldev/master
- Loading branch information
Showing
4 changed files
with
51 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// pulled from here: https://github.com/slindberg/jquery-scrollparent/blob/master/jquery.scrollparent.js | ||
const getScrollParent = (element: HTMLElement, includeHidden: boolean): HTMLElement => { | ||
let style = getComputedStyle(element); | ||
const excludeStaticParent = style.position === "absolute"; | ||
const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/; | ||
|
||
if (style.position === "fixed") return document.body; | ||
for (let parent = element; (parent = parent.parentElement);) { | ||
style = getComputedStyle(parent); | ||
if (excludeStaticParent && style.position === "static") { | ||
continue; | ||
} | ||
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) return parent; | ||
} | ||
|
||
return document.body; | ||
} | ||
|
||
const scrollResultsIntoView = (resultContainerEl: HTMLElement): void => { | ||
const searchResults = resultContainerEl.querySelectorAll(".search-result-file-matched-text"); | ||
for (const searchResult of Array.from(searchResults)) { | ||
if (searchResult instanceof HTMLElement) { | ||
const scrollParent = getScrollParent(searchResult, true) as HTMLElement; | ||
if (scrollParent) { | ||
scrollParent.scrollTop = searchResult.offsetTop - scrollParent.offsetTop - (scrollParent.offsetHeight / 2) | ||
} | ||
} | ||
} | ||
} | ||
|
||
export { getScrollParent, scrollResultsIntoView} |