-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscript.js
224 lines (183 loc) · 5.29 KB
/
script.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
var $ = function(id) { return document.getElementById(id); };
var show_IntervalSec = 10;
var show_MonitorWidth = 101;
var show_MonitorHeight = 99;
function g_Init()
{
if (document.location.host.indexOf('cgru.info') != -1)
$('sflogo').innerHTML = '<img src="https://sflogo.sourceforge.net/sflogo.php?group_id=178692&type=12" width="120" height="30" border="0" alt="SourceForge.net"/>';
document.body.onkeydown = g_OnKeyDown;
$('ontop').onclick = function(e){
g_DisplayOnTop(false);
};
let forontops = $('content').getElementsByClassName('forontop');
for (let i = 0; i < forontops.length; i++)
forontops[i].onclick = function(e){ g_ForOnTopClicked(e.currentTarget);};
// Show famous project images
// Calculate sizes
show_MonitorWidth = Math.round($('framecontent').clientWidth / 5);
show_MonitorHeight = Math.round(show_MonitorWidth / 2.5);
$('show_left').style.width = show_MonitorWidth + 'px';
$('show_right').style.width = show_MonitorWidth + 'px';
$('content').style.left = (show_MonitorWidth + 3) + 'px';
$('content').style.right = (show_MonitorWidth + 3) + 'px';
// Calculate show monitors count
let monitors_count = Math.ceil($('show_right').clientHeight / show_MonitorHeight);
if (monitors_count >= ShowData.length/2)
monitors_count = ShowData.length/2 - 1;
//console.log('Show height:' + $('show_right').clientHeight + ', count:' + monitors_count);
// Create monitors
for (let i = 0; i < monitors_count; i++)
{
new ShowMonitor($('show_left'));
new ShowMonitor($('show_right'));
}
// Create software icons
for (let i = 0; i < SoftwareIconsData.length; i++)
{
let path = SoftwareIconsData[i].icon;
let name = path.split('/').pop();
name = name.split('.')[0];
let el = document.createElement('div');
let elImg = document.createElement('img');
el.appendChild(elImg);
elImg.src = '/' + path;
elImg.height = 64;
let elName = document.createElement('div');
el.appendChild(elName);
elName.textContent = name;
$('software_icons').appendChild(el);
}
// Create studios logos
for (let i = 0; i < StudioLogosData.length; i++)
{
let path = StudioLogosData[i].logo;
let link = path;
link = link.replace(/\.(png|svg)/,'')
link = link.replace(/.*___/,'');
if (path.indexOf('___http___') != -1)
link = 'http://' + link;
else
link = 'https://' + link;
let el = document.createElement('a');
el.href = link;
el.target = '_blank';
let elImg = document.createElement('img');
elImg.m_el = el;
elImg.src = '/' + path;
elImg.onload = g_StudioLogoOnLoad;
$('studios').appendChild(el);
}
}
function g_StudioLogoOnLoad(i_evt)
{
let img = i_evt.currentTarget;
let aspect = img.naturalWidth / img.naturalHeight;
let el = img.m_el;
let height = 64;
let width = 256;
if (aspect > 2.0)
{
el.style.width = width + 'px';
}
else
{
el.style.width = height * aspect + 'px';
}
el.style.height = height + 'px';
el.style.backgroundImage = 'url(' + img.src + ')';
$('studios').classList.add('loaded');
}
function g_OnKeyDown(i_evt)
{
g_DisplayOnTop(false);
switch (i_evt.keyCode)
{
case 27: // ESC
break;
}
}
function g_ForOnTopClicked(i_el)
{
g_DisplayOnTop('<img src="'+i_el.getAttribute('img')+'"/>');
}
function g_DisplayOnTop(i_msg)
{
let display = false;
if (i_msg == null)
{
display = false;
}
else if (i_msg.length)
{
$('ontop').innerHTML = i_msg;
display = true;
}
else
{
display = false;
}
$('ontop').style.display = display ? 'block':'none';
}
function ShowMonitor(i_elShow)
{
this.elShow = i_elShow;
this.elMon = document.createElement('div');
this.elMon.classList.add('show_monitor');
this.elShow.appendChild(this.elMon);
this.elDivs = [];
for (let i = 0; i < 2; i++)
{
let elDiv = document.createElement('div');
this.elMon.appendChild(elDiv);
elDiv.classList.add('show_div');
//elDiv.style.backgroundSize = 'auto 120%';
elDiv.style.backgroundSize = 'cover';
elDiv.style.height = show_MonitorHeight + 'px';
elDiv.onclick = function(e) {g_ForOnTopClicked(e.currentTarget);};
this.elDivs.push(elDiv);
}
this.index = 0;
this.imgNum = -1;
this.update(true);
}
show_ImageNums = [];
ShowMonitor.prototype.update = function(i_first_time) {
let next = 1 - this.index;
if (i_first_time)
next = 0;
// We should not display the same images in the same time.
// Find a new image number that is not displayed now.
let new_img_num = -1;
do
{
new_img_num = Math.floor(Math.random() * ShowData.length);
}
while (show_ImageNums.indexOf(new_img_num) != -1);
// Remove previous image number from an array
let prev_num_index = show_ImageNums.indexOf(this.imgNum);
if (prev_num_index != -1)
show_ImageNums.splice(prev_num_index, 1);
// Apply a new image number and to store it in array
this.imgNum = new_img_num;
show_ImageNums.push(this.imgNum);
let item = ShowData[this.imgNum];
let img = '/' + item.image;
let thumb = '/' + item.thumbnail;
this.elDivs[next].style.backgroundImage = 'url(' + thumb + ')';
this.elDivs[next].setAttribute('img', img);
// Set a timeout to call this function again
setTimeout(ShowMonitorUpdate, 1000 * show_IntervalSec * (1+Math.random()), this);
if (i_first_time)
return;
if (this.index)
{
this.elMon.classList.remove('shifted');
}
else
{
this.elMon.classList.add('shifted');
}
this.index = 1 - this.index;
};
function ShowMonitorUpdate(i_monitor){i_monitor.update()}