Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
EmulatorOS
GitHub Repository: EmulatorOS/attaeht.github.io
Path: blob/main/ehtsite/assets/games/subway/js/loading.js
2252 views
1
/* eslint-disable prefer-template */
2
/* eslint-disable func-names */
3
/* eslint-disable no-var */
4
5
function LoadingBar()
6
{
7
var showing = false;
8
var width = 300;
9
var height = 30;
10
var border = 4;
11
var total = 0;
12
13
var container = document.createElement('div');
14
15
container.style.position = 'fixed';
16
container.style.width = width + 'px';
17
container.style.height = height + 'px';
18
container.style.zIndex = 999;
19
20
var base = document.createElement('div');
21
22
base.style.position = 'absolute';
23
base.style.width = width + 'px';
24
base.style.height = height + 'px';
25
base.style.backgroundColor = 'rgba(0, 0, 0, 0.75)';
26
container.appendChild(base);
27
28
var bar = document.createElement('div');
29
30
bar.style.position = 'absolute';
31
bar.style.left = border + 'px';
32
bar.style.top = border + 'px';
33
bar.style.width = (width - (border * 2)) + 'px';
34
bar.style.height = (height - (border * 2)) + 'px';
35
bar.style.backgroundColor = '#f65000';
36
container.appendChild(bar);
37
38
var label = document.createElement('div');
39
40
label.style.position = 'fixed';
41
label.style.width = width + 'px';
42
label.style.height = height + 'px';
43
label.style.lineHeight = height + 'px';
44
label.style.textAlign = 'center';
45
label.style.color = '#FFFFFF';
46
label.style.fontWeight = 'bold';
47
label.style.fontSize = '12px';
48
label.style.fontFamily = '"Verdana", sans-serif';
49
container.appendChild(label);
50
51
function resize()
52
{
53
container.style.left = ((window.innerWidth * 0.5) - (width * 0.5)) + 'px';
54
container.style.top = ((window.innerHeight * 0.5) + 120) + 'px';
55
}
56
57
function show()
58
{
59
if (showing) return;
60
showing = true;
61
document.body.appendChild(container);
62
window.addEventListener('resize', resize);
63
setProgress(0);
64
resize();
65
}
66
67
function hide()
68
{
69
if (!showing) return;
70
showing = false;
71
container.remove();
72
window.removeEventListener('resize', resize);
73
}
74
75
function setTotal(mbs)
76
{
77
total = mbs;
78
}
79
80
function setProgress(ratio)
81
{
82
if (ratio < 0) ratio = 0;
83
if (ratio > 1) ratio = 1;
84
85
var barMaxWidth = width - (border * 2);
86
var percent = Math.round(ratio * 100) + '%';
87
88
bar.style.width = (barMaxWidth * ratio) + 'px';
89
90
if (total)
91
{
92
var loaded = (total * ratio).toFixed(1);
93
var mbs = loaded + '/' + total + ' MB';
94
95
label.innerText = percent + ' - ' + mbs;
96
}
97
else
98
{
99
label.innerText = percent;
100
}
101
}
102
103
show();
104
this.show = show;
105
this.hide = hide;
106
this.setTotal = setTotal;
107
this.setProgress = setProgress;
108
}
109
110
window.loadingBar = new LoadingBar();
111
112