-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtimeline.js
106 lines (93 loc) · 3.64 KB
/
timeline.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
$(document).ready(function () {
$.get("stories.json", function (data) {
var timelines = {};
var idx = 0;
data.timelines.map(function (timeline) {
timeline.idx = idx;
timelines[timeline.title] = timeline;
var eltimeline = $(".template .timeline").clone();
eltimeline.addClass(timeline.color);
eltimeline.prepend(timeline.title);
$(".timelines").append(eltimeline);
idx++;
});
data.stories.map(function (story) {
var timeline = timelines[story.timeline];
var elstory = $(".template .story").clone();
elstory.addClass(timeline.color);
elstory.find(".time .main").html(story.time);
elstory.find(".info .title").append(story.title);
elstory.find(".info .more").append(story.content);
if (story.sources) {
story.sources.map(function (source) {
var link = $("<a class='pull-right'><i class='fa fa-external-link'></i></a>")
link.attr({href: source});
elstory.find(".info .title").append(link);
});
}
if (story.minor) elstory.addClass("minor");
if (timeline.idx < data.timelines.length / 2) {
elstory.addClass("left");
for (var i = 0; i < timeline.idx; i++) {
elstory.find(".time").append("<div class='timeline-bump'>");
elstory.find(".info-wrapper").append("<div class='timeline-bump'>");
}
for (var i = 0; i < data.timelines.length / 2 - timeline.idx - 1; i++) {
elstory.append("<div class='timeline-bump'>");
}
elstory.append("<div class='even-bump'>");
elstory.append("<div class='side-bump'>");
} else {
elstory.addClass("right");
for (var i = 0; i < data.timelines.length - timeline.idx - 1; i++) {
elstory.find(".time").prepend("<div class='timeline-bump'>");
elstory.find(".info-wrapper").prepend("<div class='timeline-bump'>");
}
for (var i = 0; i < timeline.idx - data.timelines.length / 2; i++) {
elstory.prepend("<div class='timeline-bump'>");
}
elstory.prepend("<div class='even-bump'>");
elstory.prepend("<div class='side-bump'>");
}
(function (story) {
var timeout;
var info = story.find(".info");
info.mouseenter(function () {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function () {
timeout = undefined;
if (story.hasClass("minor")) {
if (story.hasClass("left")) {
story.find(".story-wrapper").animate({"padding-left": 0});
} else {
story.find(".story-wrapper").animate({"padding-right": 0});
}
story.addClass("minor-expanded");
story.removeClass("minor");
}
story.addClass("expanded");
story.find(".more").slideDown();
}, 500);
});
info.mouseleave(function () {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function () {
timeout = undefined;
story.removeClass("expanded");
story.find(".more").slideUp();
if (story.hasClass("minor-expanded")) {
if (story.hasClass("left")) {
story.find(".story-wrapper").animate({"padding-left": "30%"});
} else {
story.find(".story-wrapper").animate({"padding-right": "30%"});
}
story.addClass("minor");
story.removeClass("minor-expanded");
}
}, 500);
});
})(elstory);
$(".stories .inner-stories").append(elstory);
});
}, "json");
});