add answer display

This commit is contained in:
Damien Elmes 2011-03-23 08:26:03 +09:00
parent 7fcaa98fa8
commit e48e268ee5
2 changed files with 59 additions and 35 deletions

View file

@ -157,11 +157,20 @@ body {
background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#bbb)); background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#bbb));
margin: 2em; } margin: 2em; }
a:hover { background-color: #aaa; } a:hover { background-color: #aaa; }
.but { font-size: 80%; padding: 3; background-color: #ccc; .but {
border-radius: 5px; color: #000; margin: 0 5 0 5; text-decoration: -webkit-box-shadow: 2px 2px 6px rgba(0,0,0,0.6);
none; display: inline-block; -webkit-user-drag: none;
-webkit-box-shadow: 2px 2px 6px rgba(0,0,0,0.6); -webkit-user-select: none;
border: 1px solid #aaa; background-color: #ccc;
border-radius: 5px;
border: 1px solid #aaa;
color: #000;
display: inline-block;
font-size: 80%;
margin: 0 5 0 5;
padding: 3;
text-decoration: none;
text-align: center;
} }
.but:focus, .but:hover { background-color: #aaa; } .but:focus, .but:hover { background-color: #aaa; }
.gbut { background-color: #7c7; } .gbut { background-color: #7c7; }

View file

@ -62,15 +62,13 @@ class Reviewer(object):
_css = """ _css = """
a.ansbut { a.ansbut {
display: block; position: fixed; bottom: 1em;
bottom: 1em; width: 250px; left: 50%; margin-left: -125px; height: 40px;
height: 40px; background-color: #ccc; left: 50%;
border-radius: 5px; margin-left: -125px;
text-align: center; position: fixed;
color: #000; text-decoration: none; width: 250px;
-webkit-box-shadow: 2px 2px 6px rgba(0,0,0,0.6); font-size: 100%;
border: 1px solid #aaa;
} }
a.ansbut:focus { a.ansbut:focus {
background: #c7c7c7; background: #c7c7c7;
@ -78,16 +76,15 @@ background: #c7c7c7;
div.ansbut { div.ansbut {
position: relative; top: 25%; position: relative; top: 25%;
} }
div#filler {
height: 20px;
}
"""
def _renderQA(self, card, text): div#filler {
# we want to include enough space at the bottom to allow for the height: 30px;
# answer buttons }
buf = "<div id=filler></div>"
self.web.stdHtml(text+buf, self._styles(), bodyClass=card.cssClass()) .q { margin-bottom: 1em; }
.a { margin-top: 1em; }
.inv { visibility: hidden; }
"""
def _styles(self): def _styles(self):
css = self.mw.sharedCSS css = self.mw.sharedCSS
@ -99,9 +96,27 @@ div#filler {
# Showing the question # Showing the question
########################################################################## ##########################################################################
_qHtml = """ _revHtml = """
<table width=100%% height=100%%><tr valign=middle><td>
%(q)s %(q)s
%(but)s""" <hr class=inv>
<span id="answer" />
%(a)s
</td></tr></table>
%(but)s
<script>
function showans () {
$(".inv").removeClass('inv');
location.hash = "answer";
};
$(document).ready(function () {
$(".ansbut").focus();
});
</script>
"""
def _showQuestion(self): def _showQuestion(self):
# fixme: timeboxing # fixme: timeboxing
@ -110,14 +125,18 @@ div#filler {
c = self.card c = self.card
# original question with sounds # original question with sounds
q = c.q() q = c.q()
a = c.a("a inv")
if (#self.state != self.oldState and not nosound if (#self.state != self.oldState and not nosound
self.mw.config['autoplaySounds']): self.mw.config['autoplaySounds']):
playFromText(q) playFromText(q)
# render # render
buf = self._qHtml % dict( buf = self._revHtml % dict(
q=mungeQA(q), q=mungeQA(q),
a=mungeQA(a) + '<div id=filler></div>',
but=self._questionButtons()) but=self._questionButtons())
self._renderQA(c, buf)
self.web.stdHtml(buf, self._styles(), bodyClass=c.cssClass())
runHook('showQuestion') runHook('showQuestion')
# Question buttons # Question buttons
@ -127,7 +146,9 @@ div#filler {
buf = self.typeAnsInput() buf = self.typeAnsInput()
# make sure to focus # make sure to focus
buf += """ buf += """
<a href=ans class=ansbut><div class=ansbut>%s</div></a> <a id=ansbut class="but ansbut" href=ans onclick="showans();">
<div class=ansbut>%s</div>
</a>
""" % _("Show Answer") """ % _("Show Answer")
return buf return buf
@ -135,16 +156,10 @@ div#filler {
########################################################################## ##########################################################################
def _showAnswer(self): def _showAnswer(self):
c = self.card a = c.a()
# original question with sounds
q = c.a()
if self.mw.config['autoplaySounds']: if self.mw.config['autoplaySounds']:
playFromText(a) playFromText(a)
# render # render
buf = self._qHtml % dict(
q=mungeQA(a),
but=self._answerButtons())
self._renderQA(c, buf)
runHook('showQuestion') runHook('showQuestion')
# buf = self.typeAnsResult() # buf = self.typeAnsResult()