2017-07-28 08:19:06 +02:00
|
|
|
var ankiPlatform = "desktop";
|
|
|
|
var typeans;
|
2017-07-29 06:24:45 +02:00
|
|
|
|
2017-08-10 12:45:42 +02:00
|
|
|
var qFade = 100;
|
|
|
|
var aFade = 0;
|
|
|
|
|
|
|
|
function _updateQA(html, fadeTime, onupdate, onshown) {
|
2017-08-06 04:01:30 +02:00
|
|
|
// fade out current text
|
|
|
|
var qa = $("#qa");
|
|
|
|
qa.fadeTo(fadeTime, 0, function() {
|
|
|
|
// update text
|
|
|
|
qa.html(html);
|
2017-08-06 06:48:30 +02:00
|
|
|
_removeStylingFromMathjaxCloze();
|
2017-08-06 04:01:30 +02:00
|
|
|
onupdate(qa);
|
2017-07-29 06:24:45 +02:00
|
|
|
|
2017-08-06 04:01:30 +02:00
|
|
|
// don't allow drags of images, which cause them to be deleted
|
|
|
|
$("img").attr("draggable", false);
|
2017-07-29 06:24:45 +02:00
|
|
|
|
2017-08-06 04:01:30 +02:00
|
|
|
// render mathjax
|
|
|
|
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
|
2017-07-29 06:24:45 +02:00
|
|
|
|
2017-08-06 04:01:30 +02:00
|
|
|
// and reveal when processing is done
|
2017-07-29 06:24:45 +02:00
|
|
|
MathJax.Hub.Queue(function () {
|
2017-08-06 04:01:30 +02:00
|
|
|
qa.fadeTo(fadeTime, 1, function () {
|
|
|
|
onshown(qa);
|
|
|
|
});
|
2017-07-29 06:24:45 +02:00
|
|
|
});
|
|
|
|
});
|
2017-07-28 08:48:49 +02:00
|
|
|
}
|
2017-07-28 08:19:06 +02:00
|
|
|
|
2017-08-06 04:01:30 +02:00
|
|
|
function _showQuestion(q, bodyclass) {
|
2017-08-10 12:45:42 +02:00
|
|
|
_updateQA(q, qFade, function(obj) {
|
2017-08-06 04:01:30 +02:00
|
|
|
// return to top of window
|
|
|
|
window.scrollTo(0, 0);
|
2017-07-29 06:24:45 +02:00
|
|
|
|
2017-08-06 04:01:30 +02:00
|
|
|
document.body.className = bodyclass;
|
|
|
|
}, function(obj) {
|
|
|
|
// focus typing area if visible
|
|
|
|
typeans = document.getElementById("typeans");
|
|
|
|
if (typeans) {
|
|
|
|
typeans.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-07-29 06:24:45 +02:00
|
|
|
|
2017-08-08 08:02:55 +02:00
|
|
|
function _showAnswer(a, bodyclass) {
|
2017-08-10 12:45:42 +02:00
|
|
|
_updateQA(a, aFade, function(obj) {
|
2017-08-08 08:02:55 +02:00
|
|
|
if (bodyclass) {
|
|
|
|
// when previewing
|
|
|
|
document.body.className = bodyclass;
|
|
|
|
}
|
|
|
|
|
2017-08-06 04:01:30 +02:00
|
|
|
// scroll to answer?
|
|
|
|
var e = $("#answer");
|
|
|
|
if (e[0]) {
|
|
|
|
e[0].scrollIntoView();
|
|
|
|
}
|
|
|
|
}, function(obj) {
|
|
|
|
});
|
2017-07-29 06:24:45 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 08:08:10 +02:00
|
|
|
_flagColours = {
|
|
|
|
1: "red",
|
|
|
|
2: "purple",
|
|
|
|
3: "green",
|
|
|
|
4: "blue"
|
|
|
|
};
|
|
|
|
|
|
|
|
function _drawFlag(flag) {
|
|
|
|
var elem = $("#_flag");
|
|
|
|
if (flag === 0) {
|
|
|
|
elem.hide();
|
|
|
|
return;
|
2017-07-28 08:19:06 +02:00
|
|
|
}
|
2017-08-12 08:08:10 +02:00
|
|
|
elem.show();
|
|
|
|
elem.css("color", _flagColours[flag]);
|
2017-07-28 08:19:06 +02:00
|
|
|
}
|
|
|
|
|
2017-08-16 12:30:29 +02:00
|
|
|
function _drawMark(mark) {
|
|
|
|
var elem = $("#_mark");
|
|
|
|
if (!mark) {
|
|
|
|
elem.hide();
|
|
|
|
} else {
|
|
|
|
elem.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 08:19:06 +02:00
|
|
|
function _typeAnsPress() {
|
|
|
|
if (window.event.keyCode === 13) {
|
|
|
|
pycmd("ans");
|
|
|
|
}
|
|
|
|
}
|
2017-08-06 06:48:30 +02:00
|
|
|
|
|
|
|
function _removeStylingFromMathjaxCloze() {
|
|
|
|
$(".cloze").each(function (i) {
|
|
|
|
if (_clozeIsInsideMathjax(this)) {
|
|
|
|
this.outerHTML = this.innerHTML;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function _clozeIsInsideMathjax(node) {
|
|
|
|
if (!node.previousSibling || node.previousSibling.nodeType !== 3) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// look for mathjax opening in previous text
|
2017-08-11 13:09:47 +02:00
|
|
|
return /\\\(|\$\$/.test(node.previousSibling.textContent);
|
2017-08-06 06:48:30 +02:00
|
|
|
}
|