Permalink
Browse files

pinch in/out events

  • Loading branch information...
yyx990803 committed Nov 30, 2012
1 parent 6a4e4e0 commit cbaa7fbbe760a76a85ba627c192c9bb6b99bfe67
Showing with 62 additions and 10 deletions.
  1. +16 −0 js/collection.js
  2. +16 −0 js/todo-collection.js
  3. +30 −10 js/touch.js
View
@@ -417,6 +417,22 @@ C.Collection = (function (raf) {
},
+ onPinchOutStart: function () {
+ console.log('pinchOut start');
+ },
+
+ onPinchOutMove: function (i, touch) {
+
+ },
+
+ onPinchOutCancel: function () {
+ console.log('pinchOut cancel');
+ },
+
+ onPinchOutEnd: function () {
+ console.log('pinchOut end');
+ },
+
createItemAtTop: function () {
// hide and reset dummy item
View
@@ -263,6 +263,22 @@ C.TodoCollection.prototype = {
},
+ onPinchInStart: function () {
+ console.log('pinchIn start');
+ },
+
+ onPinchInMove: function (i, touch) {
+
+ },
+
+ onPinchInEnd: function () {
+ console.log('pinchIn end');
+ },
+
+ onPinchInCancel: function () {
+ console.log('pinchIn cancelled');
+ },
+
positionForPullUp: function () {
this.el.addClass('drag');
View
@@ -290,46 +290,66 @@ C.touch = (function () {
pinchIn: {
check: function () {
+ // pinch in is only available for todoCollection
+ if (C.currentCollection.stateType === C.states.LIST_COLLECTION_VIEW) return;
+
if (pinchData.delta < -dragThreshold) {
currentAction = 'pinchIn';
+ C.currentCollection.onPinchInStart();
}
},
move: function (i) {
- console.log('pinch in!')
- var touch = touches[i];
- if (i === 0) { // first finger
- } else { // second one
+ // avoid extra triggering when one finger is lifted
+ if (touches.length === 1) return;
+
+ var touch = touches[i];
+ C.currentCollection.onPinchInMove(i, touch);
- }
},
end: function () {
+ if (touches.length === 1) return;
+
+ if (pinchData.cd <= pinchData.od * .5) {
+ C.currentCollection.onPinchInEnd();
+ } else {
+ C.currentCollection.onPinchInCancel();
+ }
}
},
pinchOut: {
+ at: null,
+
check: function () {
if (pinchData.delta > dragThreshold) {
currentAction = 'pinchOut';
+ C.currentCollection.onPinchOutStart();
}
},
move: function (i) {
- console.log('pinch out!')
- var touch = touches[i];
- if (i === 0) { // first finger
- } else { // second one
+ if (touches.length === 1) return;
- }
+ var touch = touches[i];
+ C.currentCollection.onPinchOutMove(i, touch);
},
end: function () {
+
+ if (touches.length === 1) return;
+
+ if (pinchData.delta > C.ITEM_HEIGHT) {
+ C.currentCollection.onPinchOutEnd();
+ } else {
+ C.currentCollection.onPinchOutCancel();
+ }
}

0 comments on commit cbaa7fb

Please sign in to comment.