This repository has been archived by the owner on Jan 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swipe-corners.js
executable file
·67 lines (63 loc) · 2.31 KB
/
swipe-corners.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
55
56
57
58
59
60
61
62
63
64
65
66
67
$(function () {
// If true allow the corners swipe events, otherwise just allow the four basic points (left, right, up, down)
$.event.special.swipe.allowCornerSwipe = true;
// JQ registration point
$.each({
swipeUp: "swipe",
swipeDown: "swipe",
swipeBottomRight: "swipe",
swipeBottomLeft: "swipe",
swipeTopRight: "swipe",
swipeTopLeft: "swipe"
}, function( event, sourceEvent ){
$.event.special[ event ] = {
setup: function() {
$( this ).bind( sourceEvent, $.noop );
}
};
});
$.each( ( "swipeUp swipeDown swipeBottomRight " +
"swipeBottomLeft swipeTopRight swipeTopLeft" ).split( " " ), function( i, name ) {
$.fn[ name ] = function( fn ) {
return fn ? this.bind( name, fn ) : this.trigger( name );
};
});
// swipe handler override
$.event.special.swipe.handleSwipe = function ( start, stop ) {
var enoughTime = (stop.time - start.time < $.event.special.swipe.durationThreshold),
vMovement = Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ),
hMovement = Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ),
enoughVMovement = (vMovement > $.event.special.swipe.horizontalDistanceThreshold),
enoughHMovement = (hMovement > $.event.special.swipe.horizontalDistanceThreshold),
positiveVMovement = (start.coords[ 1 ] < stop.coords[ 1 ]),
positiveHMovement = (start.coords[ 0 ] < stop.coords[ 0 ]),
isCornerSwipe = (enoughHMovement && enoughVMovement),
xorDirectional = (enoughHMovement)?!enoughVMovement:enoughVMovement,
swipeEventType = "swipe";
if($.event.special.swipe.allowCornerSwipe && isCornerSwipe && enoughTime){
if(positiveVMovement){
swipeEventType = (positiveHMovement)?"swipeBottomRight":"swipeBottomLeft";
}
else{
swipeEventType = (positiveHMovement)?"swipeTopRight":"swipeTopLeft"
}
start.origin.trigger("swipe").trigger(swipeEventType);
}
else{
if(xorDirectional && enoughTime){
if(enoughVMovement){
if(vMovement > $.event.special.swipe.verticalDistanceThreshold){
swipeEventType = (positiveVMovement)?"swipeDown":"swipeUp";
start.origin.trigger("swipe").trigger(swipeEventType);
}
}
else{
if(hMovement > $.event.special.swipe.verticalDistanceThreshold){
swipeEventType = (positiveHMovement)?"swiperight":"swipeleft";
start.origin.trigger("swipe").trigger(swipeEventType);
}
}
}
}
}
})