forked from visiongeist/toe.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.js
More file actions
58 lines (46 loc) · 2.06 KB
/
transform.js
File metadata and controls
58 lines (46 loc) · 2.06 KB
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
(function ($, touch, window, undefined) {
var namespace = 'transform', cfg = {
scale: 0.1, // minimum
rotation: 15
},
started;
touch.track(namespace, {
touchstart: function (event, state, start) {
started = false;
state[namespace] = {
start: start,
move: []
};
},
touchmove: function (event, state, move) {
var opt = $.extend(cfg, event.data);
if (move.point.length !== 2) {
return;
}
state[namespace].move.push(move);
if (state[namespace].start.point.length !== 2 && move.point.length === 2) { // in case the user failed to start with 2 fingers
state[namespace].start = $.extend({}, move);
}
state[namespace].rotation = touch.calc.getRotation(state[namespace].start, move);
state[namespace].scale = touch.calc.getScale(state[namespace].start, move);
if (Math.abs(1 - state[namespace].scale) > opt.scale || Math.abs(state[namespace].rotation) > opt.rotation) {
if (!started) {
$(event.target).trigger($.Event('transformstart', state[namespace]));
started = true;
}
$(event.target).trigger($.Event('transform', state[namespace]));
}
},
touchend: function (event, state, end) {
if (started) {
started = false;
if (end.point.length !== 2) { // in case the user failed to end with 2 fingers
state.end = $.extend({}, state[namespace].move[state[namespace].move.length - 1]);
}
state[namespace].rotation = touch.calc.getRotation(state[namespace].start, state.end);
state[namespace].scale = touch.calc.getScale(state[namespace].start, state.end);
$(event.target).trigger($.Event('transformend', state[namespace]));
}
}
});
}(jQuery, jQuery.toe, this));