commit b700cc948218bc1df10c04ecec385b8c5de1045a
parent 99e21b3fee0586d5f247525215388ed5d51c5d86
Author: Davide P. Cervone <dpvc@union.edu>
Date: Wed, 1 May 2013 18:49:07 -0400
IE8 and below doesn't do split() properly, so implement it by hand for those browsers. Fixes a problem with localization substitution in IE8 and below.
Diffstat:
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/unpacked/MathJax.js b/unpacked/MathJax.js
@@ -1075,6 +1075,25 @@ MathJax.Localization = {
// %n or %{n} or %{plural:%n|option1|option1|...} or %c
//
pattern: /%(\d+|\{\d+\}|\{[a-z]+:\%\d+(?:\|(?:%\{\d+\}|%.|[^\}])*)+\}|.)/g,
+
+ SPLIT: ("axb".split(/(x)/).length === 3 ?
+ function (string,regex) {return string.split(regex)} :
+ //
+ // IE8 and below don't do split() correctly when the pattern includes
+ // parentheses (the split should include the matched exrepssions).
+ // So implement it by hand here.
+ //
+ function (string,regex) {
+ var result = [], match, last = 0;
+ regex.lastIndex = 0;
+ while (match = regex.exec(string)) {
+ result.push(string.substr(last,match.index));
+ result.push.apply(result,match.slice(1));
+ last = match.index + match[0].length;
+ }
+ result.push(string.substr(last));
+ return result;
+ }),
_: function (id,phrase) {
if (phrase instanceof Array) {return this.processSnippet(id,phrase)}
@@ -1094,7 +1113,7 @@ MathJax.Localization = {
//
// Split string at escapes and process them individually
//
- var parts = string.split(this.pattern);
+ var parts = this.SPLIT(string,this.pattern);
for (i = 1, m = parts.length; i < m; i += 2) {
var c = parts[i].charAt(0); // first char will be { or \d or a char to be kept literally
if (c >= "0" && c <= "9") { // %n