-
Notifications
You must be signed in to change notification settings - Fork 0
/
drag_handler.js
46 lines (44 loc) · 1.81 KB
/
drag_handler.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
function addDragging(element, getParentLeft, cb) {
element.onmousedown = event => {
if(event.which == 1) {
function move(event) {
element.style.left = event.pageX - parseInt(getParentLeft()) - columns.sidebarWidth + 'px'
}
function end(event) {
removeEventListener('mousemove', move)
removeEventListener('mouseup', end)
cb(Math.floor((event.pageX - columns.sidebarWidth) / columns.columnWidth) + columns.baseID)
}
addEventListener('mousemove', move)
addEventListener('mouseup', end)
}
}
element.addEventListener('mousedown', event => {
event.preventDefault()
})
}
function addResizing(element, getDistanceToLeft, cb) {
element.addEventListener('mousemove', event => {
if(event.clientX > element.getBoundingClientRect().right - 10 && event.target.classList != 'projectCreateSlotButton') element.style.cursor = 'e-resize'
else element.style.cursor = 'initial'
})
element.addEventListener('mouseout', event => {
element.style.cursor = 'initial'
})
element.addEventListener('mousedown', event => {
if(event.target.classList != 'projectCreateSlotButton') {
function move(event) {
element.style.width = event.clientX - parseInt(getDistanceToLeft()) + 'px'
}
function end(event) {
cb(event.clientX - parseInt(getDistanceToLeft()))
removeEventListener('mouseup', end)
removeEventListener('mousemove', move)
}
if(event.clientX > element.getBoundingClientRect().right - 10) {
addEventListener('mouseup', end)
addEventListener('mousemove', move)
}
}
})
}