-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
202 lines (185 loc) · 4.31 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
const primary = '#0d2240';
const secondary = '#5a6770ff';
const secondaryLight = '#d44b61ff';
const tertiary = '#c3c6c9ff';
const quaternary = '#343736ff';
const pale = '#e6ecf0';
const $start = $('#start');
const $reset = $('#reset');
const $clapBtn = $('#clap-btn');
const $clapCount = $('#clap-count');
const $subtractCount = $('#subtract');
const $confettiBtn = $('#confetti');
const $modalDismiss = $('#modal-dismiss');
const $cheerBtn = $('#cheer-btn');
const $addCount = $('#add');
const $modal = $('#modal');
const $modalFullText = $('#full-text');
const $corndog = $('#corndog')[0];
$corndog.loop = true;
const $cheer = $('#cheer')[0];
const $clap = $('#clap')[0];
let isSpinning = false;
let count = 1;
$clapCount.text(count);
let myWheel = new Winwheel({
numSegments: 10,
outerRadius: 350,
innerRadius: 100,
textFontSize: 24,
textMargin: 20,
// drawText: true,
// textOrientation: 'curved',
textAlignment: 'outer',
textFillStyle: pale,
segments: [
{
fillStyle: primary,
text: '$50 Target gift card',
fullText: 'Really, $50 Target GC!'
},
{
fillStyle: tertiary,
text: 'Amazon GC $50',
fullText: 'Amazon Gift Card $50'
},
{
fillStyle: quaternary,
// textFillStyle: primary,
text: '$50 Target gift card',
fullText: 'Really, $50 Target GC!'
},
{
fillStyle: secondary,
text: 'Amazon GC $50',
fullText: 'Amazon Gift Card $50'
},
{
fillStyle: secondaryLight,
textFillStyle: primary,
text: '$50 GC Your Choice',
fullText: '$50 Gift Card of your Choice!'
},
{
fillStyle: primary,
text: '$50 Adventure',
fullText: 'Outdoor Adventure $50'
},
{
fillStyle: tertiary,
text: '$50 Visa Gift Card',
fullText: '$50 Visa Gift Card'
},
{
fillStyle: quaternary,
// textFillStyle: primary,
text: '$50 Restaurant GC',
fullText: 'Restaurant of your Choice'
},
{
fillStyle: secondary,
text: '$50 GC Your Choice',
fullText: '$50 Gift Card of your Choice!'
},
{
fillStyle: secondaryLight,
textFillStyle: primary,
text: '$50 Grocery GC',
fullText: '$50 for Groceries!'
}
],
animation: {
type: 'spinToStop',
duration: 10,
spins: 6,
callbackFinished: onFinished
}
});
$start.click((evt) => {
evt.preventDefault();
startSpin();
});
$subtractCount.click((evt) => {
evt.preventDefault();
count = (count <= 0) ? 0 : count - 1;
$clapCount.text(count);
});
$addCount.click((evt) => {
evt.preventDefault();
count = (count >= 15) ? 15 : count + 1;
$clapCount.text(count);
});
$clapBtn.click((evt) => {
evt.preventDefault();
let i = count;
$clapBtn.addClass('is-active');
const loop = setInterval(() => {
if (i > 0) {
$clap.pause();
$clap.play();
i--;
} else {
$clapBtn.removeClass('is-active');
clearInterval(loop);
}
}, 750);
});
$cheerBtn.click((evt) => {
evt.preventDefault();
// $cheer.pause();
// $cheer.currentTime = 0;
$cheer.play();
});
$reset.click((evt) => {
evt.preventDefault();
$corndog.pause();
$corndog.currentTime = 0;
isSpinning = false;
myWheel.stopAnimation(false);
myWheel.rotationAngle = 0;
myWheel.draw();
confetti.remove();
});
$confettiBtn.click((evt) => {
evt.preventDefault();
$confettiBtn.toggleClass('active');
(confetti.isRunning())
? confetti.stop()
: confetti.start();
});
$modalDismiss.click((evt) => {
evt.preventDefault();
$modal.toggleClass('is-hidden');
$modalDismiss.toggleClass('active');
});
function startSpin() {
myWheel.stopAnimation(false);
myWheel.rotationAngle = 0;
myWheel.draw();
if (!isSpinning) {
$corndog.play();
$start.addClass('is-gradient');
myWheel.animation.duration = rdm(9, 11);
myWheel.animation.spin = rdm(4, 50);
myWheel.startAnimation();
isSpinning = true;
}
}
function rdm(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function onLoad() {}
function onFinished(segment) {
$corndog.pause();
$start.removeClass('is-gradient');
$corndog.currentTime = 0;
isSpinning = false;
confetti.start();
$cheer.play();
setTimeout(() => {
confetti.stop();
}, 3000);
$modalFullText.text(segment.fullText);
}