From 96310815c574f2aa07c4967781959d48226c867b Mon Sep 17 00:00:00 2001 From: ylemkimon Date: Tue, 21 Aug 2018 08:53:45 +0900 Subject: [PATCH] Remove indexOf & textContent polyfill for IE 8 (#1645) * Remove indexOf polyfill for IE 8 * Remove textContent polyfill for IE 8 --- katex.js | 3 +-- src/functions/sizing.js | 5 ++-- src/utils.js | 51 +---------------------------------------- 3 files changed, 4 insertions(+), 55 deletions(-) diff --git a/katex.js b/katex.js index cb86390d..7840ae69 100644 --- a/katex.js +++ b/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); }; diff --git a/src/functions/sizing.js b/src/functions/sizing.js index 8fe3fa51..3847c66a 100644 --- a/src/functions/sizing.js +++ b/src/functions/sizing.js @@ -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, }; }, diff --git a/src/utils.js b/src/utils.js index 015345ba..87c2cdb8 100644 --- a/src/utils.js +++ b/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(list: Array, 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(list: Array, 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, };