-
-
Save jcmckeown/0d00c005d0b4ff213707 to your computer and use it in GitHub Desktop.
var id_math_stuff = { | |
// id_math_stuff.theMJ | |
theMJ : window.MathJax, | |
// id_math_stuff.idMathRun = | |
idMathRun : function () { | |
if (id_math_stuff.theMJ) { | |
id_math_stuff.theMJ.Hub.Queue(["Typeset", id_math_stuff.theMJ.Hub, "idc-cover"]); | |
} else { | |
console.log("there is still no mathjax?"); | |
} | |
}, | |
// id_math_stuff.saveEscapes = | |
saveEscapes : function (commentext) { | |
var the_text = commentext.replace(/\?/ig, "?a"); | |
the_text = the_text.replace(/\x5c/ig, "?b"); | |
return the_text; | |
}, | |
// id_math_stuff.escapeEscapes = | |
escapeEscapes : function (argRec) { | |
var the_text = argRec.text; | |
the_text = the_text.replace(/\?b/ig, "\\"); | |
the_text = the_text.replace(/\?a/ig, "?"); | |
return the_text; | |
}, | |
// id_math_stuff.switchEdit = | |
switchEdit : function () { | |
if (!id_math_stuff.editComment) { | |
id_math_stuff.editComment = window.IDeditComment; | |
window.IDeditComment = function (commentid) { | |
var elt, nowJax, delim, t; | |
/** because it only seems sensible */ | |
if (!commentObj.curUser.userid || commentObj.curUser.userid <= 0) { | |
return; | |
} | |
/** There shouldn't be scripts that aren't mathjax's! */ | |
elt = document.getElementById("IDComment-CommentText" + commentid).getElementsByTagName("script"); | |
while ( elt[0] ) { | |
t = elt [0] ; | |
nowJax = id_math_stuff.theMJ.Hub.getJaxFor(t); | |
delim = /display/.test(t.type) ? "$$" : "$"; | |
t.insertAdjacentHTML('afterend', delim + nowJax.originalText + delim); | |
nowJax.Remove(); | |
t.parentNode.removeChild(t); | |
} | |
id_math_stuff.editComment(commentid); | |
}; | |
} | |
if (!id_math_stuff.saveComment) { | |
id_math_stuff.saveComment = window.IDsaveComment; | |
window.IDsaveComment = function (commentid) { | |
var textare = document.getElementById( "IDEditCommentTextArea"+commentid); | |
var theString = id_math_stuff.saveEscapes(textare.value); | |
textare.value = theString; | |
id_math_stuff.saveComment(commentid); | |
var ctext = document.getElementById( "IDComment-CommentText" + commentid); | |
ctext.innerHTML = id_math_stuff.escapeEscapes( ctext.innerHTML ); | |
id_math_stuff.theMJ.Hub.Queue(["Typeset", id_math_stuff.theMJ.Hub, "idc-cover"]); | |
} | |
} | |
} | |
}; | |
id_add_action('comment_post', id_math_stuff.idMathRun, 45); | |
id_add_action('idcomments_func_load', id_math_stuff.switchEdit, 99); | |
id_add_filter('pre_comment_text', id_math_stuff.saveEscapes, 2); | |
id_add_filter('comment_text_load', id_math_stuff.escapeEscapes, 40); |
In Revision 6, improving approximate idempotency in do-nothing edits, and correctness of editing generally. It seems I _still_ don't grok MathJax.Hub.Queue calls, to Typeset or otherwise. I'm sure that I'm doing everything MathJax.com says I should, but maybe... maybe I'm not?
Upon reconsideration, the timing-like-issue in the previous observation might be due to "id_math_stuff.saveComment" (the saved IDsaveComment) doing asynchronous things and on the whole returning too quickly. Or maybe not. I don't want to dig into the original IDsaveComment code trying to see what it does because they seem not to want me "reverse-engineering" things.
v. 7
- ... firefox(?) changed(? fixed?) the semantics of javascript object member names(?) ... anyways, something broke the fetching the window.MathJax object, from
id_math_stuff.editComment
's perspective; - for independent reasons, discovered that "nowjax.HTMLCSS" is the wrong route to the correct delim, but on the other hand I haven't found the correct general schema yet. We'll call the fixed version v.7.1 .
now v 7.1 ! MathJax kindly leaves "display" in the script "type" HTML attribute, whatever OutputJax one is using.
In 5th revision, playing with js/DOM idioms; particularly, from developer.mozilla.org,
This was throwing me for a bad loop (!) previously.
In the meantime, still don't know how to queue mathjax re-typesets, but never mind that for now.