generated from NewcastleRSE/Standard-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
291 lines (224 loc) · 10.1 KB
/
index.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
---
layout: default
title: Home Page
---
<body>
<div class="app-wrapper">
<main>
<!-- banner -->
<div id="banner" class="overflow-x-hidden">
<!-- recruitment progress scale (really a slider) -->
<!-- <input type="text" class="slider1" name="progress" text="Recruitment progress" min="0" max="1460" value="260"> -->
<div class="mt-4 mb-4 whitespace-nowrap scroll text-primary text-sm">
<span class="mx-8 text-4xl item ">We currently have {{site.data.banner.participants}} participants recruited to SWEET, {{site.data.banner.percentage}} of our 1460 target.</span>
<span class="mx-8 text-4xl item">We currently have {{site.data.banner.participants}} participants recruited to SWEET, {{site.data.banner.percentage}} of our 1460 target.</span>
<span class="mx-8 text-4xl item">We currently have {{site.data.banner.participants}} participants recruited to SWEET, {{site.data.banner.percentage}} of our 1460 target.</span>
<span class="mx-8 text-4xl item">We currently have {{site.data.banner.participants}} participants recruited to SWEET, {{site.data.banner.percentage}} of our 1460 target.</span>
<span class="mx-8 text-4xl item">We currently have {{site.data.banner.participants}} participants recruited to SWEET, {{site.data.banner.percentage}} of our 1460 target.</span>
<span class="mx-8 text-4xl item">We currently have {{site.data.banner.participants}} participants recruited to SWEET, {{site.data.banner.percentage}} of our 1460 target.</span>
</div>
</div>
<!-- Hero -->
{% include hero.html title = site.data.hero.title alert = site.data.hero.alert cta =
site.data.hero.btnText ctaHref = site.data.hero.sendTo description =
site.data.hero.blurb subdescription=site.data.hero.blurb2 participants=site.data.hero.participants %}
</main>
</div>
<script src="script.js">
</script>
<script>
var mousePosition, active_element;
var offset = [0,0];
var isDown = false;
var slider_min = -11;
var default_range = [0,100];
var default_round = 0;
var default_color = '#7ef4ff';
var slider_positions = {};
var slider_percentages = {};
var slider_values = {};
document.addEventListener('mouseup', function() {
isDown = false;
document.body.style.webkitUserSelect = '';
document.body.style.mozUserSelect = '';
document.body.style.msUserSelect = '';
}, true);
document.addEventListener('mousemove', function(event) {
if (isDown) {
mousePosition = {x:event.clientX, y:event.clientY};
var current_input = active_element.parentElement.parentElement.parentElement.childNodes[1];
var slider_groover = active_element.parentElement.firstChild;
var name = current_input.name;
var slider_max = slider_groover.clientWidth+slider_min;
var min = parseFloat(current_input.min);
var max = parseFloat(current_input.max);
if ((min !== '' && max !== '') && (min < max)) {
var range = [min, max]
} else {
var range = default_range;
}
var left_pos = mousePosition.x + offset[0];
if (left_pos < slider_min) {
slider_positions[name] = slider_min;
} else if (left_pos > slider_max) {
slider_positions[name] = slider_max+2;
} else {
slider_positions[name] = left_pos;
}
var percentages = 100*(slider_positions[name]-slider_min-2)/slider_groover.clientWidth;
var value = range[0]+(range[1]-range[0])*percentages/100;
setSliderTo(name, value);
}
}, true);
var sliders = document.getElementsByClassName('slider1');
for (var i = 0; i < sliders.length; i++) {
var slider_parent = createSuperElement('div', {'class':'slider1_parent'});
sliders[i].parentNode.insertBefore(slider_parent, sliders[i]);
slider_parent.appendChild(sliders[i]);
if (sliders[i].getAttribute('text')) {
var text = createSuperElement('p', {'class':'title'}, sliders[i].getAttribute('text'));
} else {
var text = createSuperElement('span');
}
slider_parent.insertBefore(text, sliders[i]);
var color = sliders[i].getAttribute('color') !== null ? sliders[i].getAttribute('color') : default_color;
var slider_main_block = createSuperElement('div', {'class':'main_block'});
var slider_groove_parent = createSuperElement('div', {'class':'groove_parent'});
var slider_groove = createSuperElement('div', {'class':'groove'});
var slider_fill = createSuperElement('div', {'class':'fill'}, '', {'background-color':color});
var slider_rider = createSuperElement('div', {'class':'rider'});
var total = createSuperElement('p', {'class':'total'});
total.innerHTML = sliders[i].value;
var min = parseFloat(sliders[i].min);
var max = parseFloat(sliders[i].max);
if ((min !== '' && max !== '') && (min < max)) {
var range = [min, max]
} else {
var range = default_range;
}
var table_data = [[[range[0], {'class':'left'}],[range[1], {'class':'right'}]]];
var slider_range = createSuperTable(table_data, {'class':'slider_range'});
slider_groove.appendChild(slider_fill);
slider_groove_parent.appendChild(slider_groove);
slider_groove_parent.appendChild(slider_rider);
slider_rider.appendChild(total);
slider_main_block.appendChild(slider_groove_parent);
slider_main_block.appendChild(slider_range);
slider_parent.appendChild(slider_main_block);
slider_rider.addEventListener('mousedown', function(e) {
var current_input = this.parentElement.parentElement.parentElement.childNodes[1];
isDown = true;
offset[0] = this.offsetLeft - e.clientX;
active_element = this;
if (current_input.getAttribute('animate') !== 'no') {
this.parentNode.lastChild.style.transition = '';
this.parentNode.firstChild.firstChild.style.transition = '';
}
document.body.style.webkitUserSelect = 'none';
document.body.style.mozUserSelect = 'none';
document.body.style.msUserSelect = 'none';
}, true);
slider_groove.addEventListener('click', function(e) {
var current_input = this.parentElement.parentElement.parentElement.childNodes[1];
var name = current_input.name;
var click_position = e.clientX-my_offset(this).left;
var min = parseFloat(current_input.min);
var max = parseFloat(current_input.max);
if ((min !== '' && max !== '') && (min < max)) {
var range = [min, max]
} else {
var range = default_range;
}
if (current_input.getAttribute('animate') !== 'no') {
this.parentNode.lastChild.style.transition = 'left 0.2s ease-in-out';
this.parentNode.firstChild.firstChild.style.transition = 'width 0.2s ease-in-out';
}
var percentages = 100*(click_position)/(this.clientWidth+2);
var value = range[0]+(range[1]-range[0])*percentages/100;
setSliderTo(name, value);
}, true);
sliders[i].addEventListener('change', function(e) {
setSliderTo(this.name, this.value);
}, true);
if (!sliders[i].value) sliders[i].value = 0;
setSliderTo(sliders[i].name, sliders[i].value);
}
function setSliderTo(name, value) {
var slider = document.getElementsByName(name)[0];
value = parseFloat(value);
var min = parseFloat(slider.min);
var max = parseFloat(slider.max);
if ((min !== '' && max !== '') && (min < max)) {
var range = [min, max]
} else {
var range = default_range;
}
if (value >= range[0] && value <= range[1] && !isNaN(value)) {
var data_round = slider.getAttribute('round') !== null ? slider.getAttribute('round') : default_round;
if (slider.getAttribute('smooth') !== 'yes') value = round(value, data_round);
slider_percentages[name] = 100*(value - range[0])/(range[1] - range[0]);
slider.parentNode.childNodes[2].firstChild.firstChild.firstChild.style.width=round(slider_percentages[name], 2)+'%';
slider.parentNode.childNodes[2].firstChild.lastChild.style.left = 'calc('+round(slider_percentages[name], 2)+'% - 11px )';
value = round(value, data_round);
slider.value = value;
slider_values[name] = value;
} else {
//console.log('Value ['+value+'] is out of slider range: '+range[0]+'-'+range[1] || default_range[1]);
if (value < range[0] && !isNaN(value)) setSliderTo(name, range[0]);
else if (value > range[1] && !isNaN(value)) setSliderTo(name, range[1]);
else slider.value = slider_values[name];
}
try {
slider.onchange();
} catch (err) {}
}
function my_offset(elem) {
if(!elem) elem = this;
var x = elem.offsetLeft;
var y = elem.offsetTop;
while (elem = elem.offsetParent) {
x += elem.offsetLeft;
y += elem.offsetTop;
}
return { left: x, top: y };
}
function round(value, precision) {
var multiplier = Math.pow(10, precision || 0);
return Math.round(value * multiplier) / multiplier;
}
var element;
var table;
function createSuperElement(type, attributes, innerHTML, style) {
if (attributes === undefined) attributes = '';
if (innerHTML === undefined) innerHTML = '';
if (style === undefined) style = '';
element = document.createElement(type);
if (innerHTML !== '' && typeof innerHTML === 'object') element.appendChild(innerHTML);
else if (innerHTML !== '') element.innerHTML = innerHTML;
if (attributes !== '') {
for (var i in attributes) {
element.setAttribute(i, attributes[i]);
}
}
if (style !== '') {
var styles = '';
for (var i in style) {
styles += i+':'+style[i]+';';
}
element.setAttribute('style', styles);
}
return element;
}
function createSuperTable(data, attributes) {
if (attributes === undefined) attributes = '';
table = createSuperElement('table', attributes);
for (var i in data) { // rows
table.appendChild(createSuperElement('tr'));
for (var j in data[i]) { // cells
table.lastChild.appendChild(createSuperElement('td', data[i][j][1], data[i][j][0], data[i][j][2]));
}
}
return table;
}
</script>
</body>