wanikaniburned/templates/quiz.html

127 lines
5.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="{{ url_for('static', filename='wanakana.min.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand">
<img alt="Brand" height="24" width="24" src="{{ url_for('static', filename='burned.png')}}">
</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li>
<button id="api-refresh" type="submit" class="btn btn-default navbar-btn" aria-label="Refresh API">
<span class="glyphicon glyphicon-refresh" aria-hidden="true"></span>
</button>
</li>
<li class="navbar-text" data-toggle="tooltip" data-placement="bottom" title="Last API Refresh: {{ current_user.last_updated }}"><span><img alt="avatar" src="http://www.gravatar.com/avatar/{{ current_user.gravatar }}?s=24"></span> {{ current_user.username }}</li>
<li><a href="/logout">Logout</a></li>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 text-center"><p class="question-size" id="question-area"></p><img id="question-image" src=""></div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<input type="text" autocomplete=off id="kana" class="form-control answer-size">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<button class="btn btn-default btn-lg" id="submit-answer">Check</button>
</div>
</div>
<div class="row">
<div id="help-area" class="col-md-12 text-center help-size">
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<button class="btn btn-default btn-lg" id="get-help">I Don't Know</button>
</div>
</div>
</div>
</body>
<script>
var input = document.getElementById('kana');
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
refreshQuestion()
}).keypress(function(e){
if(e.which == 13){
$("#submit-answer").click()
}
})
function refreshQuestion(){
$.getJSON("/quiz_item", function(data){
$("#help-area").text('');
$("#kana").removeClass("correct").val('');
sessionStorage.setItem("question", data['question']);
sessionStorage.setItem("answer", data['answer']);
sessionStorage.setItem("item_type", data['item_type']);
$("#question-area").text('');
$("#question-image").attr("src", '');
if(sessionStorage.getItem('item_type') == 'radical'){
$("#kana").attr("placeholder", "Meaning")
document.body.style.backgroundColor = "deepskyblue";
wanakana.unbind(input);
if(sessionStorage.getItem('question').indexOf('http') >= 0){
$("#question-image").attr("src", sessionStorage.getItem('question'));
}
else {
$("#question-area").text(sessionStorage.getItem('question'));
}
}
else{
$("#kana").attr("placeholder", "かな")
if(sessionStorage.getItem('item_type') == 'kanji'){
document.body.style.backgroundColor = "deeppink";
}
else{
document.body.style.backgroundColor = "darkviolet";
}
wanakana.bind(input);
$("#question-area").text(sessionStorage.getItem('question'));
}
})}
$("#submit-answer").click(function (e){
e.preventDefault();
var input_answer = document.getElementById('kana').value;
if($("#kana").hasClass("correct")){
refreshQuestion();
}
else if(sessionStorage.getItem('answer').replace(/\s/g, '').split(/[,\.]/g).indexOf(input_answer) !== -1){
$("#kana").addClass("correct").removeClass("wrong");
}
else{
$("#kana").addClass("wrong").removeClass("correct").val('');
}
});
$("#get-help").click(function(e){
e.preventDefault();
$("#help-area").text(sessionStorage.getItem('answer'));
});
$("#api-refresh").click(function(e){
e.preventDefault();
$.post("{{ url_for('refresh_api') }}")
});
</script>
</html>