Skip to content

Commit

Permalink
pinch in/out events
Browse files Browse the repository at this point in the history
yyx990803 committed Nov 30, 2012
1 parent 6a4e4e0 commit cbaa7fb
Showing 3 changed files with 62 additions and 10 deletions.
16 changes: 16 additions & 0 deletions js/collection.js
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions js/todo-collection.js
Original file line number Diff line number Diff line change
@@ -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');
40 changes: 30 additions & 10 deletions js/touch.js
Original file line number Diff line number Diff line change
@@ -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.