-
Notifications
You must be signed in to change notification settings - Fork 2
/
standard-screen.html
332 lines (299 loc) · 12.8 KB
/
standard-screen.html
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<html>
<head>
<title>Rolling timer</title>
<link rel='stylesheet' href='./css/display-big.css' />
<link rel='stylesheet' href='./css/jquery.rollingBorder.css' />
<script src='./js/jquery-3.1.0.min.js'></script>
<script src="./js/jquery-ui.min.js"></script>
<script src='./js/display-setup.js'></script>
<script src='./js/jquery.rollingBorder.js'></script>
<script>
var observer, observerPeriod, targetNode, targetNodePeriod, observerConfig;
var scoreBorderSize = "5px";
$( document ).ready(function () {
// Initialise manually
var currTime = window.opener.$('#match-timer').html();
// console.log(currTime)
$('#match-timer').html( currTime );
var currPer = window.opener.$('#match-period').html();
// console.log(currTime)
$('#match-period').html( currPer );
// Blink the active period box
function blinkActive (selector) {
let elem = $(selector);
elem.fadeOut(750, 'linear', function () {
elem.fadeIn(250, 'linear', function () { blinkActive(selector); })
})
}
function blinkBackground (selector) {
let elem = $(selector);
let currBG = elem.css('background-color');
let newBG = 'rgb(100,100,100)';
elem.animate({backgroundColor: newBG}, 1000., 'linear', function () {
elem.animate({backgroundColor: currBG}, 1000., 'linear', function () { blinkBackground(selector); });
});
}
// Mutation observer approach
// Team clock observer
// console.log('Mutation observer!')
observerConfig = {
attributes: true,
childList: true,
characterData: true,
subtree: true
};
targetNode = window.opener.document.querySelector('#match-timer');
var rollingBorderTimer ;
function updateTimer (mutations) {
var t = window.opener.$('#match-timer');
var currTime = t.html();
var currBorder = t.css("borderLeftColor");
// console.log(currTime)
var timerDisp = $('#match-timer');
var oldBorder = timerDisp.css("borderLeftColor");
timerDisp.html(currTime);
timerDisp.css('border', scoreBorderSize + ' solid ' + currBorder);
$('#match-timer #timerColon').css('color', currBorder);
if (currBorder != oldBorder) {
if (rollingBorderTimer != null) {
rollingBorderTimer.destroy();
}
if (t.hasClass("clockGreen")) {
rollingBorderTimer = $('#match-timer').rollingBorder({
padding: 0,
color: "black",
width: 7,
length: "100%"
});
}
}
formatScreen();
}
observer = new MutationObserver(updateTimer);
// Do an initial update on open
updateTimer();
observer.observe(targetNode, observerConfig);
var rollingBorderPeriod;
targetNodePeriod = window.opener.document.querySelector('#match-period');
function updatePeriod (mutations) {
// End any and all period-related animations, and then remove any styles
// this might create
let periodRelated = $("[class^=period-]");
periodRelated.removeClass('period-box-active').removeClass('period-arrow-visible');
periodRelated.finish();
periodRelated.css('background-color', '').css('opacity', '').css('border-width', scoreBorderSize);
// console.log('Updating current period...');
let noPeriods = parseInt(window.opener.$("#match-timer-no-periods").val());
console.log('No. periods at reset: ' + noPeriods);
let currPer = window.opener.$('#match-period').html();
console.log('Current period at reset: ' + currPer);
let box = $('.period-box');
var perBoxRollingBorder ;
console.log("Period box:");
console.log(box);
box.removeClass().addClass('period-box');
box.html("");
$('.period-arrow').remove();
let currPerInt = parseInt(currPer);
// console.log("Current period is " + currPerInt + ", currPer is " + currPer);
if (rollingBorderPeriod != null) {
rollingBorderPeriod.destroy();
rollingBorderPeriod = null ;
}
if (currPer.includes('break')) {
// Stop any current period box animations
console.log('Making box ' + currPer + ' next');
box.addClass('period-box-next');
box.html(currPerInt);
// console.log('Looking for ' + '#period-arrow-' + (i-1) + '-' + i);
box.prepend("<div class='period-arrow'>❯</div>");
let perArrowNow = $('.period-arrow');
perArrowNow.addClass('period-arrow-visible');
blinkActive(".period-arrow-visible");
} else {
// Stop any current period arrow animations
box.html(currPerInt);
box.addClass('period-box-active');
rollingBorderPeriod = box.rollingBorder({
padding: 0,
color: "black",
width: 7,
length: "100%"
});
}
formatScreen();
}
observerPeriod = new MutationObserver(updatePeriod);
// Do an initial update on open
updatePeriod();
observerPeriod.observe(targetNodePeriod, observerConfig);
// Read and implement number of match periods
// Only re-write period boxes on selector change
function updateNoPeriods () {
// End any and all period-related animations, and then remove any styles
// this might create
// let periodRelated = $("[class^=period-]");
// periodRelated.removeClass('period-box-active').removeClass('period-arrow-visible');
// periodRelated.finish();
// periodRelated.css('background-color', '').css('opacity', '');
//
// matchPeriod = $('#match-period');
// matchPeriod.html('');
// noPeriods = window.opener.$('#match-timer-no-periods').val();
// // console.log('noPeriods = ' + noPeriods);
// // for (let i = 1; i <= noPeriods; i++) {
// // matchPeriod.append("<div id='period-" + i + "' class='period-box'>" + i + "</div>");
// // if (i < noPeriods) {
// // matchPeriod.append("<div id='period-arrow-" + i + "-" + (i+1) + "' class='period-arrow'>❯</div>")
// // }
// // }
// let adverts = $('#advertising');
// // if (noPeriods > 5) {
// // adverts.css('visibility', 'hidden');
// // } else {
// // adverts.css('visibility', 'visible');
// // }
updateTimer();
updatePeriod();
formatScreen();
}
updateNoPeriods();
window.opener.$('#match-timer-no-periods').change(function () {
// Something goes wrong with the animations that blows up the system - need to just do a reload
// This shouldn't in game anyway.... hopefully.
window.location.reload();
});
function updateScores () {
var homeScore, awayScore, homeImg, awayImg;
homeScore = $('#team-score-home');
awayScore = $('#team-score-away');
homeImg = $('#team-img-home');
awayImg = $('#team-img-away');
var currHomeName = window.opener.$('#team-home option:selected').text();
$('#team-name-home td').text(currHomeName);
var currHomeStyle = window.opener.$('#team-img-home').attr('style');
homeImg.attr('style', currHomeStyle);
var currHomeScoreStyle = window.opener.$('#team-score-home').attr('style');
homeScore.attr('style', currHomeScoreStyle);
var currHomeScore = window.opener.$('#team-score-home').text();
homeScore.text( currHomeScore );
// console.log(homeScore.attr('style'));
homeImg.css('color', homeScore.css('color'));
awayScore.css("background-color", bgcol);
var currAwayName = window.opener.$('#team-away option:selected').text();
$('#team-name-away td').text(currAwayName);
var currAwayStyle = window.opener.$('#team-img-away').attr('style');
awayImg.attr('style', currAwayStyle);
var currAwayScoreStyle = window.opener.$('#team-score-away').attr('style');
awayScore.attr('style', currAwayScoreStyle);
var currAwayScore = window.opener.$('#team-score-away').text();
awayScore.text( currAwayScore );
awayImg.css('color', awayScore.css('color'));
// Add a border if the box bg colour matches the screen background
let homePrimaryColor = homeImg.css("background-color");
let homeSecondaryColor = homeScore.css("color");
let awayPrimaryColor = awayImg.css("background-color");
let awaySecondaryColor = awayScore.css("color");
console.log(awayPrimaryColor);
console.log(RGBStrToHSL(awayPrimaryColor));
console.log(awaySecondaryColor);
console.log(RGBStrToHSL(awaySecondaryColor));
let homeColors = [homePrimaryColor, homeSecondaryColor];
let awayColors = [awayPrimaryColor, awaySecondaryColor];
let homeColorsL = homeColors.map((rgb) => RGBStrToHSL(rgb)[2]);
let awayColorsL = awayColors.map((rgb) => RGBStrToHSL(rgb)[2]);
console.log(homeColorsL);
console.log(awayColorsL);
let homeColorLightest = "white";
let awayColorLightest = "white";
var bgcol = $( 'body' ).css('background-color');
// Force the scores to have bgcol background, and text in the lighter of the two
// team colours
awayScore.css("background-color", bgcol);
// awayScore.css("color", "rgb(255,255,255)");
homeScore.css("background-color", bgcol);
// awayScore.css("color", "rgb(255,255,255)");
[
'#team-score-home',
'#team-score-away',
'#team-img-away',
'#team-img-home'
].forEach(function (e) {
var elem = $(e);
if (elem.css('background-color') == bgcol) {
elem.css('border', scoreBorderSize + ' solid gray');
if ((e == "#team-score-home") || (e == "#team-img-home")) {
if (homePrimaryColor != bgcol) {
elem.css('border-color', homePrimaryColor);
} else {
elem.css('border-color', homeSecondaryColor);
}
if (e == "#team-score-home") {
// Set score to display in lightest team colour
elem.css("color", homeColorLightest);
}
} else if ((e == "#team-score-away") || (e == "#team-img-away")) {
if (awayPrimaryColor != bgcol) {
elem.css('border-color', awayPrimaryColor);
} else {
elem.css('border-color', awaySecondaryColor);
}
if (e == "#team-score-away") {
// Set score to display in lightest team colour
elem.css("color", awayColorLightest);
}
}
} else {
elem.css('border', scoreBorderSize + ' solid none');
elem.css('border-color', elem.css('background-color'));
}
if ((e == "#team-img-home") || (e == "#team-score-away")) {
elem.css('border-right-width', '0');
} else {
elem.css('border-left-width', '0');
}
})
formatScreen();
}
// Team information observer
targetNodeTeams = window.opener.document.querySelector('#team-attributes');
observerTeams = new MutationObserver(function (mutations) {
updateScores();
});
observerTeams.observe(targetNodeTeams, observerConfig);
updateScores();
$( window ).resize(function () {
setTimeout(function(){window.location.reload()}, 300);
});
})
// window.onresize = function () {
// formatScreen();
// console.log('Resize!');
// });
</script>
</head>
<body>
<!--<div class='bgimage' id='tourney-logo' style='background-image:url(./img/tourney/FACTBanner.png)'></div>-->
<div id='match-timer'></div>
<div id='match-period' class="period-box">
1
</div>
<div id='advertising'>
<table>
<tr><td><img src='./img/bm_afa_act_logo_white_transparent_rgb.png' /></td>
<td rowspan=2 id='advertising-space' class='bgimage'></td></tr>
<tr><td>is proudly supported by:</td></tr>
</table>
</div>
<table class='team-name' id='team-name-home'>
<td></td>
</table>
<div class='bgimage team-logo' id='team-img-home'></div>
<div class='bgimage team-score' id='team-score-home'></div>
<table class='team-name' id='team-name-away'>
<td></td>
</table>
<div class='bgimage team-logo' id='team-img-away'></div>
<div class='bgimage team-score' id='team-score-away'></div>
</body>
</html>