mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 03:08:40 +00:00
Remove indexOf & textContent polyfill for IE 8 (#1645)
* Remove indexOf polyfill for IE 8 * Remove textContent polyfill for IE 8
This commit is contained in:
committed by
Kevin Barabash
parent
f70222769b
commit
96310815c5
3
katex.js
3
katex.js
@@ -22,7 +22,6 @@ import {
|
||||
PathNode,
|
||||
LineNode,
|
||||
} from "./src/domTree";
|
||||
import utils from "./src/utils";
|
||||
|
||||
import type {SettingsOptions} from "./src/Settings";
|
||||
import type {AnyParseNode} from "./src/parseNode";
|
||||
@@ -42,7 +41,7 @@ let render = function(
|
||||
baseNode: Node,
|
||||
options: SettingsOptions,
|
||||
) {
|
||||
utils.clearNode(baseNode);
|
||||
baseNode.textContent = "";
|
||||
const node = renderToDomTree(expression, options).toNode();
|
||||
baseNode.appendChild(node);
|
||||
};
|
||||
|
@@ -2,7 +2,6 @@
|
||||
import buildCommon from "../buildCommon";
|
||||
import defineFunction from "../defineFunction";
|
||||
import mathMLTree from "../mathMLTree";
|
||||
import utils from "../utils";
|
||||
|
||||
import * as html from "../buildHTML";
|
||||
import * as mml from "../buildMathML";
|
||||
@@ -23,7 +22,7 @@ export function sizingGroup(
|
||||
// Add size-resetting classes to the inner list and set maxFontSize
|
||||
// manually. Handle nested size changes.
|
||||
for (let i = 0; i < inner.length; i++) {
|
||||
const pos = utils.indexOf(inner[i].classes, "sizing");
|
||||
const pos = inner[i].classes.indexOf("sizing");
|
||||
if (pos < 0) {
|
||||
Array.prototype.push.apply(inner[i].classes,
|
||||
options.sizingClasses(baseOptions));
|
||||
@@ -69,7 +68,7 @@ defineFunction({
|
||||
type: "sizing",
|
||||
mode: parser.mode,
|
||||
// Figure out what size to use based on the list of functions above
|
||||
size: utils.indexOf(sizeFuncs, funcName) + 1,
|
||||
size: sizeFuncs.indexOf(funcName) + 1,
|
||||
body,
|
||||
};
|
||||
},
|
||||
|
51
src/utils.js
51
src/utils.js
@@ -6,32 +6,11 @@
|
||||
|
||||
import type {AnyParseNode} from "./parseNode";
|
||||
|
||||
/**
|
||||
* Provide an `indexOf` function which works in IE8, but defers to native if
|
||||
* possible.
|
||||
*/
|
||||
const nativeIndexOf = Array.prototype.indexOf;
|
||||
const indexOf = function<T>(list: Array<T>, elem: T): number {
|
||||
if (list == null) {
|
||||
return -1;
|
||||
}
|
||||
if (nativeIndexOf && list.indexOf === nativeIndexOf) {
|
||||
return list.indexOf(elem);
|
||||
}
|
||||
const l = list.length;
|
||||
for (let i = 0; i < l; i++) {
|
||||
if (list[i] === elem) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return whether an element is contained in a list
|
||||
*/
|
||||
const contains = function<T>(list: Array<T>, elem: T): boolean {
|
||||
return indexOf(list, elem) !== -1;
|
||||
return list.indexOf(elem) !== -1;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -66,31 +45,6 @@ function escape(text: mixed): string {
|
||||
return String(text).replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A function to set the text content of a DOM element in all supported
|
||||
* browsers. Note that we don't define this if there is no document.
|
||||
*/
|
||||
let setTextContent;
|
||||
if (typeof document !== "undefined") {
|
||||
const testNode = document.createElement("span");
|
||||
if ("textContent" in testNode) {
|
||||
setTextContent = function(node: Node, text: string) {
|
||||
node.textContent = text;
|
||||
};
|
||||
} else {
|
||||
setTextContent = function(node: Node, text: string) {
|
||||
node.innerText = text;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A function to clear a node.
|
||||
*/
|
||||
function clearNode(node: Node) {
|
||||
setTextContent(node, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes we want to pull out the innermost element of a group. In most
|
||||
* cases, this will just be the group itself, but when ordgroups and colors have
|
||||
@@ -154,9 +108,6 @@ export default {
|
||||
deflt,
|
||||
escape,
|
||||
hyphenate,
|
||||
indexOf,
|
||||
setTextContent,
|
||||
clearNode,
|
||||
getBaseElem,
|
||||
isCharacterBox,
|
||||
};
|
||||
|
Reference in New Issue
Block a user