FontWarnings.js 8.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/extensions/FontWarnings.js
  6. *
  7. * Implements a font warning message window that appears when
  8. * the image fonts, no fonts, or web fonts are used, informing
  9. * the user where to download the fonts, or to update to a more
  10. * modern browser. The window will fade out automatically after
  11. * a time, and the user can dismiss it by a close box.
  12. *
  13. * To include font warning messages, add "FontWarnings.js" to the
  14. * extensions array in your MathJax configuration.
  15. *
  16. * You can customize the warning messages in a number of ways. Use the
  17. * FontWarnings section of the configuration to specify any of the items
  18. * shown in the CONFIG variable below. These include
  19. *
  20. * messageStyle the style to apply to the warning box that is
  21. * displayed when MathJax uses one of its fallback
  22. * methods.
  23. *
  24. * removeAfter the amount of time to show the warning message (in ms)
  25. * fadeoutTime how long the message should take to fade out
  26. * fadeoutSteps how many separate steps to use during the fade out
  27. * (set to 0 to use no fadeout and simply remove the window)
  28. *
  29. * Messages stores the descriptions of the messages to use for the
  30. * various warnings (webFonts, imageFonts, and noFonts).
  31. * These are arrays of strings to be inserted into the window,
  32. * or identifiers within brackets, which refer to the HTML
  33. * snippets in the HTML section described below. To disable a
  34. * specific message, set its value to null (see example below).
  35. *
  36. * HTML stores snippets of HTML descriptions for various
  37. * common parts of the error messages. These include
  38. * the closeBox, the message about web fonts being available
  39. * in modern browser, and messages about downloadable fonts.
  40. * The STIX and TeX font messages are used when only one
  41. * of these is in the availableFonts list. The data for these
  42. * are arrays of either strings to include or a description of
  43. * an HTML item enclosed in square brackets. That description
  44. * has (up to) three parts: the name of the tag to be included,
  45. * a list (enclosed in braces) of attributes and their values
  46. * to be set on the tag (optional), and an array of the contents
  47. * of the tag (optional). See the definitions below for examples.
  48. *
  49. * For example,
  50. *
  51. * MathJax.Hub.Config({
  52. * ...
  53. * extensions: ["FontWarnings.js"],
  54. * FontWarnings: {
  55. * removeAfter: 20*1000, // 20 seconds
  56. * messageStyle: {
  57. * border: "2px solid black",
  58. * padding: "2em"
  59. * },
  60. * Message: {
  61. * webFont: null // no webfont messages (only image and no fonts)
  62. * }
  63. * }
  64. * });
  65. *
  66. * would extend the time the message is displayed from 12 seconds to 20,
  67. * and changes the border to a solid black one, with 2em of padding
  68. * rather than the default of 1em.
  69. *
  70. * ---------------------------------------------------------------------
  71. *
  72. * Copyright (c) 2010-2013 The MathJax Consortium
  73. *
  74. * Licensed under the Apache License, Version 2.0 (the "License");
  75. * you may not use this file except in compliance with the License.
  76. * You may obtain a copy of the License at
  77. *
  78. * http://www.apache.org/licenses/LICENSE-2.0
  79. *
  80. * Unless required by applicable law or agreed to in writing, software
  81. * distributed under the License is distributed on an "AS IS" BASIS,
  82. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  83. * See the License for the specific language governing permissions and
  84. * limitations under the License.
  85. */(function(e,h){var c=e.CombineConfig("FontWarnings",{messageStyle:{position:"fixed",bottom:"4em",left:"3em",width:"40em",border:"3px solid #880000","background-color":"#E0E0E0",color:"black",padding:"1em","font-size":"small","white-space":"normal","border-radius":".75em","-webkit-border-radius":".75em","-moz-border-radius":".75em","-khtml-border-radius":".75em","box-shadow":"4px 4px 10px #AAAAAA","-webkit-box-shadow":"4px 4px 10px #AAAAAA","-moz-box-shadow":"4px 4px 10px #AAAAAA","-khtml-box-shadow":"4px 4px 10px #AAAAAA",filter:"progid:DXImageTransform.Microsoft.dropshadow(OffX\x3d3, OffY\x3d3, Color\x3d'gray', Positive\x3d'true')"},Message:{webFont:[["closeBox"],["webFont","MathJax is using web-based fonts to display the mathematics on this page. These take time to download, so the page would render faster if you installed math fonts directly in your system's font folder."],["fonts"]],imageFonts:[["closeBox"],["imageFonts","MathJax is using its image fonts rather than local or web-based fonts. This will render slower than usual, and the mathematics may not print at the full resolution of your printer."],["fonts"],["webfonts"]],noFonts:[["closeBox"],["noFonts","MathJax is unable to locate a font to use to display its mathematics, and image fonts are not available, so it is falling back on generic unicode characters in hopes that your browser will be able to display them. Some characters may not show up properly, or possibly not at all."],["fonts"],["webfonts"]]},HTML:{closeBox:[["div",{style:{position:"absolute",overflow:"hidden",top:".1em",right:".1em",border:"1px outset",width:"1em",height:"1em","text-align":"center",cursor:"pointer","background-color":"#EEEEEE",color:"#606060","border-radius":".5em","-webkit-border-radius":".5em","-moz-border-radius":".5em","-khtml-border-radius":".5em"},onclick:function(){d.div&&0===d.fade&&(d.timer&&clearTimeout(d.timer),d.div.style.display="none")}},[["span",{style:{position:"relative",bottom:".2em"}},["x"]]]]],webfonts:[["p"],["webfonts","Most modern browsers allow for fonts to be downloaded over the web. Updating to a more recent version of your browser (or changing browsers) could improve the quality of the mathematics on this page."]],fonts:[["p"],["fonts","MathJax can use either the [STIX fonts](%1) or the [MathJax TeX fonts](%2). Download and install one of those fonts to improve your MathJax experience.","http://www.stixfonts.org/","https://github.com/mathjax/MathJax/tree/master/fonts/HTML-CSS/TeX/otf"]],STIXfonts:[["p"],["STIXPage","This page is designed to use the [STIX fonts](%1). Download and install those fonts to improve your MathJax experience.","http://www.stixfonts.org/"]],TeXfonts:[["p"],["TeXPage","This page is designed to use the [MathJax TeX fonts](%1). Download and install those fonts to improve your MathJax experience.","https://github.com/mathjax/MathJax/tree/master/fonts/HTML-CSS/TeX/otf"]]},removeAfter:12E3,fadeoutSteps:10,fadeoutTime:1500});MathJax.Hub.Browser.isIE9&&9<=document.documentMode&&delete c.messageStyle.filter;var d={div:null,fade:0},m=function(a){if(!d.div){var l=MathJax.OutputJax["HTML-CSS"],f=document.body;e.Browser.isMSIE?"fixed"===c.messageStyle.position&&(MathJax.Message.Init(),f=document.getElementById("MathJax_MSIE_Frame"),c.messageStyle.position="absolute"):delete c.messageStyle.filter;c.messageStyle.maxWidth=document.body.clientWidth-75+"px";for(var b=0;b<a.length;)if(a[b]instanceof Array)if(1===a[b].length&&c.HTML[a[b][0]])a.splice.apply(a,[b,1].concat(c.HTML[a[b][0]]));else if("string"===typeof a[b][1]){var g=MathJax.Localization.lookupPhrase(["FontWarnings",a[b][0]],a[b][1]),g=MathJax.Localization.processString(g,a[b].slice(2),"FontWarnings");a.splice.apply(a,[b,1].concat(g));b+=g.length}else b++;else b++;d.div=l.addElement(f,"div",{id:"MathJax_FontWarning",style:c.messageStyle},a);MathJax.Localization.setCSS(d.div);c.removeAfter&&e.Register.StartupHook("End",function(){d.timer=setTimeout(k,c.removeAfter)});h.Cookie.Set("fontWarn",{warned:!0})}},k=function(){d.fade++;d.timer&&delete d.timer;if(d.fade<c.fadeoutSteps){var a=1-d.fade/c.fadeoutSteps;d.div.style.opacity=a;d.div.style.filter="alpha(opacity\x3d"+Math.floor(100*a)+")";setTimeout(k,c.fadeoutTime/c.fadeoutSteps)}else d.div.style.display="none"};h.Cookie.Get("fontWarn").warned||e.Startup.signal.Interest(function(a){if(a.match(/HTML-CSS Jax - /)&&!d.div){var e=MathJax.OutputJax["HTML-CSS"],f=e.config.availableFonts,b,g=f&&f.length;g?1===f.length&&(c.HTML.fonts=c.HTML[f[0]+"fonts"]):c.HTML.fonts=[""];e.allowWebFonts&&(c.HTML.webfonts=[""]);a.match(/- Web-Font/)?g&&(b="webFont"):a.match(/- using image fonts/)?b="imageFonts":a.match(/- no valid font/)&&(b="noFonts");b&&c.Message[b]&&MathJax.Localization.loadDomain("FontWarnings",[m,c.Message[b]])}})})(MathJax.Hub,MathJax.HTML);MathJax.Ajax.loadComplete("[MathJax]/extensions/FontWarnings.js");