globalVariable.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. let isMathjaxConfig = false//用于标识是否配置
  2. const initMathjaxConfig = () => {
  3. if (!window.MathJax) {
  4. return
  5. }
  6. window.MathJax.Hub.Config({
  7. showProcessingMessages: false, //关闭js加载过程信息
  8. messageStyle: 'none', //不显示信息
  9. jax: ['input/TeX', 'output/HTML-CSS'],
  10. tex2jax: {
  11. inlineMath: [['$', '$'], ['\\(', '\\)']], //行内公式选择符
  12. displayMath: [['$$', '$$'], ['\\[', '\\]']], //段内公式选择符
  13. skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code', 'a'] //避开某些标签
  14. },
  15. 'HTML-CSS': {
  16. availableFonts: ['STIX', 'TeX'], //可选字体
  17. showMathMenu: false //关闭右击菜单显示
  18. }
  19. })
  20. isMathjaxConfig = true //配置完成,改为true
  21. }
  22. const _ensureMathjaxInit = function() {
  23. if (!isMathjaxConfig) initMathjaxConfig()
  24. }
  25. const _transferTikuQuestionImageUrls = function(docEle) {
  26. const imgList = docEle.getElementsByTagName('img')
  27. for (var i = 0; i < imgList.length; i++) {
  28. const img = imgList[i]
  29. const supportTagConfigs = [
  30. { tag: 'tikuimages', prefix: 'https://file.mingxuejinbang.com/tikubao/tikuimages' },
  31. { tag: 'mathJye', prefix: 'https://file.mingxuejinbang.com/tikubao/mathJye' }]
  32. for (let index = 0; index < supportTagConfigs.length; index++) {
  33. const config = supportTagConfigs[index]
  34. if (_transferTikuQuestionImageUrlsByTag(img, config)) break
  35. }
  36. }
  37. }
  38. const _transferTikuQuestionImageUrlsByTag = function(img, config) {
  39. let srcParams = img.src.split(config.tag)
  40. if (srcParams.length > 1) {
  41. img.src = config.prefix + srcParams[1]
  42. return true
  43. }
  44. return false
  45. }
  46. const MathQueue = function(elementId, callback) {
  47. _ensureMathjaxInit()
  48. const docEle = document.getElementById(elementId)
  49. if (!docEle) return
  50. _transferTikuQuestionImageUrls(docEle)
  51. if (!window.MathJax) {
  52. return
  53. }
  54. window.MathJax.Hub.Queue(['Typeset', window.MathJax.Hub, docEle])
  55. if (typeof callback === 'function') window.MathJax.Hub.Queue(callback)
  56. }