-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
421 lines (359 loc) · 10.5 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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="https://github.com/infusion/jQuery-xcolor/raw/master/jquery.xcolor.min.js"></script>
<style type="text/css">
body {
margin: 0;
padding: 0;
font-size: 62.5%;
}
toparrow {
display: block;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid black;
position: absolute;
}
timeline {
display: block;
width: 100%;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", sans-serif;
font-size: 1.2em;
}
timeline slideout {
display: block;
width: 100%;
height: 0px;
}
timeline slideout close {
display: block;
width: 16px;
height: 16px;
background-color: #000;
}
timeline slideout content {
margin: 0px 16px 16px 16px;
height: 100%;
display: block;
border: 1px solid red;
overflow: hidden;
}
timeline name {
width: 100%;
font-weight: bold;
color: #fff;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.68);
}
timeline subjectGroups {
display: block;
width: 100%;
}
timeline subjectGroups subjectGroup {
display: block;
width: 100%;
height: auto;
border-top: 1pt solid #d9e0e2;
border-bottom: 1pt solid #a4bcc4;
height: 2.5em;
background-color: #fafafa;
}
timeline subjectGroups subjectGroup details {
display: inline-block;
height: 100%;
background-color: #0081bc;
padding: 0em 1.3em 0em 1.3em;
}
timeline subjectGroups subjectGroup details name {
display: block;
width: 100%;
}
timeline subjectGroups subjectGroup eventGroups {
}
timeline subjectGroups subjectGroup eventGroups eventGroup {
display: inline-block;
position: absolute;
width: 10em;
height: 1.5em;
background-color: #81c8bd;
}
timeline subjectGroups subjectGroup eventGroups eventGroup name {
}
</style>
</head>
<body>
<timeline startTime="1354276293">
<subjectGroups>
<subjectGroup uuid="abc">
<details>
<name>subject group 1</name>
</details>
<eventGroups>
<eventGroup startTime="18000" uuid="bcd">
<name>eventGroup A</name>
</eventGroup>
<eventGroup startTime="86400" color="e95fbe" uuid="cde">
<name>eventGroup B</name>
</eventGroup>
<eventGroup startTime="127800" uuid="def">
<name>eventGroup C</name>
</eventGroup>
<eventGroup startTime="302400" color="ff6d37" uuid="efg">
<name>eventGroup N</name>
</eventGroup>
</eventGroups>
</subjectGroup>
<subjectGroup uuid="fgh">
<details>
<name>another long subject group 2</name>
</details>
<eventGroups>
<eventGroup startTime="0" uuid="ghi">
<name>eventGroup D</name>
</eventGroup>
<eventGroup startTime="86400" color="e95fbe" uuid="hij">
<name>eventGroup B</name>
</eventGroup>
<eventGroup startTime="259200" uuid="ijk">
<name>eventGroup E</name>
</eventGroup>
<eventGroup startTime="388800" uuid="jkl">
<name>eventGroup F</name>
</eventGroup>
</eventGroups>
</subjectGroup>
</subjectGroups>
</timeline>
<script type="text/javascript">
$(document).ready(function() {
$('timeline').timeline();
//$('eventGroup').timeline();
});
// jQuery plugin to handle the timeline
(function($){
// plugin methods
var methods = {
// retun the startTime of the latest eventGroup. Note that
// this is relative to the beginning of the timeline / start
// of the study
getStartTimeOfLastEventGroup: function(data,options) {
var startTime = 0;
$('eventGroup', data.me).each(function() {
var relTime = parseInt($(this).attr('startTime'));
if (relTime > startTime) startTime = relTime;
});
return startTime;
},
// position all event groups based on their relative start time
// to the beginning of the study / timeline
initEventGroups: function(data, options) {
$('eventGroup', data.me).each(function() {
// position this event group
methods.positionEventGroup(this, data, options);
// bind on click event
$(this).bind('click', function() {
methods.showDetails(this, data, options);
});
});
},
detailsAnimateSlide: function(eg, slideOut, color, sg, data, options) {
console.log('slide out');
// add slideOut to DOM
slideOut.insertAfter(sg);
// slide out...
slideOut.animate({
'height': '+=200px'
}, options.slideDuration, function() {
console.log('height animation done');
// ...create and slide up the top arrow...
var topArrow = $('<toparrow></toparrow>');
topArrow.css({
'border-bottom-color' :color,
'top' :slideOut.offset().top + 'px',
'left' :eg.offset().left + 'px'
});
slideOut.append(topArrow);
topArrow.animate({ 'top':'-=10px' });
});
var above = (slideOut.nextAll('slideout').length > 0);
var plus = (above) ? '+=200px' : '+=10px'
// and slide other open sliders in...
$('slideout', data.ME).each(function() {
var s = $(this);
if (s.get(0) != slideOut.get(0)) {
// slide in arrow
var a = $('toparrow', s);
a.animate({
'top': plus
}, options.slideDuration / options.slideDurationSpeedup, function() {
a.remove();
});
// slide in and remove element...
s.animate({
'height': '0px'
}, options.slideDuration, function() {
s.remove();
});
}
});
},
detailsClose: function(slideOut, data, options) {
// slide slider in...
slideOut.animate({
'height': '0px'
}, options.slideDuration, function() {
slideOut.remove();
});
// ...and slide arrow down
var t = $('toparrow', slideOut);
t.animate({
'top': '+=10px'
}, options.slideDuration / options.slideDurationSpeedup, function() {
t.remove();
});
},
detailsAnimateTransition: function(eg, slideOut, color, ne, data, options) {
console.log('transition');
// add slideOut to DOM
slideOut.insertAfter(ne);
slideOut.css({
'height': '+=200px',
'margin-top': '-200px',
'opacity' : '0'
});
// ...create the top arrow...
var topArrow = $('<toparrow></toparrow>');
topArrow.css({
'border-bottom-color' :color,
'top' :slideOut.offset().top + 'px',
'left' :eg.offset().left + 'px'
});
slideOut.append(topArrow);
// fade in new slideOut...
slideOut.animate({
'opacity' : '1'
}, options.slideDuration, function() {
console.log('done!');
slideOut.css({ 'margin-top': '0px'});
ne.remove();
topArrow.animate({ 'top':'-=10px' }, options.slideDuration);
});
// ...and arrow...
$('toparrow', ne).animate({ 'top': '+=10px' }, options.slideDuration / options.slideDurationSpeedup);
},
showDetails: function(eg, data, options) {
var EG = $(eg);
var SG = EG.parent().parent();
var NE = SG.next();
var color = EG.css('background-color');
var lightColor = $.xcolor.opacity(color, '#ffffff', 0.8).getRGB();
// var lightColor = $.xcolor.opacity(color, '#f2f2f2', 0.99).getRGB();
// add slideout element
var slideOut = $('<slideout><close></close><content>this should be rendered using an ajax call for eventGroup uuid ' + EG.attr('uuid') + '</content></slideout>');
slideOut.css({'background-color': lightColor});
// fetch details using ajax
console.log('perform ajax call to fill details div with eventGroup information (uuid: '+EG.attr('uuid')+')');
// when done, the following should be executed:
// is the next element also a slideout element?
if (NE && NE.is('slideout')) {
// transition
methods.detailsAnimateTransition(EG, slideOut, lightColor, NE, data, options);
} else {
// slide out
methods.detailsAnimateSlide(EG, slideOut, lightColor, SG, data, options);
}
},
// position one eventGroup based on it's relative start time
// and set a background color if defined
positionEventGroup: function(eg, data, options) {
//console.log('position eventGroup:');
var EG = $(eg);
var startTime = parseInt(EG.attr('startTime'));
var left = (((data.width - data.left) / data.latestRelativeTime) * startTime) + data.left;
// position element
EG.css({ 'left': left });
// does this eventGroup has a color defined?
var c = EG.attr('color');
if (c) EG.css({ 'background-color': '#'+c });
},
// get the max width of the SubjectGroup details
getMaxSubjectGroupDetailsWidth: function(data,options) {
var width = 0;
var outerWidth = 0;
// determine max width
$('subjectGroup > details', data.EM).each(function() {
var w = $(this).width();
var ow = $(this).outerWidth();
if (w > width) width = w;
if (ow > outerWidth) outerWidth = ow;
});
// resize all details elements to this max width
$('subjectGroup > details', data.EM).each(function() {
var e = $(this);
if (e.width() < width) {
e.css( { 'width': width + 'px' } );
}
});
return outerWidth;
},
// get the right position of the SubjectGroup's details, and
// hence the left position/beginning of the timeline
getLeftPosition: function(data,options) {
return $('subjectGroup > details', data.EM).first().outerWidth();
},
bindEventHandlers: function(me, data, options) {
me.on('click', 'close', function () {
methods.detailsClose($(this).parent(), data, options);
});
},
// initialize a timeline
init: function(me,data,options) {
//console.log('* initializing timeline');
//console.log(me);
// get me, myself and I
var ME = $(me);
// reference myself
data.me = me;
data.ME = ME;
// determine start and stop time
data.startTime = parseInt(ME.attr('startTime'));
data.latestRelativeTime = methods.getStartTimeOfLastEventGroup(data,options);
data.endTime = data.startTime + data.latestRelativeTime;
// determine and set timeline width
data.width = ME.width();
data.left = methods.getMaxSubjectGroupDetailsWidth(data,options);
// position eventGroups
methods.initEventGroups(data, options);
// bind event handlers
methods.bindEventHandlers(ME, data, options);
}
};
// define the jquery plugin code
$.fn.timeline = function(options) {
// default settings
var defaults = {
'slideDuration' : 500,
'slideDurationSpeedup' : 2
};
// data
var data = {
};
// extend the jQuery options with the defaults
var options = $.extend(defaults, options);
// iterate through DOM elements and initialize them
return this.each(function() {
methods.init(this,data,options);
console.log('options:');
console.log(options);
console.log('data:');
console.log(data);
});
};
})(jQuery);
</script>
</body>
</html>