-
Notifications
You must be signed in to change notification settings - Fork 0
/
timelines.html
executable file
·145 lines (138 loc) · 4.97 KB
/
timelines.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
<!DOCTYPE html>
<html>
<head>
<title>jQuery test</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link type="text/css" href="test.css" rel="stylesheet" />
</head>
<body>
<meta charset="utf-8">
<div class="container rounded_left rounded_right" pointTime="0" dx="0" sppx="30"></div>
<a id = "clickme">click</a>
<script>
function draw()
{
$("div.container").each(function()
{
w = parseInt($(this).css("width"));
$($(this).children().get(0)).css("left", "" + (w - 100) + "px");
sppx = parseInt($(this).attr("sppx"));
if((60 / sppx) > 30)
{
$($(this).children().get(2)).attr("interval", "60");
}
else if((3600 / sppx) > 30)
{
$($(this).children().get(2)).attr("interval", "3600");
}
else
{
$($(this).children().get(2)).attr("interval", "86400");
}
$(this).children("div.bglines").empty();
pointTime = parseInt($(this).attr("pointTime"));
sppx = parseInt($(this).attr("sppx"));
interval = parseInt($(this).children("div.bglines").attr("interval"));
pxinterval = interval * 1.0 / sppx;
x = (pointTime % interval);
x = x * 1.0 / sppx;
while(0 - x + $(this).width() / 2 > 0)
{
x = x + pxinterval;
}
for(i = 0; (pxinterval * i) / 6 - x + $(this).width() / 2 < $(this).width() - 15; i++)
{
if((pxinterval * i) / 6 - x + $(this).width() / 2 - 15 < 0)
{
continue;
}
if(i % 6 == 0)
{
$("div.bglines").append('<div class="vr" style="left:' + Math.floor((pxinterval * i) / 6 - x - 15 + $(this).width() / 2) + 'px"></div>');
}
else
{
$("div.bglines").append('<div class="vr" style="background-color:rgba(0, 0, 0, 0.3); left:' + Math.floor((pxinterval * i) / 6 - x - 15 + $(this).width() / 2) + 'px"></div>');
}
}
$(this).find("div.timeline").each(function()
{
w = parseInt($(this).css("width"));
$(this).children("div.activity").each(function()
{
startTime = parseInt($(this).attr("startTime"));
endTime = parseInt($(this).attr("endTime"));
$(this).css("width", ((endTime - startTime) * 1.0 / sppx) + "px");
$(this).css("left", (((startTime - pointTime) * 1.0 / sppx) + w / 2) + "px");
});
});
});
}
function addTimeline1()
{
$("div.timelineholder1 > ul.sortable").prepend('<li><div class="timeline"></div></li>');
$($("div.timelineholder1 > ul.sortable").children().get(0)).find(".timeline").each(function()
{
});
}
function addTimeline2()
{
$("div.timelineholder2 > ul.sortable").prepend('<li><div class="timeline"></div></li>');
$($("div.timelineholder2 > ul.sortable").children().get(0)).find(".timeline").each(function()
{
});
}
function makeClickable()
{
$("#clickme").attr("href", "javascript:void(0);").bind("click", function()
{
$($("div.timelineholder1 > ul.sortable > li > div.timeline").get(0)).append($($("div.activity").get(0)).clone());
});
}
$(function()
{
$("div.container").each(function()
{
w = parseInt($(this).css("width"));
$(this).empty();
$(this).append('<div class="control rounded_right"></span></div>')
.append('<div class="control rounded_left"></div>')
.append('<div class="bglines rounded_left rounded_right"></div>')
.append('<div class="timelineholder1"><ul class="sortable"><li><div class="timeline"></div></li><li><div class="timeline"></div></li></ul></div>')
.append('<div class="timelineholder2"><ul class="sortable"><li><div class="timeline"></div></li><li><div class="timeline"><div class="activity" startTime=0 endTime=3600 style="top:10px; left:50px;width: 150px;" onclick="makeClickable()">doing stuff!!</div></div></li></ul></div>');
$(".sortable").each(function()
{
$(this).sortable({forcePlaceholderSize: true, placeholder: 'ui-state-highlight'});
});
$($(this).children().get(0)).css("left", "" + (w - 100) + "px").hover(function(e)
{
$(this).parent().attr("dx", "10");
},
function(e)
{
$(this).parent().attr("dx", "0");
});
$($(this).children().get(1)).hover(function(e)
{
$(this).parent().attr("dx", "-10");
},
function(e)
{
$(this).parent().attr("dx", "0");
});
});
setInterval(function()
{
$("div.container").each(function()
{
dx = parseInt($(this).attr("dx"));
sppx = parseInt($(this).attr("sppx"));
$(this).attr("pointTime", (parseInt($(this).attr("pointTime")) + dx * sppx) + "");
draw();
});
}, 5);
});
</script>
</body>
</html>