MMLorHTML.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
  2. /* vim: set ts=2 et sw=2 tw=80: */
  3. /*************************************************************
  4. *
  5. * MathJax/config/MMLorHTML.js
  6. *
  7. * Chooses between the NativeMML and HTML-CSS output jax depending
  8. * on the capabilities of the browser and configuration settings
  9. * of the page.
  10. *
  11. * This file should be added to the config array when configuring
  12. * MathJax. Note that if you include this, you should NOT include
  13. * an output jax in the jax array (it will be added for you by
  14. * this file).
  15. *
  16. * You can specify the preferred output jax on a global or
  17. * browser-by-browser basis. To specify it globally, use
  18. *
  19. * MathJax.Hub.Config({
  20. * MMLorHTML: {prefer: "MML"} // or "HTML"
  21. * });
  22. *
  23. * To specify on a browser-by-borwser basis, use
  24. *
  25. * MathJax.Hub.Config({
  26. * MMLorHTML: {prefer: {
  27. * MSIE: "MML",
  28. * Firefox: "MML",
  29. * Opera: "HTML",
  30. * other: "HTML"
  31. * }}
  32. * });
  33. *
  34. * ---------------------------------------------------------------------
  35. *
  36. * Copyright (c) 2010-2013 The MathJax Consortium
  37. *
  38. * Licensed under the Apache License, Version 2.0 (the "License");
  39. * you may not use this file except in compliance with the License.
  40. * You may obtain a copy of the License at
  41. *
  42. * http://www.apache.org/licenses/LICENSE-2.0
  43. *
  44. * Unless required by applicable law or agreed to in writing, software
  45. * distributed under the License is distributed on an "AS IS" BASIS,
  46. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  47. * See the License for the specific language governing permissions and
  48. * limitations under the License.
  49. */
  50. (function (HUB,BROWSER) {
  51. var VERSION = "2.2";
  52. var CONFIG = MathJax.Hub.CombineConfig("MMLorHTML",{
  53. prefer: {
  54. MSIE:"MML",
  55. Firefox:"HTML",
  56. Opera:"HTML",
  57. Chrome:"HTML",
  58. Safari:"HTML",
  59. other:"HTML"
  60. }
  61. });
  62. var MINBROWSERVERSION = {
  63. Firefox: 3.0,
  64. Opera: 9.52,
  65. MSIE: 6.0,
  66. Chrome: 0.3,
  67. Safari: 2.0,
  68. Konqueror: 4.0
  69. };
  70. var canUseHTML = (BROWSER.version === "0.0" ||
  71. BROWSER.versionAtLeast(MINBROWSERVERSION[BROWSER]||0.0));
  72. var canUseMML = (BROWSER.isFirefox && BROWSER.versionAtLeast("1.5")) ||
  73. (BROWSER.isMSIE && BROWSER.hasMathPlayer) ||
  74. (BROWSER.isSafari && BROWSER.versionAtLeast("5.0")) ||
  75. (BROWSER.isOpera && BROWSER.versionAtLeast("9.52"));
  76. HUB.Register.StartupHook("End Config",function () {
  77. var prefer = (CONFIG.prefer && typeof(CONFIG.prefer) === "object" ?
  78. CONFIG.prefer[MathJax.Hub.Browser]||CONFIG.prefer.other||"HTML" :
  79. CONFIG.prefer);
  80. if (canUseHTML || canUseMML) {
  81. if (canUseMML && (prefer === "MML" || !canUseHTML)) {
  82. if (MathJax.OutputJax.NativeMML) {MathJax.OutputJax.NativeMML.Register("jax/mml")}
  83. else {HUB.config.jax.unshift("output/NativeMML")}
  84. HUB.Startup.signal.Post("NativeMML output selected");
  85. } else {
  86. if (MathJax.OutputJax["HTML-CSS"]) {MathJax.OutputJax["HTML-CSS"].Register("jax/mml")}
  87. else {HUB.config.jax.unshift("output/HTML-CSS")}
  88. HUB.Startup.signal.Post("HTML-CSS output selected");
  89. }
  90. } else {
  91. HUB.PreProcess.disabled = true;
  92. HUB.prepareScripts.disabled = true;
  93. MathJax.Message.Set(
  94. ["MathJaxNotSupported","Your browser does not support MathJax"],
  95. null,4000
  96. );
  97. HUB.Startup.signal.Post("MathJax not supported");
  98. }
  99. });
  100. })(MathJax.Hub,MathJax.Hub.Browser);
  101. MathJax.Ajax.loadComplete("[MathJax]/config/MMLorHTML.js");