mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
add some js hooks
This commit is contained in:
parent
177fa8b052
commit
6efd9b9cbb
1 changed files with 18 additions and 9 deletions
|
@ -88,16 +88,17 @@ class Reviewer(object):
|
||||||
<div id=a></div>
|
<div id=a></div>
|
||||||
<div id=filler></div>
|
<div id=filler></div>
|
||||||
</td></tr></table>
|
</td></tr></table>
|
||||||
<a id=ansbut class="ansbut ansbutbig" href=ans onclick="showans();">
|
<a id=ansbut class="ansbut ansbutbig" href=ans onclick="_showans();">
|
||||||
<div class=ansbuttxt>%(showans)s</div>
|
<div class=ansbuttxt>%(showans)s</div>
|
||||||
</a>
|
</a>
|
||||||
<div id=easebuts>
|
<div id=easebuts>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
var ankiPlatform = "desktop";
|
||||||
var hideq;
|
var hideq;
|
||||||
var ans;
|
var ans;
|
||||||
var typeans;
|
var typeans;
|
||||||
function updateQA (qa) {
|
function _updateQA (qa) {
|
||||||
hideq = qa[4];
|
hideq = qa[4];
|
||||||
location.hash = "";
|
location.hash = "";
|
||||||
$("#q").html(qa[0]);
|
$("#q").html(qa[0]);
|
||||||
|
@ -115,8 +116,12 @@ function updateQA (qa) {
|
||||||
if (typeans) {
|
if (typeans) {
|
||||||
typeans.focus();
|
typeans.focus();
|
||||||
}
|
}
|
||||||
|
// user hook
|
||||||
|
if (typeof(onQuestion) === "function") {
|
||||||
|
onQuestion();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
function showans () {
|
function _showans () {
|
||||||
if (typeans) {
|
if (typeans) {
|
||||||
py.link("typeans:"+typeans.value);
|
py.link("typeans:"+typeans.value);
|
||||||
}
|
}
|
||||||
|
@ -129,11 +134,15 @@ function showans () {
|
||||||
}
|
}
|
||||||
$("#ansbut").hide();
|
$("#ansbut").hide();
|
||||||
$("#defease").focus();
|
$("#defease").focus();
|
||||||
|
// user hook
|
||||||
|
if (typeof(onAnswer) === "function") {
|
||||||
|
onAnswer();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
function proctypeans (res) {
|
function _processTyped (res) {
|
||||||
$("#typeans").replaceWith(res);
|
$("#typeans").replaceWith(res);
|
||||||
}
|
}
|
||||||
function space() {
|
function _onSpace() {
|
||||||
if (/^ease/.test(document.activeElement.href)) {
|
if (/^ease/.test(document.activeElement.href)) {
|
||||||
py.link(document.activeElement.href);
|
py.link(document.activeElement.href);
|
||||||
}
|
}
|
||||||
|
@ -165,7 +174,7 @@ $(".ansbut").focus();
|
||||||
esc = self.mw.deck.media.escapeImages
|
esc = self.mw.deck.media.escapeImages
|
||||||
q=esc(mungeQA(q)) + self.typeAnsInput()
|
q=esc(mungeQA(q)) + self.typeAnsInput()
|
||||||
a=esc(mungeQA(a))
|
a=esc(mungeQA(a))
|
||||||
self.web.eval("updateQA(%s);" % simplejson.dumps(
|
self.web.eval("_updateQA(%s);" % simplejson.dumps(
|
||||||
[q, a, self._answerButtons(), c.cssClass(),
|
[q, a, self._answerButtons(), c.cssClass(),
|
||||||
c.template()['hideQ']]))
|
c.template()['hideQ']]))
|
||||||
runHook('showQuestion')
|
runHook('showQuestion')
|
||||||
|
@ -247,11 +256,11 @@ $(".ansbut").focus();
|
||||||
self.web.eval("$('#typeans').blur();")
|
self.web.eval("$('#typeans').blur();")
|
||||||
if show:
|
if show:
|
||||||
self._showAnswer()
|
self._showAnswer()
|
||||||
self.web.eval("showans();")
|
self.web.eval("_showans();")
|
||||||
return True
|
return True
|
||||||
elif self.state == "answer":
|
elif self.state == "answer":
|
||||||
if evt.key() == Qt.Key_Space:
|
if evt.key() == Qt.Key_Space:
|
||||||
self.web.eval("space();")
|
self.web.eval("_onSpace();")
|
||||||
else:
|
else:
|
||||||
key = unicode(evt.text())
|
key = unicode(evt.text())
|
||||||
if key and key >= "1" and key <= "4":
|
if key and key >= "1" and key <= "4":
|
||||||
|
@ -384,7 +393,7 @@ div#filler {
|
||||||
cor = ""
|
cor = ""
|
||||||
if cor:
|
if cor:
|
||||||
res = self.correct(cor, given)
|
res = self.correct(cor, given)
|
||||||
self.web.eval("proctypeans(%s);" % simplejson.dumps(res))
|
self.web.eval("_processTyped(%s);" % simplejson.dumps(res))
|
||||||
|
|
||||||
def getFont(self):
|
def getFont(self):
|
||||||
f = self.card.model().fields[self.typeAns()]
|
f = self.card.model().fields[self.typeAns()]
|
||||||
|
|
Loading…
Reference in a new issue