mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-08 20:48:41 +00:00
Fix scrollspy.js & use query-string@5 to support IE (#1621)
* Fix scrollspy.js syntax error on IE * Use query-string@5 to support IE
This commit is contained in:
@@ -51,7 +51,7 @@
|
||||
"mkdirp": "^0.5.1",
|
||||
"pako": "1.0.6",
|
||||
"postcss-loader": "^3.0.0",
|
||||
"query-string": "^6.1.0",
|
||||
"query-string": "^5.1.1",
|
||||
"rimraf": "^2.6.2",
|
||||
"rollup": "^0.63.4",
|
||||
"rollup-plugin-babel": "^3.0.7",
|
||||
|
@@ -1,26 +1,31 @@
|
||||
/* eslint-disable no-var */
|
||||
// Inspired by ScrollSpy as in e.g. Bootstrap
|
||||
|
||||
(function() {
|
||||
const OFFSET = 10;
|
||||
let timer;
|
||||
let headingsCache;
|
||||
const findHeadings = () => headingsCache ? headingsCache :
|
||||
document.querySelectorAll('.toc-headings > li > a');
|
||||
const onScroll = () => {
|
||||
var OFFSET = 10;
|
||||
var timer;
|
||||
|
||||
var headingsCache;
|
||||
function findHeadings() {
|
||||
return headingsCache ? headingsCache :
|
||||
document.querySelectorAll('.toc-headings > li > a');
|
||||
}
|
||||
|
||||
function onScroll() {
|
||||
if (timer) { // throttle
|
||||
return;
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
timer = setTimeout(function() {
|
||||
timer = null;
|
||||
let found = false;
|
||||
const headings = findHeadings();
|
||||
for (let i = 0; i < headings.length; i++) {
|
||||
var found = false;
|
||||
var headings = findHeadings();
|
||||
for (var i = 0; i < headings.length; i++) {
|
||||
// if !found and i is the last element, highlight the last
|
||||
let current = !found;
|
||||
var current = !found;
|
||||
if (!found && i < headings.length - 1) {
|
||||
const next = headings[i + 1].href.split('#')[1];
|
||||
const nextHeader = document.getElementById(next);
|
||||
const top = nextHeader.getBoundingClientRect().top;
|
||||
var next = headings[i + 1].href.split('#')[1];
|
||||
var nextHeader = document.getElementById(next);
|
||||
var top = nextHeader.getBoundingClientRect().top;
|
||||
// The following tests whether top + scrollTop
|
||||
// (the top of the header) is greater than scrollTop
|
||||
// (where scrollTop = window.pageYOffset, the top of
|
||||
@@ -35,10 +40,11 @@
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
};
|
||||
}
|
||||
|
||||
document.addEventListener('scroll', onScroll);
|
||||
document.addEventListener('resize', onScroll);
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Cache the headings once the page has fully loaded.
|
||||
headingsCache = findHeadings();
|
||||
onScroll();
|
||||
|
15
yarn.lock
15
yarn.lock
@@ -5958,12 +5958,13 @@ qs@~6.5.1:
|
||||
version "6.5.2"
|
||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
|
||||
|
||||
query-string@^6.1.0:
|
||||
version "6.1.0"
|
||||
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.1.0.tgz#01e7d69f6a0940dac67a937d6c6325647aa4532a"
|
||||
query-string@^5.1.1:
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/query-string/-/query-string-5.1.1.tgz#a78c012b71c17e05f2e3fa2319dd330682efb3cb"
|
||||
dependencies:
|
||||
decode-uri-component "^0.2.0"
|
||||
strict-uri-encode "^2.0.0"
|
||||
object-assign "^4.1.0"
|
||||
strict-uri-encode "^1.0.0"
|
||||
|
||||
querystring-es3@^0.2.0:
|
||||
version "0.2.1"
|
||||
@@ -6879,9 +6880,9 @@ stream-shift@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
|
||||
|
||||
strict-uri-encode@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
|
||||
strict-uri-encode@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
|
||||
|
||||
string-length@^2.0.0:
|
||||
version "2.0.0"
|
||||
|
Reference in New Issue
Block a user