-
Notifications
You must be signed in to change notification settings - Fork 5
/
drip-drop.js
42 lines (34 loc) · 1.36 KB
/
drip-drop.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
exports.drop = require('./drop')
exports.drag = require('./drag')
exports.dontPreventDefault = function() {
document.removeEventListener('dragenter', docEnterHandler, true)
document.removeEventListener('dragover', docOverHandler, true)
}
// returns an opaque clone of the passed dom node ready to be moved with moveToMouse
exports.ghostItem = function(domNode, zIndex) {
if(zIndex === undefined) zIndex = 1000
var aClone = domNode.cloneNode(true)
aClone.style.position = 'absolute'
aClone.style.top = '-100px'
aClone.style.width = domNode.clientWidth+'px'
aClone.style.opacity = '.6'
aClone.style.pointerEvents = 'none' // makes this 'invisible' to mouse events so it doesn't block mouse events while you're dragging it around
aClone.style['z-index'] = zIndex
return aClone
}
// moves an absolutely positioned element to the position by x and y
exports.moveAbsoluteNode = function(node, x, y) {
node.style.left = x+'px'
node.style.top = y+'px'
}
// get rid of the need to do this for other drag events
var docEnterHandler, docOverHandler;
document.addEventListener('dragenter',docEnterHandler=function(e){
e.preventDefault()
}, true)
document.addEventListener('dragover',docOverHandler=function(e){
e.preventDefault()
}, true)
//document.addEventListener('dragstart',docOverHandler=function(e){
// e.preventDefault()
//})