mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-13 06:58:40 +00:00
Add an Array.indexOf polyfill and don't depend on underscore.js
Auditors: alpert
This commit is contained in:
@@ -363,7 +363,7 @@ Parser.prototype.parseNucleus = function(pos) {
|
|||||||
if (group) {
|
if (group) {
|
||||||
return new ParseResult(
|
return new ParseResult(
|
||||||
new ParseNode("sizing", {
|
new ParseNode("sizing", {
|
||||||
size: "size" + (_.indexOf(sizeFuncs, nucleus.type) + 1),
|
size: "size" + (sizeFuncs.indexOf(nucleus.type) + 1),
|
||||||
value: group.result
|
value: group.result
|
||||||
}),
|
}),
|
||||||
group.position);
|
group.position);
|
||||||
|
43
utils.js
43
utils.js
@@ -1,17 +1,38 @@
|
|||||||
function fastContains(list, elem) {
|
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
|
||||||
return list.indexOf(elem) !== -1;
|
if (!Array.prototype.indexOf) {
|
||||||
}
|
Array.prototype.indexOf = function (searchElement, fromIndex) {
|
||||||
|
if ( this === undefined || this === null ) {
|
||||||
function slowContains(list, elem) {
|
throw new TypeError( '"this" is null or not defined' );
|
||||||
for (var i = 0; i < list.length; i++) {
|
|
||||||
if (list[i] === elem) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
var length = this.length >>> 0; // Hack to convert object.length to a UInt32
|
||||||
|
|
||||||
|
fromIndex = +fromIndex || 0;
|
||||||
|
|
||||||
|
if (Math.abs(fromIndex) === Infinity) {
|
||||||
|
fromIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fromIndex < 0) {
|
||||||
|
fromIndex += length;
|
||||||
|
if (fromIndex < 0) {
|
||||||
|
fromIndex = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;fromIndex < length; fromIndex++) {
|
||||||
|
if (this[fromIndex] === searchElement) {
|
||||||
|
return fromIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var contains = Array.prototype.indexOf ? fastContains : slowContains;
|
var contains = function(list, elem) {
|
||||||
|
return list.indexOf(elem) !== -1;
|
||||||
|
};
|
||||||
|
|
||||||
var setTextContent;
|
var setTextContent;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user