From 89086b842038830f39b77b3f7beb164d2cb028ee Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 7 Feb 2016 13:35:00 -0800 Subject: [PATCH] Simplify math tag code now that jsMath conversion is removed and double parsing no longer a problem. --- src/Miscellaneous/Fourchan.coffee | 37 +++++++++++++------------------ 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/Miscellaneous/Fourchan.coffee b/src/Miscellaneous/Fourchan.coffee index 7e5bb2f31..2dcad9b04 100644 --- a/src/Miscellaneous/Fourchan.coffee +++ b/src/Miscellaneous/Fourchan.coffee @@ -25,27 +25,20 @@ Fourchan = cb: @code if g.BOARD.ID is 'sci' - $.globalEval ''' - window.addEventListener('mathjax', function(e) { - if (window.MathJax) { - window.MathJax.Hub.Queue(function() { - if (!e.target.querySelector('.MathJax')) { - window.MathJax.Hub.Typeset(e.target); - } - }); - } else { - if (!document.querySelector('script[src^="//cdn.mathjax.org/"]')) { - window.loadMathJax(); - window.loadMathJax = function() {}; - if (!e.target.classList.contains('postMessage')) { - document.querySelector('script[src^="//cdn.mathjax.org/"]').addEventListener('load', function() { - window.MathJax.Hub.Queue(['Typeset', window.MathJax.Hub, e.target]); - }, false); - } - } - } - }, false); - ''' + $.global -> + window.addEventListener 'mathjax', (e) -> + if window.MathJax + window.MathJax.Hub.Queue ['Typeset', window.MathJax.Hub, e.target] + else + unless document.querySelector 'script[src^="//cdn.mathjax.org/"]' # don't load MathJax if already loading + window.loadMathJax() + window.loadMathJax = -> + # 4chan only handles post comments on MathJax load; anything else (e.g. the QR preview) must be queued explicitly. + unless e.target.classList.contains 'postMessage' + document.querySelector('script[src^="//cdn.mathjax.org/"]').addEventListener 'load', -> + window.MathJax.Hub.Queue ['Typeset', window.MathJax.Hub, e.target] + , false + , false Post.callbacks.push name: 'Parse /sci/ math' cb: @math @@ -69,7 +62,7 @@ Fourchan = return math: -> - return unless /\[(math|eqn)\]/.test(@nodes.comment.textContent) or $('.math:not([id])', @nodes.comment) + return unless /\[(math|eqn)\]/.test @nodes.comment.textContent cb = => return unless doc.contains @nodes.comment $.off d, 'PostsInserted', cb