-
Notifications
You must be signed in to change notification settings - Fork 581
/
Copy pathdemo.js
62 lines (54 loc) · 1.55 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var animationWriter;
var quizWriter;
var character;
var isCharVisible;
var isOutlineVisible;
function updateCharacter() {
$('#animation-target').html('');
$('#quiz-target').html('');
var character = $('#character-select').val();
$('.char-symbol').text(character);
animationWriter = HanziWriter.create('animation-target', character, {
width: 300,
height: 300,
showOutline: shouldShowOutline('animation'),
showCharacter: false
});
quizWriter = HanziWriter.create('quiz-target', character, {
width: 300,
height: 300,
showOutline: shouldShowOutline('quiz'),
showCharacter: false,
showHintAfterMisses: 1
});
quizWriter.quiz();
// for easier debugging
window.animationWriter = animationWriter;
window.quizWriter = quizWriter;
}
function shouldShowOutline(demoType) {
return $('#' + demoType + '-show-outline').prop('checked');
}
$(function() {
updateCharacter();
$('.js-char-form').on('submit', function(evt) {
evt.preventDefault();
updateCharacter();
});
$('#animate').on('click', function(evt) {
evt.preventDefault();
animationWriter.animateCharacter();
});
$('#quiz-reset').on('click', function(evt) {
evt.preventDefault();
quizWriter.quiz();
});
$('#animation-show-outline').on('click', function() {
var method = shouldShowOutline('animation') ? 'showOutline' : 'hideOutline';
animationWriter[method]();
});
$('#quiz-show-outline').on('click', function() {
var method = shouldShowOutline('quiz') ? 'showOutline' : 'hideOutline';
quizWriter[method]();
});
});