forked from dcloudio/mui
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmui.gestures.drag.js
54 lines (53 loc) · 1.37 KB
/
mui.gestures.drag.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
/**
* mui gesture drag[start|left|right|up|down|end]
* @param {type} $
* @param {type} name
* @returns {undefined}
*/
(function($, name) {
var handle = function(event, touch) {
var session = $.gestures.session;
switch (event.type) {
case $.EVENT_START:
break;
case $.EVENT_MOVE:
if (!touch.direction || !session.target) {
return;
}
//修正direction,可在session期间自行锁定拖拽方向,方便开发scroll类不同方向拖拽插件嵌套
if (session.lockDirection && session.startDirection) {
if (session.startDirection && session.startDirection !== touch.direction) {
if (session.startDirection === 'up' || session.startDirection === 'down') {
touch.direction = touch.deltaY < 0 ? 'up' : 'down';
} else {
touch.direction = touch.deltaX < 0 ? 'left' : 'right';
}
}
}
if (!session.drag) {
session.drag = true;
$.trigger(session.target, name + 'start', touch);
}
$.trigger(session.target, name, touch);
$.trigger(session.target, name + touch.direction, touch);
break;
case $.EVENT_END:
case $.EVENT_CANCEL:
if (session.drag && touch.isFinal) {
$.trigger(session.target, name + 'end', touch);
}
break;
}
};
/**
* mui gesture drag
*/
$.addGesture({
name: name,
index: 20,
handle: handle,
options: {
fingers: 1
}
});
})(mui, 'drag');