blob: a299701b00455d85c9859e3fda38a595740e5d64 (
plain)
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
|
function part_to_hour (f) {
return Math.floor(10 * 24 * f) / 10;
}
var start_time = 0
var start_fraq = 0
var parent
var createdEvents = false
function onmousedownhandler (e) {
last = this
event = e
var comp = this
console.log(comp.clientHeight)
while (! comp.classList.contains("events")) {
comp = comp.parentElement
}
console.log(e);
parent = comp
console.log(comp.clientHeight)
fraq = e.offsetY / comp.clientHeight
start_fraq = fraq
start_time = part_to_hour(fraq);
createdEvent = document.createElement("div");
createdEvent.className = "event generated";
createdEvent.style.pointerEvents = "none";
createdEvent.style.width = "100%";
createdEvent.style.top = fraq * 100 + "%";
createdEvent.innerText = "New Event";
}
function onmousemovehandler (e) {
if (createdEvent) {
fraq = e.offsetY / this.clientHeight
var diff = fraq - start_fraq;
if (! createdEvent.parentElement) {
for (let e of this.children) {
e.style.pointerEvents = "none";
}
this.appendChild(createdEvent);
}
createdEvent.style.height = diff * 100 + "%";
}
}
function onmouseuphandler (e) {
var end_time = part_to_hour(e.offsetY / this.clientHeight);
console.log("Creating event " + start_time + " - " + end_time);
createdEvent = false;
for (let e of parent.children) {
e.style.pointerEvents = "initial";
}
}
window.onload = function () {
for (let c of document.getElementsByClassName("events")) {
c.onmousedown = onmousedownhandler;
c.onmouseup = onmouseuphandler;
c.onmousemove = onmousemovehandler;
}
}
|