anki/web/reviewer.js
Damien Elmes 68d55239b4 rework fade in code
there were a number of issues with preloading:
- it could result in duplicate IDs in the document
- embedded styles failed to apply, because a preloaded item was
overriding them
- the type answer code needed rewriting to support it

so we're back to something closer to the old approach - a single node
that we fade out, update, and then fade in again. this means there's a
longer delay when revealing mathjax, but should minimize the breakage of
existing notes
2017-08-06 12:01:30 +10:00

67 lines
1.4 KiB
JavaScript

var ankiPlatform = "desktop";
var typeans;
var fadeTime = 100;
function _updateQA(html, onupdate, onshown) {
// fade out current text
var qa = $("#qa");
qa.fadeTo(fadeTime, 0, function() {
// update text
qa.html(html);
onupdate(qa);
// don't allow drags of images, which cause them to be deleted
$("img").attr("draggable", false);
// render mathjax
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
// and reveal when processing is done
MathJax.Hub.Queue(function () {
qa.fadeTo(fadeTime, 1, function () {
onshown(qa);
});
});
});
}
function _showQuestion(q, bodyclass) {
_updateQA(q, function(obj) {
// return to top of window
window.scrollTo(0, 0);
document.body.className = bodyclass;
}, function(obj) {
// focus typing area if visible
typeans = document.getElementById("typeans");
if (typeans) {
typeans.focus();
}
});
}
function _showAnswer(a) {
_updateQA(a, function(obj) {
// scroll to answer?
var e = $("#answer");
if (e[0]) {
e[0].scrollIntoView();
}
}, function(obj) {
});
}
function _toggleStar(show) {
if (show) {
$(".marked").show();
} else {
$(".marked").hide();
}
}
function _typeAnsPress() {
if (window.event.keyCode === 13) {
pycmd("ans");
}
}