PageRenderTime 34ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/common/static/js/vendor/mathjax-MathJax-c9db6ac/unpacked/MathJax.js

https://github.com/ngocchung75/edx-platform
JavaScript | 2436 lines | 1824 code | 157 blank | 455 comment | 629 complexity | 2f7d50cbe1cd26a37de9d639d0db031f MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. /*************************************************************
  2. *
  3. * MathJax.js
  4. *
  5. * The main support code for the MathJax Hub, including the
  6. * Ajax, Callback, Messaging, and Object-Oriented Programming
  7. * libraries, as well as the base Jax classes, and startup
  8. * processing code.
  9. *
  10. * ---------------------------------------------------------------------
  11. *
  12. * Copyright (c) 2009-2012 Design Science, Inc.
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License");
  15. * you may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. if (document.getElementById && document.childNodes && document.createElement) {
  27. if (!window.MathJax) {window.MathJax= {}}
  28. if (!MathJax.Hub) { // skip if already loaded
  29. MathJax.version = "2.0";
  30. MathJax.fileversion = "2.0";
  31. /**********************************************************/
  32. (function (BASENAME) {
  33. var BASE = window[BASENAME];
  34. if (!BASE) {BASE = window[BASENAME] = {}}
  35. var PROTO = []; // a static object used to indicate when a prototype is being created
  36. var OBJECT = function (def) {
  37. var obj = def.constructor; if (!obj) {obj = new Function("")}
  38. for (var id in def) {if (id !== 'constructor' && def.hasOwnProperty(id)) {obj[id] = def[id]}}
  39. return obj;
  40. };
  41. var CONSTRUCTOR = function () {
  42. return new Function ("return arguments.callee.Init.call(this,arguments)");
  43. };
  44. //
  45. // Test for Safari 2.x bug (can't replace prototype for result of new Function()).
  46. // (We don't use this version for everyone since it is a closure and we don't need that).
  47. //
  48. var BUGTEST = CONSTRUCTOR(); BUGTEST.prototype = {bug_test: 1};
  49. if (!BUGTEST.prototype.bug_test) {
  50. CONSTRUCTOR = function () {
  51. return function () {return arguments.callee.Init.call(this,arguments)};
  52. };
  53. };
  54. BASE.Object = OBJECT({
  55. constructor: CONSTRUCTOR(),
  56. Subclass: function (def,classdef) {
  57. var obj = CONSTRUCTOR();
  58. obj.SUPER = this; obj.Init = this.Init;
  59. obj.Subclass = this.Subclass; obj.Augment = this.Augment;
  60. obj.protoFunction = this.protoFunction;
  61. obj.can = this.can; obj.has = this.has; obj.isa = this.isa;
  62. obj.prototype = new this(PROTO);
  63. obj.prototype.constructor = obj; // the real constructor
  64. obj.Augment(def,classdef);
  65. return obj;
  66. },
  67. Init: function (args) {
  68. var obj = this;
  69. if (args.length === 1 && args[0] === PROTO) {return obj}
  70. if (!(obj instanceof args.callee)) {obj = new args.callee(PROTO)}
  71. return obj.Init.apply(obj,args) || obj;
  72. },
  73. Augment: function (def,classdef) {
  74. var id;
  75. if (def != null) {
  76. for (id in def) {if (def.hasOwnProperty(id)) {this.protoFunction(id,def[id])}}
  77. // MSIE doesn't list toString even if it is not native so handle it separately
  78. if (def.toString !== this.prototype.toString && def.toString !== {}.toString)
  79. {this.protoFunction('toString',def.toString)}
  80. }
  81. if (classdef != null) {
  82. for (id in classdef) {if (classdef.hasOwnProperty(id)) {this[id] = classdef[id]}}
  83. }
  84. return this;
  85. },
  86. protoFunction: function (id,def) {
  87. this.prototype[id] = def;
  88. if (typeof def === "function") {def.SUPER = this.SUPER.prototype}
  89. },
  90. prototype: {
  91. Init: function () {},
  92. SUPER: function (fn) {return fn.callee.SUPER},
  93. can: function (method) {return typeof(this[method]) === "function"},
  94. has: function (property) {return typeof(this[property]) !== "undefined"},
  95. isa: function (obj) {return (obj instanceof Object) && (this instanceof obj)}
  96. },
  97. can: function (method) {return this.prototype.can.call(this,method)},
  98. has: function (property) {return this.prototype.has.call(this,property)},
  99. isa: function (obj) {
  100. var constructor = this;
  101. while (constructor) {
  102. if (constructor === obj) {return true} else {constructor = constructor.SUPER}
  103. }
  104. return false;
  105. },
  106. SimpleSUPER: OBJECT({
  107. constructor: function (def) {return this.SimpleSUPER.define(def)},
  108. define: function (src) {
  109. var dst = {};
  110. if (src != null) {
  111. for (var id in src) {if (src.hasOwnProperty(id)) {dst[id] = this.wrap(id,src[id])}}
  112. // MSIE doesn't list toString even if it is not native so handle it separately
  113. if (src.toString !== this.prototype.toString && src.toString !== {}.toString)
  114. {dst.toString = this.wrap('toString',src.toString)}
  115. }
  116. return dst;
  117. },
  118. wrap: function (id,f) {
  119. if (typeof(f) === 'function' && f.toString().match(/\.\s*SUPER\s*\(/)) {
  120. var fn = new Function(this.wrapper);
  121. fn.label = id; fn.original = f; f = fn;
  122. fn.toString = this.stringify;
  123. }
  124. return f;
  125. },
  126. wrapper: function () {
  127. var fn = arguments.callee;
  128. this.SUPER = fn.SUPER[fn.label];
  129. try {var result = fn.original.apply(this,arguments)}
  130. catch (err) {delete this.SUPER; throw err}
  131. delete this.SUPER;
  132. return result;
  133. }.toString().replace(/^\s*function\s*\(\)\s*\{\s*/i,"").replace(/\s*\}\s*$/i,""),
  134. toString: function () {
  135. return this.original.toString.apply(this.original,arguments);
  136. }
  137. })
  138. });
  139. })("MathJax");
  140. /**********************************************************/
  141. /*
  142. * Create a callback function from various forms of data:
  143. *
  144. * MathJax.Callback(fn) -- callback to a function
  145. *
  146. * MathJax.Callback([fn]) -- callback to function
  147. * MathJax.Callback([fn,data...])
  148. * -- callback to function with given data as arguments
  149. * MathJax.Callback([object,fn])
  150. * -- call fn with object as "this"
  151. * MathJax.Callback([object,fn,data...])
  152. * -- call fn with object as "this" and data as arguments
  153. * MathJax.Callback(["method",object])
  154. * -- call method of object wth object as "this"
  155. * MathJax.Callback(["method",object,data...])
  156. * -- as above, but with data as arguments to method
  157. *
  158. * MathJax.Callback({hook: fn, data: [...], object: this})
  159. * -- give function, data, and object to act as "this" explicitly
  160. *
  161. * MathJax.Callback("code") -- callback that compiles and executes a string
  162. *
  163. * MathJax.Callback([...],i)
  164. * -- use slice of array starting at i and interpret
  165. * result as above. (Used for passing "arguments" array
  166. * and trimming initial arguments, if any.)
  167. */
  168. /*
  169. * MathJax.Callback.After([...],cb1,cb2,...)
  170. * -- make a callback that isn't called until all the other
  171. * ones are called first. I.e., wait for a union of
  172. * callbacks to occur before making the given callback.
  173. */
  174. /*
  175. * MathJax.Callback.Queue([callback,...])
  176. * -- make a synchronized queue of commands that process
  177. * sequentially, waiting for those that return uncalled
  178. * callbacks.
  179. */
  180. /*
  181. * MathJax.Callback.Signal(name)
  182. * -- finds or creates a names signal, to which listeners
  183. * can be attached and are signaled by messages posted
  184. * to the signal. Responses can be asynchronous.
  185. */
  186. (function (BASENAME) {
  187. var BASE = window[BASENAME];
  188. if (!BASE) {BASE = window[BASENAME] = {}}
  189. //
  190. // Create a callback from an associative array
  191. //
  192. var CALLBACK = function (data) {
  193. var cb = new Function("return arguments.callee.execute.apply(arguments.callee,arguments)");
  194. for (var id in CALLBACK.prototype) {
  195. if (CALLBACK.prototype.hasOwnProperty(id)) {
  196. if (typeof(data[id]) !== 'undefined') {cb[id] = data[id]}
  197. else {cb[id] = CALLBACK.prototype[id]}
  198. }
  199. }
  200. cb.toString = CALLBACK.prototype.toString;
  201. return cb;
  202. };
  203. CALLBACK.prototype = {
  204. isCallback: true,
  205. hook: function () {},
  206. data: [],
  207. object: window,
  208. execute: function () {
  209. if (!this.called || this.autoReset) {
  210. this.called = !this.autoReset;
  211. return this.hook.apply(this.object,this.data.concat([].slice.call(arguments,0)));
  212. }
  213. },
  214. reset: function () {delete this.called},
  215. toString: function () {return this.hook.toString.apply(this.hook,arguments)}
  216. };
  217. var ISCALLBACK = function (f) {
  218. return (typeof(f) === "function" && f.isCallback);
  219. }
  220. //
  221. // Evaluate a string in global context
  222. //
  223. var EVAL = function (code) {return eval.call(window,code)}
  224. EVAL("var __TeSt_VaR__ = 1"); // check if it works in global context
  225. if (window.__TeSt_VaR__) {
  226. try { delete window.__TeSt_VaR__; } // NOTE IE9 throws when in IE7 mode
  227. catch (error) { window.__TeSt_VaR__ = null; }
  228. } else {
  229. if (window.execScript) {
  230. // IE
  231. EVAL = function (code) {
  232. BASE.__code = code;
  233. code = "try {"+BASENAME+".__result = eval("+BASENAME+".__code)} catch(err) {"+BASENAME+".__result = err}";
  234. window.execScript(code);
  235. var result = BASE.__result; delete BASE.__result; delete BASE.__code;
  236. if (result instanceof Error) {throw result}
  237. return result;
  238. }
  239. } else {
  240. // Safari2
  241. EVAL = function (code) {
  242. BASE.__code = code;
  243. code = "try {"+BASENAME+".__result = eval("+BASENAME+".__code)} catch(err) {"+BASENAME+".__result = err}";
  244. var head = (document.getElementsByTagName("head"))[0]; if (!head) {head = document.body}
  245. var script = document.createElement("script");
  246. script.appendChild(document.createTextNode(code));
  247. head.appendChild(script); head.removeChild(script);
  248. var result = BASE.__result; delete BASE.__result; delete BASE.__code;
  249. if (result instanceof Error) {throw result}
  250. return result;
  251. }
  252. }
  253. }
  254. //
  255. // Create a callback from various types of data
  256. //
  257. var USING = function (args,i) {
  258. if (arguments.length > 1) {
  259. if (arguments.length === 2 && !(typeof arguments[0] === 'function') &&
  260. arguments[0] instanceof Object && typeof arguments[1] === 'number')
  261. {args = [].slice.call(args,i)}
  262. else {args = [].slice.call(arguments,0)}
  263. }
  264. if (args instanceof Array && args.length === 1) {args = args[0]}
  265. if (typeof args === 'function') {
  266. if (args.execute === CALLBACK.prototype.execute) {return args}
  267. return CALLBACK({hook: args});
  268. } else if (args instanceof Array) {
  269. if (typeof(args[0]) === 'string' && args[1] instanceof Object &&
  270. typeof args[1][args[0]] === 'function') {
  271. return CALLBACK({hook: args[1][args[0]], object: args[1], data: args.slice(2)});
  272. } else if (typeof args[0] === 'function') {
  273. return CALLBACK({hook: args[0], data: args.slice(1)});
  274. } else if (typeof args[1] === 'function') {
  275. return CALLBACK({hook: args[1], object: args[0], data: args.slice(2)});
  276. }
  277. } else if (typeof(args) === 'string') {
  278. return CALLBACK({hook: EVAL, data: [args]});
  279. } else if (args instanceof Object) {
  280. return CALLBACK(args);
  281. } else if (typeof(args) === 'undefined') {
  282. return CALLBACK({});
  283. }
  284. throw Error("Can't make callback from given data");
  285. };
  286. //
  287. // Wait for a given time to elapse and then perform the callback
  288. //
  289. var DELAY = function (time,callback) {
  290. callback = USING(callback);
  291. callback.timeout = setTimeout(callback,time);
  292. return callback;
  293. };
  294. //
  295. // Callback used by AFTER, QUEUE, and SIGNAL to check if calls have completed
  296. //
  297. var WAITFOR = function (callback,signal) {
  298. callback = USING(callback);
  299. if (!callback.called) {WAITSIGNAL(callback,signal); signal.pending++}
  300. };
  301. var WAITEXECUTE = function () {
  302. var signals = this.signal; delete this.signal;
  303. this.execute = this.oldExecute; delete this.oldExecute;
  304. var result = this.execute.apply(this,arguments);
  305. if (ISCALLBACK(result) && !result.called) {WAITSIGNAL(result,signals)} else {
  306. for (var i = 0, m = signals.length; i < m; i++) {
  307. signals[i].pending--;
  308. if (signals[i].pending <= 0) {signals[i].call()}
  309. }
  310. }
  311. };
  312. var WAITSIGNAL = function (callback,signals) {
  313. if (!(signals instanceof Array)) {signals = [signals]}
  314. if (!callback.signal) {
  315. callback.oldExecute = callback.execute;
  316. callback.execute = WAITEXECUTE;
  317. callback.signal = signals;
  318. } else if (signals.length === 1) {callback.signal.push(signals[0])}
  319. else {callback.signal = callback.signal.concat(signals)}
  320. };
  321. //
  322. // Create a callback that is called when a collection of other callbacks have
  323. // all been executed. If the callback gets called immediately (i.e., the
  324. // others are all already called), check if it returns another callback
  325. // and return that instead.
  326. //
  327. var AFTER = function (callback) {
  328. callback = USING(callback);
  329. callback.pending = 0;
  330. for (var i = 1, m = arguments.length; i < m; i++)
  331. {if (arguments[i]) {WAITFOR(arguments[i],callback)}}
  332. if (callback.pending === 0) {
  333. var result = callback();
  334. if (ISCALLBACK(result)) {callback = result}
  335. }
  336. return callback;
  337. };
  338. //
  339. // An array of prioritized hooks that are executed sequentially
  340. // with a given set of data.
  341. //
  342. var HOOKS = MathJax.Object.Subclass({
  343. //
  344. // Initialize the array and the auto-reset status
  345. //
  346. Init: function (reset) {
  347. this.hooks = [];
  348. this.reset = reset;
  349. },
  350. //
  351. // Add a callback to the list, in priority order (default priority is 10)
  352. //
  353. Add: function (hook,priority) {
  354. if (priority == null) {priority = 10}
  355. if (!ISCALLBACK(hook)) {hook = USING(hook)}
  356. hook.priority = priority;
  357. var i = this.hooks.length;
  358. while (i > 0 && priority < this.hooks[i-1].priority) {i--}
  359. this.hooks.splice(i,0,hook);
  360. return hook;
  361. },
  362. Remove: function (hook) {
  363. for (var i = 0, m = this.hooks.length; i < m; i++) {
  364. if (this.hooks[i] === hook) {this.hooks.splice(i,1); return}
  365. }
  366. },
  367. //
  368. // Execute the list of callbacks, resetting them if requested.
  369. // If any return callbacks, return a callback that will be
  370. // executed when they all have completed.
  371. //
  372. Execute: function () {
  373. var callbacks = [{}];
  374. for (var i = 0, m = this.hooks.length; i < m; i++) {
  375. if (this.reset) {this.hooks[i].reset()}
  376. var result = this.hooks[i].apply(window,arguments);
  377. if (ISCALLBACK(result) && !result.called) {callbacks.push(result)}
  378. }
  379. if (callbacks.length === 1) {return null}
  380. if (callbacks.length === 2) {return callbacks[1]}
  381. return AFTER.apply({},callbacks);
  382. }
  383. });
  384. //
  385. // Run an array of callbacks passing them the given data.
  386. // (Legacy function, since this has been replaced by the HOOKS object).
  387. //
  388. var EXECUTEHOOKS = function (hooks,data,reset) {
  389. if (!hooks) {return null}
  390. if (!(hooks instanceof Array)) {hooks = [hooks]}
  391. if (!(data instanceof Array)) {data = (data == null ? [] : [data])}
  392. var handler = HOOKS(reset);
  393. for (var i = 0, m = hooks.length; i < m; i++) {handler.Add(hooks[i])}
  394. return handler.Execute.apply(handler,data);
  395. };
  396. //
  397. // Command queue that performs commands in order, waiting when
  398. // necessary for commands to complete asynchronousely
  399. //
  400. var QUEUE = BASE.Object.Subclass({
  401. //
  402. // Create the queue and push any commands that are specified
  403. //
  404. Init: function () {
  405. this.pending = 0; this.running = 0;
  406. this.queue = [];
  407. this.Push.apply(this,arguments);
  408. },
  409. //
  410. // Add commands to the queue and run them. Adding a callback object
  411. // (rather than a callback specification) queues a wait for that callback.
  412. // Return the final callback for synchronization purposes.
  413. //
  414. Push: function () {
  415. var callback;
  416. for (var i = 0, m = arguments.length; i < m; i++) {
  417. callback = USING(arguments[i]);
  418. if (callback === arguments[i] && !callback.called)
  419. {callback = USING(["wait",this,callback])}
  420. this.queue.push(callback);
  421. }
  422. if (!this.running && !this.pending) {this.Process()}
  423. return callback;
  424. },
  425. //
  426. // Process the command queue if we aren't waiting on another command
  427. //
  428. Process: function (queue) {
  429. while (!this.running && !this.pending && this.queue.length) {
  430. var callback = this.queue[0];
  431. queue = this.queue.slice(1); this.queue = [];
  432. this.Suspend(); var result = callback(); this.Resume();
  433. if (queue.length) {this.queue = queue.concat(this.queue)}
  434. if (ISCALLBACK(result) && !result.called) {WAITFOR(result,this)}
  435. }
  436. },
  437. //
  438. // Suspend/Resume command processing on this queue
  439. //
  440. Suspend: function () {this.running++},
  441. Resume: function () {if (this.running) {this.running--}},
  442. //
  443. // Used by WAITFOR to restart the queue when an action completes
  444. //
  445. call: function () {this.Process.apply(this,arguments)},
  446. wait: function (callback) {return callback}
  447. });
  448. //
  449. // Create a named signal that listeners can attach to, to be signaled by
  450. // postings made to the signal. Posts are queued if they occur while one
  451. // is already in process.
  452. //
  453. var SIGNAL = QUEUE.Subclass({
  454. Init: function (name) {
  455. QUEUE.prototype.Init.call(this);
  456. this.name = name;
  457. this.posted = []; // the messages posted so far
  458. this.listeners = HOOKS(true); // those with interest in this signal
  459. },
  460. //
  461. // Post a message to the signal listeners, with callback for when complete
  462. //
  463. Post: function (message,callback,forget) {
  464. callback = USING(callback);
  465. if (this.posting || this.pending) {
  466. this.Push(["Post",this,message,callback,forget]);
  467. } else {
  468. this.callback = callback; callback.reset();
  469. if (!forget) {this.posted.push(message)}
  470. this.Suspend(); this.posting = true;
  471. var result = this.listeners.Execute(message);
  472. if (ISCALLBACK(result) && !result.called) {WAITFOR(result,this)}
  473. this.Resume(); delete this.posting;
  474. if (!this.pending) {this.call()}
  475. }
  476. return callback;
  477. },
  478. //
  479. // Clear the post history (so new listeners won't get old messages)
  480. //
  481. Clear: function (callback) {
  482. callback = USING(callback);
  483. if (this.posting || this.pending) {
  484. callback = this.Push(["Clear",this,callback]);
  485. } else {
  486. this.posted = [];
  487. callback();
  488. }
  489. return callback;
  490. },
  491. //
  492. // Call the callback (all replies are in) and process the command queue
  493. //
  494. call: function () {this.callback(this); this.Process()},
  495. //
  496. // A listener calls this to register intrest in the signal (so it will be called
  497. // when posts occur). If ignorePast is true, it will not be sent the post history.
  498. //
  499. Interest: function (callback,ignorePast,priority) {
  500. callback = USING(callback);
  501. this.listeners.Add(callback,priority);
  502. if (!ignorePast) {
  503. for (var i = 0, m = this.posted.length; i < m; i++) {
  504. callback.reset();
  505. var result = callback(this.posted[i]);
  506. if (ISCALLBACK(result) && i === this.posted.length-1) {WAITFOR(result,this)}
  507. }
  508. }
  509. return callback;
  510. },
  511. //
  512. // A listener calls this to remove itself from a signal
  513. //
  514. NoInterest: function (callback) {
  515. this.listeners.Remove(callback);
  516. },
  517. //
  518. // Hook a callback to a particular message on this signal
  519. //
  520. MessageHook: function (msg,callback,priority) {
  521. callback = USING(callback);
  522. if (!this.hooks) {this.hooks = {}; this.Interest(["ExecuteHooks",this])}
  523. if (!this.hooks[msg]) {this.hooks[msg] = HOOKS(true)}
  524. this.hooks[msg].Add(callback,priority);
  525. for (var i = 0, m = this.posted.length; i < m; i++)
  526. {if (this.posted[i] == msg) {callback.reset(); callback(this.posted[i])}}
  527. return callback;
  528. },
  529. //
  530. // Execute the message hooks for the given message
  531. //
  532. ExecuteHooks: function (msg,more) {
  533. var type = ((msg instanceof Array) ? msg[0] : msg);
  534. if (!this.hooks[type]) {return null}
  535. return this.hooks[type].Execute(msg);
  536. }
  537. },{
  538. signals: {}, // the named signals
  539. find: function (name) {
  540. if (!SIGNAL.signals[name]) {SIGNAL.signals[name] = new SIGNAL(name)}
  541. return SIGNAL.signals[name];
  542. }
  543. });
  544. //
  545. // The main entry-points
  546. //
  547. BASE.Callback = BASE.CallBack = USING;
  548. BASE.Callback.Delay = DELAY;
  549. BASE.Callback.After = AFTER;
  550. BASE.Callback.Queue = QUEUE;
  551. BASE.Callback.Signal = SIGNAL.find;
  552. BASE.Callback.Hooks = HOOKS;
  553. BASE.Callback.ExecuteHooks = EXECUTEHOOKS;
  554. })("MathJax");
  555. /**********************************************************/
  556. (function (BASENAME) {
  557. var BASE = window[BASENAME];
  558. if (!BASE) {BASE = window[BASENAME] = {}}
  559. var isSafari2 = (navigator.vendor === "Apple Computer, Inc." &&
  560. typeof navigator.vendorSub === "undefined");
  561. var sheets = 0; // used by Safari2
  562. //
  563. // Update sheets count and look up the head object
  564. //
  565. var HEAD = function (head) {
  566. if (document.styleSheets && document.styleSheets.length > sheets)
  567. {sheets = document.styleSheets.length}
  568. if (!head) {
  569. head = (document.getElementsByTagName("head"))[0];
  570. if (!head) {head = document.body}
  571. }
  572. return head;
  573. };
  574. //
  575. // Remove scripts that are completed so they don't clutter up the HEAD.
  576. // This runs via setTimeout since IE7 can't remove the script while it is running.
  577. //
  578. var SCRIPTS = []; // stores scripts to be removed after a delay
  579. var REMOVESCRIPTS = function () {
  580. for (var i = 0, m = SCRIPTS.length; i < m; i++) {BASE.Ajax.head.removeChild(SCRIPTS[i])}
  581. SCRIPTS = [];
  582. };
  583. BASE.Ajax = {
  584. loaded: {}, // files already loaded
  585. loading: {}, // files currently in process of loading
  586. loadHooks: {}, // hooks to call when files are loaded
  587. timeout: 15*1000, // timeout for loading of files (15 seconds)
  588. styleDelay: 1, // delay to use before styles are available
  589. config: {root: ""}, // URL of root directory to load from
  590. STATUS: {
  591. OK: 1, // file is loading or did load OK
  592. ERROR: -1 // file timed out during load
  593. },
  594. rootPattern: new RegExp("^\\["+BASENAME+"\\]"),
  595. //
  596. // Return a complete URL to a file (replacing the root pattern)
  597. //
  598. fileURL: function (file) {return file.replace(this.rootPattern,this.config.root)},
  599. //
  600. // Load a file if it hasn't been already.
  601. // Make sure the file URL is "safe"?
  602. //
  603. Require: function (file,callback) {
  604. callback = BASE.Callback(callback); var type;
  605. if (file instanceof Object) {for (var i in file) {}; type = i.toUpperCase(); file = file[i]}
  606. else {type = file.split(/\./).pop().toUpperCase()}
  607. file = this.fileURL(file);
  608. // FIXME: check that URL is OK
  609. if (this.loaded[file]) {
  610. callback(this.loaded[file]);
  611. } else {
  612. var FILE = {}; FILE[type] = file;
  613. this.Load(FILE,callback);
  614. }
  615. return callback;
  616. },
  617. //
  618. // Load a file regardless of where it is and whether it has
  619. // already been loaded.
  620. //
  621. Load: function (file,callback) {
  622. callback = BASE.Callback(callback); var type;
  623. if (file instanceof Object) {for (var i in file) {}; type = i.toUpperCase(); file = file[i]}
  624. else {type = file.split(/\./).pop().toUpperCase()}
  625. file = this.fileURL(file);
  626. if (this.loading[file]) {
  627. this.addHook(file,callback);
  628. } else {
  629. this.head = HEAD(this.head);
  630. if (this.loader[type]) {this.loader[type].call(this,file,callback)}
  631. else {throw Error("Can't load files of type "+type)}
  632. }
  633. return callback;
  634. },
  635. //
  636. // Register a load hook for a particular file (it will be called when
  637. // loadComplete() is called for that file)
  638. //
  639. LoadHook: function (file,callback,priority) {
  640. callback = BASE.Callback(callback);
  641. if (file instanceof Object) {for (var i in file) {file = file[i]}}
  642. file = this.fileURL(file);
  643. if (this.loaded[file]) {callback(this.loaded[file])}
  644. else {this.addHook(file,callback,priority)}
  645. return callback;
  646. },
  647. addHook: function (file,callback,priority) {
  648. if (!this.loadHooks[file]) {this.loadHooks[file] = MathJax.Callback.Hooks()}
  649. this.loadHooks[file].Add(callback,priority);
  650. },
  651. //
  652. // Used when files are combined in a preloading configuration file
  653. //
  654. Preloading: function () {
  655. for (var i = 0, m = arguments.length; i < m; i++) {
  656. var file = this.fileURL(arguments[i]);
  657. if (!this.loading[file]) {this.loading[file] = {preloaded: true}}
  658. }
  659. },
  660. //
  661. // Code used to load the various types of files
  662. // (JS for JavaScript, CSS for style sheets)
  663. //
  664. loader: {
  665. //
  666. // Create a SCRIPT tag to load the file
  667. //
  668. JS: function (file,callback) {
  669. var script = document.createElement("script");
  670. var timeout = BASE.Callback(["loadTimeout",this,file]);
  671. this.loading[file] = {
  672. callback: callback,
  673. message: BASE.Message.File(file),
  674. timeout: setTimeout(timeout,this.timeout),
  675. status: this.STATUS.OK,
  676. script: script
  677. };
  678. script.onerror = timeout; // doesn't work in IE and no apparent substitute
  679. script.type = "text/javascript";
  680. script.src = file;
  681. this.head.appendChild(script);
  682. },
  683. //
  684. // Create a LINK tag to load the style sheet
  685. //
  686. CSS: function (file,callback) {
  687. var link = document.createElement("link");
  688. link.rel = "stylesheet"; link.type = "text/css"; link.href = file;
  689. this.loading[file] = {
  690. callback: callback,
  691. message: BASE.Message.File(file),
  692. status: this.STATUS.OK
  693. };
  694. this.head.appendChild(link);
  695. this.timer.create.call(this,[this.timer.file,file],link);
  696. }
  697. },
  698. //
  699. // Timing code for checking when style sheets are available.
  700. //
  701. timer: {
  702. //
  703. // Create the timing callback and start the timing loop.
  704. // We use a delay because some browsers need it to allow the styles
  705. // to be processed.
  706. //
  707. create: function (callback,node) {
  708. callback = BASE.Callback(callback);
  709. if (node.nodeName === "STYLE" && node.styleSheet &&
  710. typeof(node.styleSheet.cssText) !== 'undefined') {
  711. callback(this.STATUS.OK); // MSIE processes style immediately, but doesn't set its styleSheet!
  712. } else if (window.chrome && typeof(window.sessionStorage) !== "undefined" &&
  713. node.nodeName === "STYLE") {
  714. callback(this.STATUS.OK); // Same for Chrome 5 (beta), Grrr.
  715. } else if (isSafari2) {
  716. this.timer.start(this,[this.timer.checkSafari2,sheets++,callback],this.styleDelay);
  717. } else {
  718. this.timer.start(this,[this.timer.checkLength,node,callback],this.styleDelay);
  719. }
  720. return callback;
  721. },
  722. //
  723. // Start the timer for the given callback checker
  724. //
  725. start: function (AJAX,check,delay,timeout) {
  726. check = BASE.Callback(check);
  727. check.execute = this.execute; check.time = this.time;
  728. check.STATUS = AJAX.STATUS; check.timeout = timeout || AJAX.timeout;
  729. check.delay = check.total = 0;
  730. if (delay) {setTimeout(check,delay)} else {check()}
  731. },
  732. //
  733. // Increment the time total, increase the delay
  734. // and test if we are past the timeout time.
  735. //
  736. time: function (callback) {
  737. this.total += this.delay;
  738. this.delay = Math.floor(this.delay * 1.05 + 5);
  739. if (this.total >= this.timeout) {callback(this.STATUS.ERROR); return 1}
  740. return 0;
  741. },
  742. //
  743. // For JS file loads, call the proper routine according to status
  744. //
  745. file: function (file,status) {
  746. if (status < 0) {BASE.Ajax.loadTimeout(file)} else {BASE.Ajax.loadComplete(file)}
  747. },
  748. //
  749. // Call the hook with the required data
  750. //
  751. execute: function () {this.hook.call(this.object,this,this.data[0],this.data[1])},
  752. //
  753. // Safari2 doesn't set the link's stylesheet, so we need to look in the
  754. // document.styleSheets array for the new sheet when it is created
  755. //
  756. checkSafari2: function (check,length,callback) {
  757. if (check.time(callback)) return;
  758. if (document.styleSheets.length > length &&
  759. document.styleSheets[length].cssRules &&
  760. document.styleSheets[length].cssRules.length)
  761. {callback(check.STATUS.OK)} else {setTimeout(check,check.delay)}
  762. },
  763. //
  764. // Look for the stylesheets rules and check when they are defined
  765. // and no longer of length zero. (This assumes there actually ARE
  766. // some rules in the stylesheet.)
  767. //
  768. checkLength: function (check,node,callback) {
  769. if (check.time(callback)) return;
  770. var isStyle = 0; var sheet = (node.sheet || node.styleSheet);
  771. try {if ((sheet.cssRules||sheet.rules||[]).length > 0) {isStyle = 1}} catch(err) {
  772. if (err.message.match(/protected variable|restricted URI/)) {isStyle = 1}
  773. else if (err.message.match(/Security error/)) {
  774. // Firefox3 gives "Security error" for missing files, so
  775. // can't distinguish that from OK files on remote servers.
  776. // or OK files in different directory from local files.
  777. isStyle = 1; // just say it is OK (can't really tell)
  778. }
  779. }
  780. if (isStyle) {
  781. // Opera 9.6 requires this setTimeout
  782. setTimeout(BASE.Callback([callback,check.STATUS.OK]),0);
  783. } else {
  784. setTimeout(check,check.delay);
  785. }
  786. }
  787. },
  788. //
  789. // JavaScript code must call this when they are completely initialized
  790. // (this allows them to perform asynchronous actions before indicating
  791. // that they are complete).
  792. //
  793. loadComplete: function (file) {
  794. file = this.fileURL(file);
  795. var loading = this.loading[file];
  796. if (loading && !loading.preloaded) {
  797. BASE.Message.Clear(loading.message);
  798. clearTimeout(loading.timeout);
  799. if (loading.script) {
  800. if (SCRIPTS.length === 0) {setTimeout(REMOVESCRIPTS,0)}
  801. SCRIPTS.push(loading.script);
  802. }
  803. this.loaded[file] = loading.status; delete this.loading[file];
  804. this.addHook(file,loading.callback);
  805. } else {
  806. if (loading) {delete this.loading[file]}
  807. this.loaded[file] = this.STATUS.OK;
  808. loading = {status: this.STATUS.OK}
  809. }
  810. if (!this.loadHooks[file]) {return null}
  811. return this.loadHooks[file].Execute(loading.status);
  812. },
  813. //
  814. // If a file fails to load within the timeout period (or the onerror handler
  815. // is called), this routine runs to signal the error condition.
  816. //
  817. loadTimeout: function (file) {
  818. if (this.loading[file].timeout) {clearTimeout(this.loading[file].timeout)}
  819. this.loading[file].status = this.STATUS.ERROR;
  820. this.loadError(file);
  821. this.loadComplete(file);
  822. },
  823. //
  824. // The default error hook for file load failures
  825. //
  826. loadError: function (file) {
  827. BASE.Message.Set("File failed to load: "+file,null,2000);
  828. BASE.Hub.signal.Post(["file load error",file]);
  829. },
  830. //
  831. // Defines a style sheet from a hash of style declarations (key:value pairs
  832. // where the key is the style selector and the value is a hash of CSS attributes
  833. // and values).
  834. //
  835. Styles: function (styles,callback) {
  836. var styleString = this.StyleString(styles);
  837. if (styleString === "") {
  838. callback = BASE.Callback(callback);
  839. callback();
  840. } else {
  841. var style = document.createElement("style"); style.type = "text/css";
  842. this.head = HEAD(this.head);
  843. this.head.appendChild(style);
  844. if (style.styleSheet && typeof(style.styleSheet.cssText) !== 'undefined') {
  845. style.styleSheet.cssText = styleString;
  846. } else {
  847. style.appendChild(document.createTextNode(styleString));
  848. }
  849. callback = this.timer.create.call(this,callback,style);
  850. }
  851. return callback;
  852. },
  853. //
  854. // Create a stylesheet string from a style declaration object
  855. //
  856. StyleString: function (styles) {
  857. if (typeof(styles) === 'string') {return styles}
  858. var string = "", id, style;
  859. for (id in styles) {if (styles.hasOwnProperty(id)) {
  860. if (typeof styles[id] === 'string') {
  861. string += id + " {"+styles[id]+"}\n";
  862. } else if (styles[id] instanceof Array) {
  863. for (var i = 0; i < styles[id].length; i++) {
  864. style = {}; style[id] = styles[id][i];
  865. string += this.StyleString(style);
  866. }
  867. } else if (id.substr(0,6) === '@media') {
  868. string += id + " {"+this.StyleString(styles[id])+"}\n";
  869. } else if (styles[id] != null) {
  870. style = [];
  871. for (var name in styles[id]) {if (styles[id].hasOwnProperty(name)) {
  872. if (styles[id][name] != null)
  873. {style[style.length] = name + ': ' + styles[id][name]}
  874. }}
  875. string += id +" {"+style.join('; ')+"}\n";
  876. }
  877. }}
  878. return string;
  879. }
  880. };
  881. })("MathJax");
  882. /**********************************************************/
  883. MathJax.HTML = {
  884. //
  885. // Create an HTML element with given attributes and content.
  886. // The def parameter is an (optional) object containing key:value pairs
  887. // of the attributes and their values, and contents is an (optional)
  888. // array of strings to be inserted as text, or arrays of the form
  889. // [type,def,contents] that describes an HTML element to be inserted
  890. // into the current element. Thus the contents can describe a complete
  891. // HTML snippet of arbitrary complexity. E.g.:
  892. //
  893. // MathJax.HTML.Element("span",{id:"mySpan",style{"font-style":"italic"}},[
  894. // "(See the ",["a",{href:"http://www.mathjax.org"},["MathJax home page"]],
  895. // " for more details.)"]);
  896. //
  897. Element: function (type,def,contents) {
  898. var obj = document.createElement(type);
  899. if (def) {
  900. if (def.style) {
  901. var style = def.style; def.style = {};
  902. for (var id in style) {if (style.hasOwnProperty(id))
  903. {def.style[id.replace(/-([a-z])/g,this.ucMatch)] = style[id]}}
  904. }
  905. MathJax.Hub.Insert(obj,def);
  906. }
  907. if (contents) {
  908. for (var i = 0; i < contents.length; i++) {
  909. if (contents[i] instanceof Array) {
  910. obj.appendChild(this.Element(contents[i][0],contents[i][1],contents[i][2]));
  911. } else {
  912. obj.appendChild(document.createTextNode(contents[i]));
  913. }
  914. }
  915. }
  916. return obj;
  917. },
  918. ucMatch: function (match,c) {return c.toUpperCase()},
  919. addElement: function (span,type,def,contents) {return span.appendChild(this.Element(type,def,contents))},
  920. TextNode: function (text) {return document.createTextNode(text)},
  921. addText: function (span,text) {return span.appendChild(this.TextNode(text))},
  922. //
  923. // Set and get the text of a script
  924. //
  925. setScript: function (script,text) {
  926. if (this.setScriptBug) {script.text = text} else {
  927. while (script.firstChild) {script.removeChild(script.firstChild)}
  928. this.addText(script,text);
  929. }
  930. },
  931. getScript: function (script) {
  932. var text = (script.text === "" ? script.innerHTML : script.text);
  933. return text.replace(/^\s+/,"").replace(/\s+$/,"");
  934. },
  935. //
  936. // Manage cookies
  937. //
  938. Cookie: {
  939. prefix: "mjx",
  940. expires: 365,
  941. //
  942. // Save an object as a named cookie
  943. //
  944. Set: function (name,def) {
  945. var keys = [];
  946. if (def) {
  947. for (var id in def) {if (def.hasOwnProperty(id)) {
  948. keys.push(id+":"+def[id].toString().replace(/&/g,"&&"));
  949. }}
  950. }
  951. var cookie = this.prefix+"."+name+"="+escape(keys.join('&;'));
  952. if (this.expires) {
  953. var time = new Date(); time.setDate(time.getDate() + this.expires);
  954. cookie += '; expires='+time.toGMTString();
  955. }
  956. document.cookie = cookie+"; path=/";
  957. },
  958. //
  959. // Get the contents of a named cookie and incorporate
  960. // it into the given object (or return a fresh one)
  961. //
  962. Get: function (name,obj) {
  963. if (!obj) {obj = {}}
  964. var pattern = new RegExp("(?:^|;\\s*)"+this.prefix+"\\."+name+"=([^;]*)(?:;|$)");
  965. var match = pattern.exec(document.cookie);
  966. if (match && match[1] !== "") {
  967. var keys = unescape(match[1]).split('&;');
  968. for (var i = 0, m = keys.length; i < m; i++) {
  969. match = keys[i].match(/([^:]+):(.*)/);
  970. var value = match[2].replace(/&&/g,'&');
  971. if (value === "true") {value = true} else if (value === "false") {value = false}
  972. else if (value.match(/^-?(\d+(\.\d+)?|\.\d+)$/)) {value = parseFloat(value)}
  973. obj[match[1]] = value;
  974. }
  975. }
  976. return obj;
  977. }
  978. }
  979. };
  980. /**********************************************************/
  981. MathJax.Message = {
  982. ready: false, // used to tell when the styles are available
  983. log: [{}], current: null,
  984. textNodeBug: (navigator.vendor === "Apple Computer, Inc." &&
  985. typeof navigator.vendorSub === "undefined") ||
  986. (window.hasOwnProperty && window.hasOwnProperty("konqueror")), // Konqueror displays some gibberish with text.nodeValue = "..."
  987. styles: {
  988. "#MathJax_Message": {
  989. position: "fixed", left: "1px", bottom: "2px",
  990. 'background-color': "#E6E6E6", border: "1px solid #959595",
  991. margin: "0px", padding: "2px 8px",
  992. 'z-index': "102", color: "black", 'font-size': "80%",
  993. width: "auto", 'white-space': "nowrap"
  994. },
  995. "#MathJax_MSIE_Frame": {
  996. position: "absolute",
  997. top:0, left: 0, width: "0px", 'z-index': 101,
  998. border: "0px", margin: "0px", padding: "0px"
  999. }
  1000. },
  1001. browsers: {
  1002. MSIE: function (browser) {
  1003. MathJax.Hub.config.styles["#MathJax_Message"].position = "absolute";
  1004. MathJax.Message.quirks = (document.compatMode === "BackCompat");
  1005. },
  1006. Chrome: function (browser) {
  1007. MathJax.Hub.config.styles["#MathJax_Message"].bottom = "1.5em";
  1008. MathJax.Hub.config.styles["#MathJax_Message"].left = "1em";
  1009. }
  1010. },
  1011. Init: function (styles) {
  1012. if (styles) {this.ready = true}
  1013. if (!document.body || !this.ready) {return false}
  1014. //
  1015. // ASCIIMathML replaces the entire page with a copy of itself (@#!#%@!!)
  1016. // so check that this.div is still part of the page, otherwise look up
  1017. // the copy and use that.
  1018. //
  1019. if (this.div && this.div.parentNode == null) {
  1020. this.div = document.getElementById("MathJax_Message");
  1021. if (this.div) {this.text = this.div.firstChild}
  1022. }
  1023. if (!this.div) {
  1024. var frame = document.body;
  1025. if (MathJax.Hub.Browser.isMSIE) {
  1026. frame = this.frame = this.addDiv(document.body); frame.removeAttribute("id");
  1027. frame.style.position = "absolute";
  1028. frame.style.border = frame.style.margin = frame.style.padding = "0px";
  1029. frame.style.zIndex = "101"; frame.style.height = "0px";
  1030. frame = this.addDiv(frame);
  1031. frame.id = "MathJax_MSIE_Frame";
  1032. window.attachEvent("onscroll",this.MoveFrame);
  1033. window.attachEvent("onresize",this.MoveFrame);
  1034. this.MoveFrame();
  1035. }
  1036. this.div = this.addDiv(frame); this.div.style.display = "none";
  1037. this.text = this.div.appendChild(document.createTextNode(""));
  1038. }
  1039. return true;
  1040. },
  1041. addDiv: function (parent) {
  1042. var div = document.createElement("div");
  1043. div.id = "MathJax_Message";
  1044. if (parent.firstChild) {parent.insertBefore(div,parent.firstChild)}
  1045. else {parent.appendChild(div)}
  1046. return div;
  1047. },
  1048. MoveFrame: function () {
  1049. var body = (MathJax.Message.quirks ? document.body : document.documentElement);
  1050. var frame = MathJax.Message.frame;
  1051. frame.style.left = body.scrollLeft + 'px';
  1052. frame.style.top = body.scrollTop + 'px';
  1053. frame.style.width = body.clientWidth + 'px';
  1054. frame = frame.firstChild;
  1055. frame.style.height = body.clientHeight + 'px';
  1056. },
  1057. filterText: function (text,n) {
  1058. if (MathJax.Hub.config.messageStyle === "simple") {
  1059. if (text.match(/^Loading /)) {
  1060. if (!this.loading) {this.loading = "Loading "}
  1061. text = this.loading; this.loading += ".";
  1062. } else if (text.match(/^Processing /)) {
  1063. if (!this.processing) {this.processing = "Processing "}
  1064. text = this.processing; this.processing += ".";
  1065. } else if (text.match(/^Typesetting /)) {
  1066. if (!this.typesetting) {this.typesetting = "Typesetting "}
  1067. text = this.typesetting; this.typesetting += ".";
  1068. }
  1069. }
  1070. return text;
  1071. },
  1072. Set: function (text,n,clearDelay) {
  1073. if (this.timer) {clearTimeout(this.timer); delete this.timeout}
  1074. if (n == null) {n = this.log.length; this.log[n] = {}}
  1075. this.log[n].text = text; this.log[n].filteredText = text = this.filterText(text,n);
  1076. if (typeof(this.log[n].next) === "undefined") {
  1077. this.log[n].next = this.current;
  1078. if (this.current != null) {this.log[this.current].prev = n}
  1079. this.current = n;
  1080. }
  1081. if (this.current === n && MathJax.Hub.config.messageStyle !== "none") {
  1082. if (this.Init()) {
  1083. if (this.textNodeBug) {this.div.innerHTML = text} else {this.text.nodeValue = text}
  1084. this.div.style.display = "";
  1085. if (this.status) {window.status = ""; delete this.status}
  1086. } else {
  1087. window.status = text;
  1088. this.status = true;
  1089. }
  1090. }
  1091. if (clearDelay) {setTimeout(MathJax.Callback(["Clear",this,n]),clearDelay)}
  1092. else if (clearDelay == 0) {this.Clear(n,0)}
  1093. return n;
  1094. },
  1095. Clear: function (n,delay) {
  1096. if (this.log[n].prev != null) {this.log[this.log[n].prev].next = this.log[n].next}
  1097. if (this.log[n].next != null) {this.log[this.log[n].next].prev = this.log[n].prev}
  1098. if (this.current === n) {
  1099. this.current = this.log[n].next;
  1100. if (this.text) {
  1101. if (this.div.parentNode == null) {this.Init()} // see ASCIIMathML comments above
  1102. if (this.current == null) {
  1103. if (this.timer) {clearTimeout(this.timer); delete this.timer}
  1104. if (delay == null) {delay = 600}
  1105. if (delay === 0) {this.Remove()}
  1106. else {this.timer = setTimeout(MathJax.Callback(["Remove",this]),delay)}
  1107. } else if (MathJax.Hub.config.messageStyle !== "none") {
  1108. if (this.textNodeBug) {this.div.innerHTML = this.log[this.current].filteredText}
  1109. else {this.text.nodeValue = this.log[this.current].filteredText}
  1110. }
  1111. if (this.status) {window.status = ""; delete this.status}
  1112. } else if (this.status) {
  1113. window.status = (this.current == null ? "" : this.log[this.current].text);
  1114. }
  1115. }
  1116. delete this.log[n].next; delete this.log[n].prev;
  1117. delete this.log[n].filteredText;
  1118. },
  1119. Remove: function () {
  1120. // FIXME: do a fade out or something else interesting?
  1121. this.text.nodeValue = "";
  1122. this.div.style.display = "none";
  1123. },
  1124. File: function (file) {
  1125. var root = MathJax.Ajax.config.root;
  1126. if (file.substr(0,root.length) === root) {file = "[MathJax]"+file.substr(root.length)}
  1127. return this.Set("Loading "+file);
  1128. },
  1129. Log: function () {
  1130. var strings = [];
  1131. for (var i = 1, m = this.log.length; i < m; i++) {strings[i] = this.log[i].text}
  1132. return strings.join("\n");
  1133. }
  1134. };
  1135. /**********************************************************/
  1136. MathJax.Hub = {
  1137. config: {
  1138. root: "",
  1139. config: [], // list of configuration files to load
  1140. styleSheets: [], // list of CSS files to load
  1141. styles: { // styles to generate in-line
  1142. ".MathJax_Preview": {color: "#888"}
  1143. },
  1144. jax: [], // list of input and output jax to load
  1145. extensions: [], // list of extensions to load
  1146. preJax: null, // pattern to remove from before math script tag
  1147. postJax: null, // pattern to remove from after math script tag
  1148. displayAlign: 'center', // how to align displayed equations (left, center, right)
  1149. displayIndent: '0', // indentation for displayed equations (when not centered)
  1150. preRemoveClass: 'MathJax_Preview', // class of objects to remove preceeding math script
  1151. showProcessingMessages: true, // display "Processing math: nn%" messages or not
  1152. messageStyle: "normal", // set to "none" or "simple" (for "Loading..." and "Processing...")
  1153. delayStartupUntil: "none", // set to "onload" to delay setup until the onload handler runs
  1154. // set to "configured" to delay startup until MathJax.Hub.Configured() is called
  1155. // set to a Callback to wait for before continuing with the startup
  1156. skipStartupTypeset: false, // set to true to skip PreProcess and Process during startup
  1157. "v1.0-compatible": true, // set to false to prevent message about configuration change
  1158. elements: [], // array of elements to process when none is given explicitly
  1159. positionToHash: true, // after initial typeset pass, position to #hash location?
  1160. showMathMenu: true, // attach math context menu to typeset math?
  1161. showMathMenuMSIE: true, // separtely determine if MSIE should have math menu
  1162. // (since the code for that is a bit delicate)
  1163. menuSettings: {
  1164. zoom: "None", // when to do MathZoom
  1165. CTRL: false, // require CTRL for MathZoom?
  1166. ALT: false, // require Alt or Option?
  1167. CMD: false, // require CMD?
  1168. Shift: false, // require Shift?
  1169. discoverable: false, // make math menu discoverable on hover?
  1170. zscale: "200%", // the scaling factor for MathZoom
  1171. renderer: "", // set when Jax are loaded
  1172. font: "Auto", // what font HTML-CSS should use
  1173. context: "MathJax", // or "Browser" for pass-through to browser menu
  1174. mpContext: false, // true means pass menu events to MathPlayer in IE
  1175. mpMouse: false, // true means pass mouse events to MathPlayer in IE
  1176. texHints: true // include class names for TeXAtom elements
  1177. },
  1178. errorSettings: {
  1179. message: ["[Math Processing Error]"], // HTML snippet structure for message to use
  1180. style: {color: "#CC0000", "font-style":"italic"} // style for message
  1181. }
  1182. },
  1183. preProcessors: MathJax.Callback.Hooks(true), // list of callbacks for preprocessing (initialized by extensions)
  1184. inputJax: {}, // mime-type mapped to input jax (by registration)
  1185. outputJax: {order:{}}, // mime-type mapped to output jax list (by registration)
  1186. processUpdateTime: 250, // time between screen updates when processing math (milliseconds)
  1187. processUpdateDelay: 10, // pause between screen updates to allow other processing (milliseconds)
  1188. signal: MathJax.Callback.Signal("Hub"), // Signal used for Hub events
  1189. Config: function (def) {
  1190. this.Insert(this.config,def);
  1191. if (this.config.Augment) {this.Augment(this.config.Augment)}
  1192. },
  1193. CombineConfig: function (name,def) {
  1194. var config = this.config, id, parent; name = name.split(/\./);
  1195. for (var i = 0, m = name.length; i < m; i++) {
  1196. id = name[i]; if (!config[id]) {config[id] = {}}
  1197. parent = config; config = config[id];
  1198. }
  1199. parent[id] = config = this.Insert(def,config);
  1200. return config;
  1201. },
  1202. Register: {
  1203. PreProcessor: function () {MathJax.Hub.preProcessors.Add.apply(MathJax.Hub.preProcessors,arguments)},
  1204. MessageHook: function () {return MathJax.Hub.signal.MessageHook.apply(MathJax.Hub.signal,arguments)},
  1205. StartupHook: function () {return MathJax.Hub.Startup.signal.MessageHook.apply(MathJax.Hub.Startup.signal,arguments)},
  1206. LoadHook: function () {return MathJax.Ajax.LoadHook.apply(MathJax.Ajax,arguments)}
  1207. },
  1208. getAllJax: function (element) {
  1209. var jax = [], scripts = this.elementScripts(element);
  1210. for (var i = 0, m = scripts.length; i < m; i++) {
  1211. if (scripts[i].MathJax && scripts[i].MathJax.elementJax)
  1212. {jax.push(scripts[i].MathJax.elementJax)}
  1213. }
  1214. return jax;
  1215. },
  1216. getJaxByType: function (type,element) {
  1217. var jax = [], scripts = this.elementScripts(element);
  1218. for (var i = 0, m = scripts.length; i < m; i++) {
  1219. if (scripts[i].MathJax && scripts[i].MathJax.elementJax &&
  1220. scripts[i].MathJax.elementJax.mimeType === type)
  1221. {jax.push(scripts[i].MathJax.elementJax)}
  1222. }
  1223. return jax;
  1224. },
  1225. getJaxByInputType: function (type,element) {
  1226. var jax = [], scripts = this.elementScripts(element);
  1227. for (var i = 0, m = scripts.length; i < m; i++) {
  1228. if (scripts[i].MathJax && scripts[i].MathJax.elementJax &&
  1229. scripts[i].type && scripts[i].type.replace(/ *;(.|\s)*/,"") === type)
  1230. {jax.push(scripts[i].MathJax.elementJax)}
  1231. }
  1232. return jax;
  1233. },
  1234. getJaxFor: function (element) {
  1235. if (typeof(element) === 'string') {element = document.getElementById(element)}
  1236. if (element && element.MathJax) {return element.MathJax.elementJax}
  1237. if (element && element.isMathJax) {
  1238. while (element && !element.jaxID) {element = element.parentNode}
  1239. if (element) {return MathJax.OutputJax[element.jaxID].getJaxFromMath(element)}
  1240. }
  1241. return null;
  1242. },
  1243. isJax: function (element) {
  1244. if (typeof(element) === 'string') {element = document.getElementById(element)}
  1245. if (element && element.isMathJax) {return 1}
  1246. if (element && element.tagName != null && element.tagName.toLowerCase() === 'script') {
  1247. if (element.MathJax)
  1248. {return (element.MathJax.state === MathJax.ElementJax.STATE.PROCESSED ? 1 : -1)}
  1249. if (element.type && this.inputJax[element.type.replace(/ *;(.|\s)*/,"")]) {return -1}
  1250. }
  1251. return 0;
  1252. },
  1253. setRenderer: function (renderer,type) {
  1254. if (!renderer) return;
  1255. if (!MathJax.OutputJax[renderer]) {
  1256. this.config.menuSettings.renderer = "";
  1257. var file = "[MathJax]/jax/output/"+renderer+"/config.js";
  1258. return MathJax.Ajax.Require(file,["setRenderer",this,renderer,type]);
  1259. } else {
  1260. this.config.menuSettings.renderer = renderer;
  1261. if (type == null) {type = "jax/mml"}
  1262. var jax = this.outputJax;
  1263. if (jax[type] && jax[type].length) {
  1264. if (renderer !== jax[type][0].id) {
  1265. jax[type].unshift(MathJax.OutputJax[renderer]);
  1266. return this.signal.Post(["Renderer Selected",renderer]);
  1267. }
  1268. }
  1269. return null;
  1270. }
  1271. },
  1272. Queue: function () {
  1273. return this.queue.Push.apply(this.queue,arguments);
  1274. },
  1275. Typeset: function (element,callback) {
  1276. if (!MathJax.isReady) return null;
  1277. var ec = this.elementCallback(element,callback);
  1278. var queue = MathJax.Callback.Queue();
  1279. for (var i = 0, m = ec.elements.length; i < m; i++) {
  1280. if (ec.elements[i]) {
  1281. queue.Push(
  1282. ["PreProcess",this,ec.elements[i]],
  1283. ["Process",this,ec.elements[i]]
  1284. );
  1285. }
  1286. }
  1287. return queue.Push(ec.callback);
  1288. },
  1289. PreProcess: function (element,callback) {
  1290. var ec = this.elementCallback(element,callback);
  1291. var queue = MathJax.Callback.Queue();
  1292. for (var i = 0, m = ec.elements.length; i < m; i++) {
  1293. if (ec.elements[i]) {
  1294. queue.Push(
  1295. ["Post",this.signal,["Begin PreProcess",ec.elements[i]]],
  1296. (arguments.callee.disabled? {} : ["Execute",this.preProcessors,ec.elements[i]]),
  1297. ["Post",this.signal,["End PreProcess",ec.elements[i]]]
  1298. );
  1299. }
  1300. }
  1301. return queue.Push(ec.callback);
  1302. },
  1303. Process: function (element,callback) {return this.takeAction("Process",element,callback)},
  1304. Update: function (element,callback) {return this.takeAction("Update",element,callback)},
  1305. Reprocess: function (element,callback) {return this.takeAction("Reprocess",element,callback)},
  1306. Rerender: function (element,callback) {return this.takeAction("Rerender",element,callback)},
  1307. takeAction: function (action,element,callback) {
  1308. var ec = this.elementCallback(element,callback);
  1309. var queue = MathJax.Callback.Queue(["Clear",this.signal]);
  1310. for (var i = 0, m = ec.elements.length; i < m; i++) {
  1311. if (ec.elements[i]) {
  1312. var state = {
  1313. scripts: [], // filled in by prepareScripts
  1314. start: new Date().getTime(), // timer for processing messages
  1315. i: 0, j: 0, // current script, current jax
  1316. jax: {}, // scripts grouped by output jax
  1317. jaxIDs: [] // id's of jax used
  1318. };
  1319. queue.Push(
  1320. ["Post",this.signal,["Begin "+action,ec.elements[i]]],
  1321. ["Post",this.signal,["Begin Math",ec.elements[i],action]],
  1322. ["prepareScripts",this,action,ec.elements[i],state],
  1323. ["Post",this.signal,["Begin Math Input",ec.elements[i],action]],
  1324. ["processInput",this,state],
  1325. ["Post",this.signal,["End Math Input",ec.elements[i],action]],
  1326. ["prepareOutput",this,state,"preProcess"],
  1327. ["Post",this.signal,["Begin Math Output",ec.elements[i],action]],
  1328. ["processOutput",this,state],
  1329. ["Post",this.signal,["End Math Output",ec.elements[i],action]],
  1330. ["prepareOutput",this,state,"postProcess"],
  1331. ["Post",this.signal,["End Math",ec.elements[i],action]],
  1332. ["Post",this.signal,["End "+action,ec.elements[i]]]
  1333. );
  1334. }
  1335. }
  1336. return queue.Push(ec.callback);
  1337. },
  1338. scriptAction: {
  1339. Process: function (script) {},
  1340. Update: function (script) {
  1341. var jax = script.MathJax.elementJax;
  1342. if (jax && jax.needsUpdate()) {jax.Remove(true); script.MathJax.state = jax.STATE.UPDATE}
  1343. else {script.MathJax.state = jax.STATE.PROCESSED}
  1344. },
  1345. Reprocess: function (script) {
  1346. var jax = script.MathJax.elementJax;
  1347. if (jax) {jax.Remove(true); script.MathJax.state = jax.STATE.UPDATE}
  1348. },
  1349. Rerender: function (script) {
  1350. var jax = script.MathJax.elementJax;
  1351. if (jax) {jax.Remove(true); script.MathJax.state = jax.STATE.OUTPUT}
  1352. }
  1353. },
  1354. prepareScripts: function (action,element,state) {
  1355. if (arguments.callee.disabled) return;
  1356. var scripts = this.elementScripts(element);
  1357. var STATE = MathJax.ElementJax.STATE;
  1358. for (var i = 0, m = scripts.length; i < m; i++) {
  1359. var script = scripts[i];
  1360. if (script.type && this.inputJax[script.type.replace(/ *;(.|\n)*/,"")]) {
  1361. if (script.MathJax) {
  1362. if (script.MathJax.elementJax && script.MathJax.elementJax.hover) {
  1363. MathJax.Extension.MathEvents.Hover.ClearHover(script.MathJax.elementJax);
  1364. }
  1365. if (script.MathJax.state !== STATE.PENDING) {this.scriptAction[action](script)}
  1366. }
  1367. if (!script.MathJax) {script.MathJax = {state: STATE.PENDING}}
  1368. if (script.MathJax.state !== STATE.PROCESSED) {state.scripts.push(script)}
  1369. }
  1370. }
  1371. },
  1372. checkScriptSiblings: function (script) {
  1373. if (script.MathJax.checked) return;
  1374. var config = this.config, pre = script.previousSibling;
  1375. if (pre && pre.nodeName === "#text") {
  1376. var preJax,postJax, post = script.nextSibling;
  1377. if (post && post.nodeName !== "#text") {post = null}
  1378. if (config.preJax) {
  1379. if (typeof(config.preJax) === "string") {config.preJax = new RegExp(config.preJax+"$")}
  1380. preJax = pre.nodeValue.match(config.preJax);
  1381. }
  1382. if (config.postJax && post) {
  1383. if (typeof(config.postJax) === "string") {config.postJax = new RegExp("^"+config.postJax)}
  1384. postJax = post.nodeValue.match(config.postJax);
  1385. }
  1386. if (preJax && (!config.postJax || postJax)) {
  1387. pre.nodeValue = pre.nodeValue.replace
  1388. (config.preJax,(preJax.length > 1? preJax[1] : ""));
  1389. pre = null;
  1390. }
  1391. if (postJax && (!config.preJax || preJax)) {
  1392. post.nodeValue = post.nodeValue.replace
  1393. (config.postJax,(postJax.length > 1? postJax[1] : ""));
  1394. }
  1395. if (pre && !pre.nodeValue.match(/\S/)) {pre = pre.previousSibling}
  1396. }
  1397. if (config.preRemoveClass && pre && pre.className === config.preRemoveClass)
  1398. {script.MathJax.preview = pre}
  1399. script.MathJax.checked = 1;
  1400. },
  1401. processInput: function (state) {
  1402. var jax, STATE = MathJax.ElementJax.STATE;
  1403. var script, prev, m = state.scripts.length;
  1404. try {
  1405. //
  1406. // Loop through the scripts
  1407. //
  1408. while (state.i < m) {
  1409. script = state.scripts[state.i]; if (!script) {state.i++; continue}
  1410. //
  1411. // Remove previous error marker, if any
  1412. //
  1413. prev = script.previousSibling;
  1414. if (prev && prev.className === "MathJax_Error") {prev.parentNode.removeChild(prev)}
  1415. //
  1416. // Check if already processed or needs processing
  1417. //
  1418. if (!script.MathJax || script.MathJax.state === STATE.PROCESSED) {state.i++; continue};
  1419. if (!script.MathJax.elementJax || script.MathJax.state === STATE.UPDATE) {
  1420. this.checkScriptSiblings(script); // remove preJax/postJax etc.
  1421. var type = script.type.replace(/ *;(.|\s)*/,""); // the input jax type
  1422. jax = this.inputJax[type].Process(script,state); // run the input jax
  1423. if (typeof jax === 'function') { // if a callback was returned
  1424. if (jax.called) continue; // go back and call Process() again
  1425. this.RestartAfter(jax); // wait for the callback
  1426. }
  1427. jax.Attach(script,this.inputJax[type].id); // register the jax on the script
  1428. this.saveScript(jax,state,script,STATE); // add script to state
  1429. } else if (script.MathJax.state === STATE.OUTPUT) {
  1430. this.saveScript(script.MathJax.elementJax,state,script,STATE); // add script to state
  1431. }
  1432. //
  1433. // Go on to the next script, and check if we need to update the processing message
  1434. //
  1435. state.i++; var now = new Date().getTime();
  1436. if (now - state.start > this.processUpdateTime && state.i < state.scripts.length)
  1437. {state.start = now; this.RestartAfter(MathJax.Callback.Delay(1))}
  1438. }
  1439. } catch (err) {return this.processError(err,state,"Input")}
  1440. //
  1441. // Put up final message, reset the state and return
  1442. //
  1443. if (state.scripts.length && this.config.showProcessingMessages)
  1444. {MathJax.Message.Set("Processing math: 100%",0)}
  1445. state.start = new Date().getTime(); state.i = state.j = 0;
  1446. return null;
  1447. },
  1448. saveScript: function (jax,state,script,STATE) {
  1449. //
  1450. // Check that output jax exists
  1451. //
  1452. if (!this.outputJax[jax.mimeType]) {
  1453. script.MathJax.state = STATE.UPDATE;
  1454. throw Error("No output jax registered for "+jax.mimeType);
  1455. }
  1456. //
  1457. // Record the output jax
  1458. // and put this script in the queue for that jax
  1459. //
  1460. jax.outputJax = this.outputJax[jax.mimeType][0].id;
  1461. if (!state.jax[jax.outputJax]) {
  1462. if (state.jaxIDs.length === 0) {
  1463. // use original array until we know there are more (rather than two copies)
  1464. state.jax[jax.outputJax] = state.scripts;
  1465. } else {
  1466. if (state.jaxIDs.length === 1) // get the script so far for the existing jax
  1467. {state.jax[state.jaxIDs[0]] = state.scripts.slice(0,state.i)}
  1468. state.jax[jax.outputJax] = []; // start a new array for the new jax
  1469. }
  1470. state.jaxIDs.push(jax.outputJax); // save the ID of the jax
  1471. }
  1472. if (state.jaxIDs.length > 1) {state.jax[jax.outputJax].push(script)}
  1473. //
  1474. // Mark script as needing output
  1475. //
  1476. script.MathJax.state = STATE.OUTPUT;
  1477. },
  1478. //
  1479. // Pre- and post-process scripts by jax
  1480. // (to get scaling factors, hide/show output, and so on)
  1481. // Since this can cause the jax to load, we need to trap restarts
  1482. //
  1483. prepareOutput: function (state,method) {
  1484. while (state.j < state.jaxIDs.length) {
  1485. var id = state.jaxIDs[state.j], JAX = MathJax.OutputJax[id];
  1486. if (JAX[method]) {
  1487. try {
  1488. var result = JAX[method](state);
  1489. if (typeof result === 'function') {
  1490. if (result.called) continue; // go back and try again
  1491. this.RestartAfter(result);
  1492. }
  1493. } catch (err) {
  1494. if (!err.restart) {
  1495. MathJax.Message.Set("Error preparing "+id+" output ("+method+")",null,600);
  1496. MathJax.Hub.lastPrepError = err;
  1497. state.j++;
  1498. }
  1499. return MathJax.Callback.After(["prepareOutput",this,state,method],err.restart);
  1500. }
  1501. }
  1502. state.j++;
  1503. }
  1504. return null;
  1505. },
  1506. processOutput: function (state) {
  1507. var result, STATE = MathJax.ElementJax.STATE, script, m = state.scripts.length;
  1508. try {
  1509. //
  1510. // Loop through the scripts
  1511. //
  1512. while (state.i < m) {
  1513. //
  1514. // Check that there is an element jax
  1515. //
  1516. script = state.scripts[state.i]; if (!script || !script.MathJax) {state.i++; continue}
  1517. var jax = script.MathJax.elementJax; if (!jax) {state.i++; continue}
  1518. //
  1519. // Call the output Jax's Process method (which will be its Translate()
  1520. // method once loaded). Mark it as complete and remove the preview.
  1521. //
  1522. result = MathJax.OutputJax[jax.outputJax].Process(script,state);
  1523. script.MathJax.state = STATE.PROCESSED; state.i++;
  1524. if (script.MathJax.preview) {script.MathJax.preview.innerHTML = ""}
  1525. //
  1526. // Signal that new math is available
  1527. //
  1528. this.signal.Post(["New Math",jax.inputID]); // FIXME: wait for this? (i.e., restart if returns uncalled callback)
  1529. //
  1530. // Update the processing message, if needed
  1531. //
  1532. var now = new Date().getTime();
  1533. if (now - state.start > this.processUpdateTime && state.i < state.scripts.length)
  1534. {state.start = now; this.RestartAfter(MathJax.Callback.Delay(this.processUpdateDelay))}
  1535. }
  1536. } catch (err) {return this.processError(err,state,"Output")}
  1537. //
  1538. // Put up the typesetting-complete message
  1539. //
  1540. if (state.scripts.length && this.config.showProcessingMessages) {
  1541. MathJax.Message.Set("Typesetting math: 100%",0);
  1542. MathJax.Message.Clear(0);
  1543. }
  1544. state.i = state.j = 0;
  1545. return null;
  1546. },
  1547. processMessage: function (state,type) {
  1548. var m = Math.floor(state.i/(state.scripts.length)*100);
  1549. var message = (type === "Output" ? "Typesetting" : "Processing");
  1550. if (this.config.showProcessingMessages) {MathJax.Message.Set(message+" math: "+m+"%",0)}
  1551. },
  1552. processError: function (err,state,type) {
  1553. if (!err.restart) {
  1554. if (!this.config.errorSettings.message) {throw err}
  1555. this.formatError(state.scripts[state.i],err); state.i++;
  1556. }
  1557. this.processMessage(state,type);
  1558. return MathJax.Callback.After(["process"+type,this,state],err.restart);
  1559. },
  1560. formatError: function (script,err) {
  1561. var error = MathJax.HTML.Element("span",{className:"MathJax_Error"},this.config.errorSettings.message);
  1562. error.jaxID = "Error";
  1563. if (MathJax.Extension.MathEvents) {
  1564. error.oncontextmenu = MathJax.Extension.MathEvents.Event.Menu;
  1565. error.onmousedown = MathJax.Extension.MathEvents.Event.Mousedown;
  1566. } else {
  1567. MathJax.Ajax.Require("[MathJax]/extensions/MathEvents.js",function () {
  1568. error.oncontextmenu = MathJax.Extension.MathEvents.Event.Menu;
  1569. error.onmousedown = MathJax.Extension.MathEvents.Event.Mousedown;
  1570. });
  1571. }
  1572. script.parentNode.insertBefore(error,script);
  1573. if (script.MathJax.preview) {script.MathJax.preview.innerHTML = ""}
  1574. this.lastError = err;
  1575. },
  1576. RestartAfter: function (callback) {
  1577. throw this.Insert(Error("restart"),{restart: MathJax.Callback(callback)});
  1578. },
  1579. elementCallback: function (element,callback) {
  1580. if (callback == null && (element instanceof Array || typeof element === 'function'))
  1581. {try {MathJax.Callback(element); callback = element; element = null} catch(e) {}}
  1582. if (element == null) {element = this.config.elements || []}
  1583. if (!(element instanceof Array)) {element = [element]}
  1584. element = [].concat(element); // make a copy so the original isn't changed
  1585. for (var i = 0, m = element.length; i < m; i++)
  1586. {if (typeof(element[i]) === 'string') {element[i] = document.getElementById(element[i])}}
  1587. if (element.length == 0) {element.push(document.body)}
  1588. if (!callback) {callback = {}}
  1589. return {elements: element, callback: callback};
  1590. },
  1591. elementScripts: function (element) {
  1592. if (typeof(element) === 'string') {element = document.getElementById(element)}
  1593. if (element == null) {element = document.body}
  1594. if (element.tagName != null && element.tagName.toLowerCase() === "script") {return [element]}
  1595. return element.getElementsByTagName("script");
  1596. },
  1597. Insert: function (dst,src) {
  1598. for (var id in src) {if (src.hasOwnProperty(id)) {
  1599. // allow for concatenation of arrays?
  1600. if (typeof src[id] === 'object' && !(src[id] instanceof Array) &&
  1601. (typeof dst[id] === 'object' || typeof dst[id] === 'function')) {
  1602. this.Insert(dst[id],src[id]);
  1603. } else {
  1604. dst[id] = src[id];
  1605. }
  1606. }}
  1607. return dst;
  1608. }
  1609. };
  1610. MathJax.Hub.Insert(MathJax.Hub.config.styles,MathJax.Message.styles);
  1611. MathJax.Hub.Insert(MathJax.Hub.config.styles,{".MathJax_Error":MathJax.Hub.config.errorSettings.style});
  1612. //
  1613. // Storage area for extensions and preprocessors
  1614. //
  1615. MathJax.Extension = {};
  1616. //
  1617. // Hub Startup code
  1618. //
  1619. MathJax.Hub.Configured = MathJax.Callback({}); // called when configuration is complete
  1620. MathJax.Hub.Startup = {
  1621. script: "", // the startup script from the SCRIPT call that loads MathJax.js
  1622. queue: MathJax.Callback.Queue(), // Queue used for startup actions
  1623. signal: MathJax.Callback.Signal("Startup"), // Signal used for startup events
  1624. params: {},
  1625. //
  1626. // Load the configuration files
  1627. //
  1628. Config: function () {
  1629. this.queue.Push(["Post",this.signal,"Begin Config"]);
  1630. //
  1631. // Check for user cookie configuration
  1632. //
  1633. var user = MathJax.HTML.Cookie.Get("user");
  1634. if (user.URL || user.Config) {
  1635. if (confirm(
  1636. "MathJax has found a user-configuration cookie that includes code to be run. " +
  1637. "Do you want to run it?\n\n"+
  1638. "(You should press Cancel unless you set up the cookie yourself.)"
  1639. )) {
  1640. if (user.URL) {this.queue.Push(["Require",MathJax.Ajax,user.URL])}
  1641. if (user.Config) {this.queue.Push(new Function(user.Config))}
  1642. } else {MathJax.HTML.Cookie.Set("user",{})}
  1643. }
  1644. //
  1645. // Run the config files, if any are given in the parameter list
  1646. //
  1647. if (this.params.config) {
  1648. var files = this.params.config.split(/,/);
  1649. for (var i = 0, m = files.length; i < m; i++) {
  1650. if (!files[i].match(/\.js$/)) {files[i] += ".js"}
  1651. this.queue.Push(["Require",MathJax.Ajax,this.URL("config",files[i])]);
  1652. }
  1653. }
  1654. //
  1655. // Run the deprecated configuration script, if any (ignoring return value)
  1656. // Wait for the startup delay signal
  1657. // Run the mathjax-config blocks
  1658. // Handle the default configuration (v1.0 compatible)
  1659. // Load the files in the configuration's config array
  1660. //
  1661. if (this.script.match(/\S/)) {this.queue.Push(this.script+";\n1;")}
  1662. this.queue.Push(
  1663. ["ConfigDelay",this],
  1664. ["ConfigBlocks",this],
  1665. ["ConfigDefault",this],
  1666. [function (THIS) {return THIS.loadArray(MathJax.Hub.config.config,"config",null,true)},this],
  1667. ["Post",this.signal,"End Config"]
  1668. );
  1669. },
  1670. //
  1671. // Return the delay callback
  1672. //
  1673. ConfigDelay: function () {
  1674. var delay = this.params.delayStartupUntil || MathJax.Hub.config.delayStartupUntil;
  1675. if (delay === "onload") {return this.onload}
  1676. if (delay === "configured") {return MathJax.Hub.Configured}
  1677. return delay;
  1678. },
  1679. //
  1680. // Run the scipts of type=text/x-mathajx-config
  1681. //
  1682. ConfigBlocks: function () {
  1683. var scripts = document.getElementsByTagName("script");
  1684. var last = null, queue = MathJax.Callback.Queue();
  1685. for (var i = 0, m = scripts.length; i < m; i++) {
  1686. var type = String(scripts[i].type).replace(/ /g,"");
  1687. if (type.match(/^text\/x-mathjax-config(;.*)?$/) && !type.match(/;executed=true/)) {
  1688. scripts[i].type += ";executed=true";
  1689. last = queue.Push(scripts[i].innerHTML+";\n1;");
  1690. }
  1691. }
  1692. return last;
  1693. },
  1694. //
  1695. // Check for v1.0 no-configuration and put up a warning message.
  1696. //
  1697. ConfigDefault: function () {
  1698. var CONFIG = MathJax.Hub.config;
  1699. if (CONFIG["v1.0-compatible"] && (CONFIG.jax||[]).length === 0 &&
  1700. !this.params.config && (CONFIG.config||[]).length === 0)
  1701. {return MathJax.Ajax.Require(this.URL("extensions","v1.0-warning.js"))}
  1702. },
  1703. //
  1704. // Read cookie and set up menu defaults
  1705. // (adjust the jax to accommodate renderer preferences)
  1706. //
  1707. Cookie: function () {
  1708. return this.queue.Push(
  1709. ["Post",this.signal,"Begin Cookie"],
  1710. ["Get",MathJax.HTML.Cookie,"menu",MathJax.Hub.config.menuSettings],
  1711. [function (config) {
  1712. var renderer = config.menuSettings.renderer, jax = config.jax;
  1713. if (renderer) {
  1714. var name = "output/"+renderer; jax.sort();
  1715. for (var i = 0, m = jax.length; i < m; i++) {
  1716. if (jax[i].substr(0,7) === "output/") break;
  1717. }
  1718. if (i == m-1) {jax.pop()} else {
  1719. while (i < m) {if (jax[i] === name) {jax.splice(i,1); break}; i++}
  1720. }
  1721. jax.unshift(name);
  1722. }
  1723. },MathJax.Hub.config],
  1724. ["Post",this.signal,"End Cookie"]
  1725. );
  1726. },
  1727. //
  1728. // Setup stylesheets and extra styles
  1729. //
  1730. Styles: function () {
  1731. return this.queue.Push(
  1732. ["Post",this.signal,"Begin Styles"],
  1733. ["loadArray",this,MathJax.Hub.config.styleSheets,"config"],
  1734. ["Styles",MathJax.Ajax,MathJax.Hub.config.styles],
  1735. ["Post",this.signal,"End Styles"]
  1736. );
  1737. },
  1738. //
  1739. // Load the input and output jax
  1740. //
  1741. Jax: function () {
  1742. var config = MathJax.Hub.config, jax = MathJax.Hub.outputJax;
  1743. // Save the order of the output jax since they are loading asynchronously
  1744. for (var i = 0, m = config.jax.length, k = 0; i < m; i++) {
  1745. if (config.jax[i].substr(0,7) === "output/")
  1746. {jax.order[config.jax[i].substr(7)] = k; k++}
  1747. }
  1748. var queue = MathJax.Callback.Queue();
  1749. return queue.Push(
  1750. ["Post",this.signal,"Begin Jax"],
  1751. ["loadArray",this,config.jax,"jax","config.js"],
  1752. ["Post",this.signal,"End Jax"]
  1753. );
  1754. },
  1755. //
  1756. // Load the extensions
  1757. //
  1758. Extensions: function () {
  1759. var queue = MathJax.Callback.Queue();
  1760. return queue.Push(
  1761. ["Post",this.signal,"Begin Extensions"],
  1762. ["loadArray",this,MathJax.Hub.config.extensions,"extensions"],
  1763. ["Post",this.signal,"End Extensions"]
  1764. );
  1765. },
  1766. //
  1767. // Initialize the Message system
  1768. //
  1769. Message: function () {
  1770. MathJax.Message.Init(true);
  1771. },
  1772. //
  1773. // Set the math menu renderer, if it isn't already
  1774. // (this must come after the jax are loaded)
  1775. //
  1776. Menu: function () {
  1777. var menu = MathJax.Hub.config.menuSettings, jax = MathJax.Hub.outputJax, registered;
  1778. for (var id in jax) {if (jax.hasOwnProperty(id)) {
  1779. if (jax[id].length) {registered = jax[id]; break}
  1780. }}
  1781. if (registered && registered.length) {
  1782. if (menu.renderer && menu.renderer !== registered[0].id)
  1783. {registered.unshift(MathJax.OutputJax[menu.renderer])}
  1784. menu.renderer = registered[0].id;
  1785. }
  1786. },
  1787. //
  1788. // Set the location to the designated hash position
  1789. //
  1790. Hash: function () {
  1791. if (MathJax.Hub.config.positionToHash && document.location.hash)
  1792. {setTimeout("document.location = document.location.hash",1)}
  1793. },
  1794. //
  1795. // Load the Menu and Zoom code, if it hasn't already been loaded.
  1796. // This is called after the initial typeset, so should no longer be
  1797. // competing with other page loads, but will make these available
  1798. // if needed later on.
  1799. //
  1800. MenuZoom: function () {
  1801. if (!MathJax.Extension.MathMenu) {
  1802. setTimeout(
  1803. MathJax.Callback(["Require",MathJax.Ajax,"[MathJax]/extensions/MathMenu.js",{}]),
  1804. 1000
  1805. );
  1806. }
  1807. if (!MathJax.Extension.MathZoom) {
  1808. setTimeout(
  1809. MathJax.Callback(["Require",MathJax.Ajax,"[MathJax]/extensions/MathZoom.js",{}]),
  1810. 2000
  1811. );
  1812. }
  1813. },
  1814. //
  1815. // Setup the onload callback
  1816. //
  1817. onLoad: function (when) {
  1818. var onload = this.onload =
  1819. MathJax.Callback(function () {MathJax.Hub.Startup.signal.Post("onLoad")});
  1820. if (document.body && document.readyState && document.readyState !== "loading") {return [onload]}
  1821. if (window.addEventListener) {
  1822. window.addEventListener("load",onload,false);
  1823. if (!this.params.noDOMContentEvent)
  1824. {window.addEventListener("DOMContentLoaded",onload,false)}
  1825. }
  1826. else if (window.attachEvent) {window.attachEvent("onload",onload)}
  1827. else {window.onload = onload}
  1828. return onload;
  1829. },
  1830. //
  1831. // Perform the initial typesetting (or skip if configuration says to)
  1832. //
  1833. Typeset: function (element,callback) {
  1834. if (MathJax.Hub.config.skipStartupTypeset) {return function () {}}
  1835. return this.queue.Push(
  1836. ["Post",this.signal,"Begin Typeset"],
  1837. ["Typeset",MathJax.Hub,element,callback],
  1838. ["Post",this.signal,"End Typeset"]
  1839. );
  1840. },
  1841. //
  1842. // Create a URL in the MathJax hierarchy
  1843. //
  1844. URL: function (dir,name) {
  1845. if (!name.match(/^([a-z]+:\/\/|\[|\/)/)) {name = "[MathJax]/"+dir+"/"+name}
  1846. return name;
  1847. },
  1848. //
  1849. // Load an array of files, waiting for all of them
  1850. // to be loaded before going on
  1851. //
  1852. loadArray: function (files,dir,name,synchronous) {
  1853. if (files) {
  1854. if (!(files instanceof Array)) {files = [files]}
  1855. if (files.length) {
  1856. var queue = MathJax.Callback.Queue(), callback = {}, file;
  1857. for (var i = 0, m = files.length; i < m; i++) {
  1858. file = this.URL(dir,files[i]);
  1859. if (name) {file += "/" + name}
  1860. if (synchronous) {queue.Push(["Require",MathJax.Ajax,file,callback])}
  1861. else {queue.Push(MathJax.Ajax.Require(file,callback))}
  1862. }
  1863. return queue.Push({}); // wait for everything to finish
  1864. }
  1865. }
  1866. return null;
  1867. }
  1868. };
  1869. /**********************************************************/
  1870. (function (BASENAME) {
  1871. var BASE = window[BASENAME], ROOT = "["+BASENAME+"]";
  1872. var HUB = BASE.Hub, AJAX = BASE.Ajax, CALLBACK = BASE.Callback;
  1873. var JAX = MathJax.Object.Subclass({
  1874. JAXFILE: "jax.js",
  1875. require: null, // array of files to load before jax.js is complete
  1876. config: {},
  1877. //
  1878. // Make a subclass and return an instance of it.
  1879. // (FIXME: should we replace config with a copy of the constructor's
  1880. // config? Otherwise all subclasses share the same config structure.)
  1881. //
  1882. Init: function (def,cdef) {
  1883. if (arguments.length === 0) {return this}
  1884. return (this.constructor.Subclass(def,cdef))();
  1885. },
  1886. //
  1887. // Augment by merging with class definition (not replacing)
  1888. //
  1889. Augment: function (def,cdef) {
  1890. var cObject = this.constructor, ndef = {};
  1891. if (def != null) {
  1892. for (var id in def) {if (def.hasOwnProperty(id)) {
  1893. if (typeof def[id] === "function")
  1894. {cObject.protoFunction(id,def[id])} else {ndef[id] = def[id]}
  1895. }}
  1896. // MSIE doesn't list toString even if it is not native so handle it separately
  1897. if (def.toString !== cObject.prototype.toString && def.toString !== {}.toString)
  1898. {cObject.protoFunction('toString',def.toString)}
  1899. }
  1900. HUB.Insert(cObject.prototype,ndef);
  1901. cObject.Augment(null,cdef);
  1902. return this;
  1903. },
  1904. Translate: function (script,state) {
  1905. throw Error(this.directory+"/"+this.JAXFILE+" failed to define the Translate() method");
  1906. },
  1907. Register: function (mimetype) {},
  1908. Config: function () {
  1909. this.config = HUB.CombineConfig(this.id,this.config);
  1910. if (this.config.Augment) {this.Augment(this.config.Augment)}
  1911. },
  1912. Startup: function () {},
  1913. loadComplete: function (file) {
  1914. if (file === "config.js") {
  1915. return AJAX.loadComplete(this.directory+"/"+file);
  1916. } else {
  1917. var queue = CALLBACK.Queue();
  1918. queue.Push(
  1919. HUB.Register.StartupHook("End Config",{}), // wait until config complete
  1920. ["Post",HUB.Startup.signal,this.id+" Jax Config"],
  1921. ["Config",this],
  1922. ["Post",HUB.Startup.signal,this.id+" Jax Require"],
  1923. // Config may set the required and extensions array,
  1924. // so use functions to delay making the reference until needed
  1925. [function (THIS) {return MathJax.Hub.Startup.loadArray(THIS.require,this.directory)},this],
  1926. [function (config,id) {return MathJax.Hub.Startup.loadArray(config.extensions,"extensions/"+id)},this.config||{},this.id],
  1927. ["Post",HUB.Startup.signal,this.id+" Jax Startup"],
  1928. ["Startup",this],
  1929. ["Post",HUB.Startup.signal,this.id+" Jax Ready"]
  1930. );
  1931. if (this.copyTranslate) {
  1932. queue.Push(
  1933. [function (THIS) {
  1934. THIS.preProcess = THIS.preTranslate;
  1935. THIS.Process = THIS.Translate;
  1936. THIS.postProcess = THIS.postTranslate;
  1937. },this.constructor.prototype]
  1938. );
  1939. }
  1940. return queue.Push(["loadComplete",AJAX,this.directory+"/"+file]);
  1941. }
  1942. }
  1943. },{
  1944. id: "Jax",
  1945. version: "2.0",
  1946. directory: ROOT+"/jax",
  1947. extensionDir: ROOT+"/extensions"
  1948. });
  1949. /***********************************/
  1950. BASE.InputJax = JAX.Subclass({
  1951. elementJax: "mml", // the element jax to load for this input jax
  1952. copyTranslate: true,
  1953. Process: function (script,state) {
  1954. var queue = CALLBACK.Queue(), file;
  1955. // Load any needed element jax
  1956. var jax = this.elementJax; if (!(jax instanceof Array)) {jax = [jax]}
  1957. for (var i = 0, m = jax.length; i < m; i++) {
  1958. file = BASE.ElementJax.directory+"/"+jax[i]+"/"+this.JAXFILE;
  1959. if (!this.require) {this.require = []}
  1960. else if (!(this.require instanceof Array)) {this.require = [this.require]};
  1961. this.require.push(file); // so Startup will wait for it to be loaded
  1962. queue.Push(AJAX.Require(file));
  1963. }
  1964. // Load the input jax
  1965. file = this.directory+"/"+this.JAXFILE;
  1966. var load = queue.Push(AJAX.Require(file));
  1967. if (!load.called) {
  1968. this.constructor.prototype.Process = function () {
  1969. if (!load.called) {return load}
  1970. throw Error(file+" failed to load properly");
  1971. }
  1972. }
  1973. // Load the associated output jax
  1974. jax = HUB.outputJax["jax/"+jax[0]];
  1975. if (jax) {queue.Push(AJAX.Require(jax[0].directory+"/"+this.JAXFILE))}
  1976. return queue.Push({});
  1977. },
  1978. needsUpdate: function (jax) {
  1979. var script = jax.SourceElement();
  1980. return (jax.originalText !== BASE.HTML.getScript(script));
  1981. },
  1982. Register: function (mimetype) {
  1983. if (!HUB.inputJax) {HUB.inputJax = {}}
  1984. HUB.inputJax[mimetype] = this;
  1985. }
  1986. },{
  1987. id: "InputJax",
  1988. version: "2.0",
  1989. directory: JAX.directory+"/input",
  1990. extensionDir: JAX.extensionDir
  1991. });
  1992. /***********************************/
  1993. BASE.OutputJax = JAX.Subclass({
  1994. copyTranslate: true,
  1995. preProcess: function (state) {
  1996. var load, file = this.directory+"/"+this.JAXFILE;
  1997. this.constructor.prototype.preProcess = function (state) {
  1998. if (!load.called) {return load}
  1999. throw Error(file+" failed to load properly");
  2000. }
  2001. load = AJAX.Require(file);
  2002. return load;
  2003. },
  2004. Register: function (mimetype) {
  2005. var jax = HUB.outputJax;
  2006. if (!jax[mimetype]) {jax[mimetype] = []}
  2007. // If the output jax is earlier in the original configuration list, put it first here
  2008. if (jax[mimetype].length && (this.id === HUB.config.menuSettings.renderer ||
  2009. (jax.order[this.id]||0) < (jax.order[jax[mimetype][0].id]||0)))
  2010. {jax[mimetype].unshift(this)} else {jax[mimetype].push(this)}
  2011. // Make sure the element jax is loaded before Startup is called
  2012. if (!this.require) {this.require = []}
  2013. else if (!(this.require instanceof Array)) {this.require = [this.require]};
  2014. this.require.push(BASE.ElementJax.directory+"/"+(mimetype.split(/\//)[1])+"/"+this.JAXFILE);
  2015. },
  2016. Remove: function (jax) {}
  2017. },{
  2018. id: "OutputJax",
  2019. version: "2.0",
  2020. directory: JAX.directory+"/output",
  2021. extensionDir: JAX.extensionDir,
  2022. fontDir: ROOT+(BASE.isPacked?"":"/..")+"/fonts",
  2023. imageDir: ROOT+(BASE.isPacked?"":"/..")+"/images"
  2024. });
  2025. /***********************************/
  2026. BASE.ElementJax = JAX.Subclass({
  2027. // make a subclass, not an instance
  2028. Init: function (def,cdef) {return this.constructor.Subclass(def,cdef)},
  2029. inputJax: null,
  2030. outputJax: null,
  2031. inputID: null,
  2032. originalText: "",
  2033. mimeType: "",
  2034. Text: function (text,callback) {
  2035. var script = this.SourceElement();
  2036. BASE.HTML.setScript(script,text);
  2037. script.MathJax.state = this.STATE.UPDATE;
  2038. return HUB.Update(script,callback);
  2039. },
  2040. Reprocess: function (callback) {
  2041. var script = this.SourceElement();
  2042. script.MathJax.state = this.STATE.UPDATE;
  2043. return HUB.Reprocess(script,callback);
  2044. },
  2045. Update: function (callback) {return this.Rerender(callback)},
  2046. Rerender: function (callback) {
  2047. var script = this.SourceElement();
  2048. script.MathJax.state = this.STATE.OUTPUT;
  2049. return HUB.Process(script,callback);
  2050. },
  2051. Remove: function (keep) {
  2052. if (this.hover) {this.hover.clear(this)}
  2053. BASE.OutputJax[this.outputJax].Remove(this);
  2054. if (!keep) {
  2055. HUB.signal.Post(["Remove Math",this.inputID]); // wait for this to finish?
  2056. this.Detach();
  2057. }
  2058. },
  2059. needsUpdate: function () {
  2060. return BASE.InputJax[this.inputJax].needsUpdate(this);
  2061. },
  2062. SourceElement: function () {return document.getElementById(this.inputID)},
  2063. Attach: function (script,inputJax) {
  2064. var jax = script.MathJax.elementJax;
  2065. if (script.MathJax.state === this.STATE.UPDATE) {
  2066. jax.Clone(this);
  2067. } else {
  2068. jax = script.MathJax.elementJax = this;
  2069. if (script.id) {this.inputID = script.id}
  2070. else {script.id = this.inputID = BASE.ElementJax.GetID(); this.newID = 1}
  2071. }
  2072. jax.originalText = BASE.HTML.getScript(script);
  2073. jax.inputJax = inputJax;
  2074. if (jax.root) {jax.root.inputID = jax.inputID}
  2075. return jax;
  2076. },
  2077. Detach: function () {
  2078. var script = this.SourceElement(); if (!script) return;
  2079. try {delete script.MathJax} catch(err) {script.MathJax = null}
  2080. if (this.newID) {script.id = ""}
  2081. },
  2082. Clone: function (jax) {
  2083. var id;
  2084. for (id in this) {
  2085. if (!this.hasOwnProperty(id)) continue;
  2086. if (typeof(jax[id]) === 'undefined' && id !== 'newID') {delete this[id]}
  2087. }
  2088. for (id in jax) {
  2089. if (!jax.hasOwnProperty(id)) continue;
  2090. if (typeof(this[id]) === 'undefined' || (this[id] !== jax[id] && id !== 'inputID'))
  2091. {this[id] = jax[id]}
  2092. }
  2093. }
  2094. },{
  2095. id: "ElementJax",
  2096. version: "2.0",
  2097. directory: JAX.directory+"/element",
  2098. extensionDir: JAX.extensionDir,
  2099. ID: 0, // jax counter (for IDs)
  2100. STATE: {
  2101. PENDING: 1, // script is identified as math but not yet processed
  2102. PROCESSED: 2, // script has been processed
  2103. UPDATE: 3, // elementJax should be updated
  2104. OUTPUT: 4 // output should be updated (input is OK)
  2105. },
  2106. GetID: function () {this.ID++; return "MathJax-Element-"+this.ID},
  2107. Subclass: function () {
  2108. var obj = JAX.Subclass.apply(this,arguments);
  2109. obj.loadComplete = this.prototype.loadComplete;
  2110. return obj;
  2111. }
  2112. });
  2113. BASE.ElementJax.prototype.STATE = BASE.ElementJax.STATE;
  2114. //
  2115. // Some "Fake" jax used to allow menu access for "Math Processing Error" messages
  2116. //
  2117. BASE.OutputJax.Error = {
  2118. id: "Error", version: "2.0", config: {},
  2119. ContextMenu: function () {return BASE.Extension.MathEvents.Event.ContextMenu.apply(BASE.Extension.MathEvents.Event,arguments)},
  2120. Mousedown: function () {return BASE.Extension.MathEvents.Event.AltContextMenu.apply(BASE.Extension.MathEvents.Event,arguments)},
  2121. getJaxFromMath: function () {return {inputJax:"Error", outputJax:"Error", originalText:"Math Processing Error"}}
  2122. };
  2123. BASE.InputJax.Error = {
  2124. id: "Error", version: "2.0", config: {},
  2125. sourceMenuTitle: "Error Message"
  2126. };
  2127. })("MathJax");
  2128. /**********************************************************/
  2129. (function (BASENAME) {
  2130. var BASE = window[BASENAME];
  2131. if (!BASE) {BASE = window[BASENAME] = {}}
  2132. var HUB = BASE.Hub; var STARTUP = HUB.Startup; var CONFIG = HUB.config;
  2133. var HEAD = document.getElementsByTagName("head")[0];
  2134. if (!HEAD) {HEAD = document.childNodes[0]};
  2135. var scripts = (document.documentElement || document).getElementsByTagName("script");
  2136. var namePattern = new RegExp("(^|/)"+BASENAME+"\\.js(\\?.*)?$");
  2137. for (var i = scripts.length-1; i >= 0; i--) {
  2138. if (scripts[i].src.match(namePattern)) {
  2139. STARTUP.script = scripts[i].innerHTML;
  2140. if (RegExp.$2) {
  2141. var params = RegExp.$2.substr(1).split(/\&/);
  2142. for (var j = 0, m = params.length; j < m; j++) {
  2143. var KV = params[j].match(/(.*)=(.*)/);
  2144. if (KV) {STARTUP.params[unescape(KV[1])] = unescape(KV[2])}
  2145. }
  2146. }
  2147. CONFIG.root = scripts[i].src.replace(/(^|\/)[^\/]*(\?.*)?$/,'');
  2148. break;
  2149. }
  2150. }
  2151. BASE.Ajax.config = CONFIG;
  2152. var BROWSERS = {
  2153. isMac: (navigator.platform.substr(0,3) === "Mac"),
  2154. isPC: (navigator.platform.substr(0,3) === "Win"),
  2155. isMSIE: (window.ActiveXObject != null && window.clipboardData != null),
  2156. isFirefox: (window.netscape != null && document.ATTRIBUTE_NODE != null && !window.opera),
  2157. isSafari: (navigator.userAgent.match(/ (Apple)?WebKit\//) != null &&
  2158. (!window.chrome || window.chrome.loadTimes == null)),
  2159. isChrome: (window.chrome != null && window.chrome.loadTimes != null),
  2160. isOpera: (window.opera != null && window.opera.version != null),
  2161. isKonqueror: (window.hasOwnProperty && window.hasOwnProperty("konqueror") && navigator.vendor == "KDE"),
  2162. versionAtLeast: function (v) {
  2163. var bv = (this.version).split('.'); v = (new String(v)).split('.');
  2164. for (var i = 0, m = v.length; i < m; i++)
  2165. {if (bv[i] != v[i]) {return parseInt(bv[i]||"0") >= parseInt(v[i])}}
  2166. return true;
  2167. },
  2168. Select: function (choices) {
  2169. var browser = choices[HUB.Browser];
  2170. if (browser) {return browser(HUB.Browser)}
  2171. return null;
  2172. }
  2173. };
  2174. var AGENT = navigator.userAgent
  2175. .replace(/^Mozilla\/(\d+\.)+\d+ /,"") // remove initial Mozilla, which is never right
  2176. .replace(/[a-z][-a-z0-9._: ]+\/\d+[^ ]*-[^ ]*\.([a-z][a-z])?\d+ /i,"") // remove linux version
  2177. .replace(/Gentoo |Ubuntu\/(\d+\.)*\d+ (\([^)]*\) )?/,""); // special case for these
  2178. HUB.Browser = HUB.Insert(HUB.Insert(new String("Unknown"),{version: "0.0"}),BROWSERS);
  2179. for (var browser in BROWSERS) {if (BROWSERS.hasOwnProperty(browser)) {
  2180. if (BROWSERS[browser] && browser.substr(0,2) === "is") {
  2181. browser = browser.slice(2);
  2182. if (browser === "Mac" || browser === "PC") continue;
  2183. HUB.Browser = HUB.Insert(new String(browser),BROWSERS);
  2184. var VERSION = new RegExp(
  2185. ".*(Version)/((?:\\d+\\.)+\\d+)|" + // for Safari and Opera10
  2186. ".*("+browser+")"+(browser == "MSIE" ? " " : "/")+"((?:\\d+\\.)*\\d+)|"+ // for one of the main browser
  2187. "(?:^|\\(| )([a-z][-a-z0-9._: ]+|(?:Apple)?WebKit)/((?:\\d+\\.)+\\d+)"); // for unrecognized browser
  2188. var MATCH = VERSION.exec(AGENT) || ["","","","unknown","0.0"];
  2189. HUB.Browser.name = (MATCH[1] == "Version" ? browser : (MATCH[3] || MATCH[5]));
  2190. HUB.Browser.version = MATCH[2] || MATCH[4] || MATCH[6];
  2191. break;
  2192. }
  2193. }};
  2194. //
  2195. // Initial browser-specific info (e.g., touch up version or name)
  2196. //
  2197. HUB.Browser.Select({
  2198. Safari: function (browser) {
  2199. var v = parseInt((String(browser.version).split("."))[0]);
  2200. if (v > 85) {browser.webkit = browser.version}
  2201. if (v >= 534) {browser.version = "5.1"}
  2202. else if (v >= 533) {browser.version = "5.0"}
  2203. else if (v >= 526) {browser.version = "4.0"}
  2204. else if (v >= 525) {browser.version = "3.1"}
  2205. else if (v > 500) {browser.version = "3.0"}
  2206. else if (v > 400) {browser.version = "2.0"}
  2207. else if (v > 85) {browser.version = "1.0"}
  2208. browser.isMobile = (navigator.appVersion.match(/Mobile/i) != null);
  2209. browser.noContextMenu = browser.isMobile;
  2210. },
  2211. Firefox: function (browser) {
  2212. if ((browser.version === "0.0" || navigator.userAgent.match(/Firefox/) == null) &&
  2213. navigator.product === "Gecko") {
  2214. var rv = navigator.userAgent.match(/[\/ ]rv:(\d+\.\d.*?)[\) ]/);
  2215. if (rv) {browser.version = rv[1]}
  2216. else {
  2217. var date = (navigator.buildID||navigator.productSub||"0").substr(0,8);
  2218. if (date >= "20111220") {browser.version = "9.0"}
  2219. else if (date >= "20111120") {browser.version = "8.0"}
  2220. else if (date >= "20110927") {browser.version = "7.0"}
  2221. else if (date >= "20110816") {browser.version = "6.0"}
  2222. else if (date >= "20110621") {browser.version = "5.0"}
  2223. else if (date >= "20110320") {browser.version = "4.0"}
  2224. else if (date >= "20100121") {browser.version = "3.6"}
  2225. else if (date >= "20090630") {browser.version = "3.5"}
  2226. else if (date >= "20080617") {browser.version = "3.0"}
  2227. else if (date >= "20061024") {browser.version = "2.0"}
  2228. }
  2229. }
  2230. browser.isMobile = (navigator.appVersion.match(/Android/i) != null ||
  2231. navigator.userAgent.match(/ Fennec\//) != null);
  2232. },
  2233. Opera: function (browser) {browser.version = opera.version()},
  2234. MSIE: function (browser) {
  2235. browser.isIE9 = !!(document.documentMode && (window.performance || window.msPerformance));
  2236. MathJax.HTML.setScriptBug = !browser.isIE9 || document.documentMode < 9;
  2237. var MathPlayer = false;
  2238. try {new ActiveXObject("MathPlayer.Factory.1"); MathPlayer = true} catch(err) {}
  2239. if (MathPlayer && !STARTUP.params.NoMathPlayer) {
  2240. var mathplayer = document.createElement("object");
  2241. mathplayer.id = "mathplayer"; mathplayer.classid = "clsid:32F66A20-7614-11D4-BD11-00104BD3F987";
  2242. document.getElementsByTagName("head")[0].appendChild(mathplayer);
  2243. document.namespaces.add("m","http://www.w3.org/1998/Math/MathML");
  2244. browser.hasMathPlayer = true;
  2245. if (document.readyState && (document.readyState === "loading" ||
  2246. document.readyState === "interactive")) {
  2247. document.write('<?import namespace="m" implementation="#MathPlayer">');
  2248. browser.mpImported = true;
  2249. }
  2250. }
  2251. }
  2252. });
  2253. HUB.Browser.Select(MathJax.Message.browsers);
  2254. HUB.queue = BASE.Callback.Queue();
  2255. HUB.queue.Push(
  2256. ["Post",STARTUP.signal,"Begin"],
  2257. ["Config",STARTUP],
  2258. ["Cookie",STARTUP],
  2259. ["Styles",STARTUP],
  2260. ["Message",STARTUP],
  2261. function () {
  2262. // Do Jax and Extensions in parallel, but wait for them all to complete
  2263. var queue = BASE.Callback.Queue(
  2264. STARTUP.Jax(),
  2265. STARTUP.Extensions()
  2266. );
  2267. return queue.Push({});
  2268. },
  2269. ["Menu",STARTUP],
  2270. STARTUP.onLoad(),
  2271. function () {MathJax.isReady = true}, // indicates that MathJax is ready to process math
  2272. ["Typeset",STARTUP],
  2273. ["Hash",STARTUP],
  2274. ["MenuZoom",STARTUP],
  2275. ["Post",STARTUP.signal,"End"]
  2276. );
  2277. })("MathJax");
  2278. }}
  2279. /**********************************************************/