-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
249 lines (216 loc) · 6.22 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/**
* Created by liu on 17-3-31.
*/
const MAIN_TIME = 420;
const PAUSE_TIME = 120;
const DEBUG_TIME = 60;
const LAYOUT_TIME = 120;
const TRANSITION_TIME = 240;
const LATE_TIME = 600;
const AUDIO_TIME = 10;
var transition_late_flag = false;
var $audio_timer = $('#audio-timer');
function startTimerAudio() {
$audio_timer[0].play();
}
function stopTimeAudioTimeout(timeout) {
var count = $audio_timer.data('count');
$audio_timer.data('count', ++count);
setTimeout(function () {
if (count === $audio_timer.data('count')) $audio_timer[0].pause();
}, timeout);
}
function stopTimerAudio() {
stopTimeAudioTimeout(0);
}
//startTimerAudio();
function onInterval() {
var time = this.factory.getTime().time;
if (this.factory.audioFlag)return;
if (time > 0 && time <= AUDIO_TIME) {
this.factory.audioFlag = true;
startTimerAudio();
stopTimeAudioTimeout(time * 1000);
}
}
var clock_main = $('#clock-main').FlipClock(0, {
countdown: true,
autoStart: false,
clockFace: 'MinuteCounter',
callbacks: {
interval: onInterval
}
});
var clock_debug = $('#clock-debug').FlipClock(0, {
countdown: true,
autoStart: false,
clockFace: 'MinuteCounter'
});
var clock_left_pause = $('#clock-left-pause').FlipClock(0, {
countdown: true,
autoStart: false,
clockFace: 'MinuteCounter'
});
var clock_right_pause = $('#clock-right-pause').FlipClock(0, {
countdown: true,
autoStart: false,
clockFace: 'MinuteCounter'
});
function stopAllClock() {
clock_debug.stop();
clock_main.stop();
clock_left_pause.stop();
clock_right_pause.stop();
$('#btn-start').find('i').removeClass('fa-stop');
$('#btn-debug').find('i').removeClass('fa-stop');
$('#btn-left-pause').find('i').removeClass('fa-stop');
$('#btn-right-pause').find('i').removeClass('fa-stop');
clock_main.stopFlag = true;
clock_debug.stopFlag = true;
clock_left_pause.stopFlag = true;
clock_right_pause.stopFlag = true;
clock_main.audioFlag = false;
clock_debug.audioFlag = false;
clock_left_pause.audioFlag = false;
clock_right_pause.audioFlag = false;
stopTimerAudio();
}
function initLayout() {
$('#text-main').html('自由摆放剩余时间');
$('.pause-wrapper').hide();
$('.debug-wrapper').show().addClass('offset-4');
$('#btn-switch').hide();
$('#btn-start').removeClass('mr-1');
clock_main.reset();
clock_main.setTime(LAYOUT_TIME);
clock_debug.reset();
clock_debug.setTime(DEBUG_TIME);
stopAllClock();
}
function initRace() {
$('#text-main').html('比赛剩余时间');
$('.pause-wrapper').show();
$('.debug-wrapper').show().removeClass('offset-4');
$('#btn-switch').hide();
$('#btn-start').removeClass('mr-1');
clock_main.reset();
clock_main.setTime(MAIN_TIME);
clock_left_pause.reset();
clock_left_pause.setTime(PAUSE_TIME);
clock_right_pause.reset();
clock_right_pause.setTime(PAUSE_TIME);
clock_debug.reset();
clock_debug.setTime(DEBUG_TIME);
stopAllClock();
}
function initTransition() {
$('#text-main').html('过渡时间');
$('.pause-wrapper').hide();
$('.debug-wrapper').hide();
$('#btn-switch').show();
$('#btn-start').addClass('mr-1');
clock_main.reset();
clock_main.setTime(TRANSITION_TIME);
stopAllClock();
}
function initLate() {
$('#text-main').html('迟到倒计时');
$('.pause-wrapper').hide();
$('.debug-wrapper').hide();
$('#btn-switch').show();
$('#btn-start').addClass('mr-1');
clock_main.reset();
clock_main.setTime(LATE_TIME);
stopAllClock();
}
initLayout();
$('#btn-start').on('click', function () {
if (clock_main.stopFlag) {
stopAllClock();
clock_main.stopFlag = false;
clock_main.start();
$('#btn-start').find('i').addClass('fa-stop');
}
else {
stopAllClock();
}
});
$('#btn-debug').on('click', function () {
if (clock_debug.stopFlag) {
stopAllClock();
clock_debug.stopFlag = false;
clock_debug.start();
$('#btn-debug').find('i').addClass('fa-stop');
}
else {
stopAllClock();
}
});
$('#btn-left-pause').on('click', function () {
if (clock_left_pause.stopFlag) {
stopAllClock();
clock_left_pause.stopFlag = false;
clock_left_pause.start();
$('#btn-left-pause').find('i').addClass('fa-stop');
}
else {
stopAllClock();
}
});
$('#btn-right-pause').on('click', function () {
if (clock_right_pause.stopFlag) {
stopAllClock();
clock_right_pause.stopFlag = false;
clock_right_pause.start();
$('#btn-right-pause').find('i').addClass('fa-stop');
}
else {
stopAllClock();
}
});
$('#btn-layout').on('click', initLayout);
$('#btn-race').on('click', initRace);
$('#btn-transition').on('click', initTransition);
$('#btn-switch').on('click', function () {
if (transition_late_flag = !transition_late_flag) initLate();
else initTransition();
});
function selectTemplate(item) {
return item.id + '# ' + item.text;
}
var teams_arr = {};
for (var i = 0; i < window.teams.length; i++) {
window.teams[i].text = window.teams[i].id + '# ' + window.teams[i].value;
teams_arr[window.teams[i].id] = i;
}
var $select_left = $('#select-left');
$select_left.select2({
data: window.teams,
placeholder: "---",
allowClear: true,
//templateResult: selectTemplate
});
var $select_right = $('#select-right');
$select_right.select2({
data: window.teams,
placeholder: "---",
allowClear: true,
//templateResult: selectTemplate
});
$select_left.on('select2:select', function (e) {
var item = window.teams[teams_arr[e.params.data.id]];
changeTeamName(item.id + '#<br>' + item.value, $('#left-team-name'));
});
$select_left.on('select2:unselect', function (e) {
changeTeamName('', $('#left-team-name'));
});
$select_right.on('select2:select', function (e) {
var item = window.teams[teams_arr[e.params.data.id]];
changeTeamName(item.id + '#<br>' + item.value, $('#right-team-name'));
});
$select_right.on('select2:unselect', function (e) {
changeTeamName('', $('#right-team-name'));
});
function changeTeamName(name, container) {
container.html(name);
}