Skip to content

Commit

Permalink
Merge pull request #56 from Nona-Creative/feat/additional-funtionality
Browse files Browse the repository at this point in the history
Feature: additional funtionality
  • Loading branch information
kornelski committed Sep 21, 2015
2 parents 94f48f9 + fa0d899 commit 6fec52c
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions slip.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ window['Slip'] = (function(){

if (!this || this === window) return new Slip(container, options);

this.options = options;
this.options = options = options || {};
this.options.keepSwipingPercent = options.keepSwipingPercent || 0;
this.options.minimumSwipeVelocity = options.minimumSwipeVelocity || 1;
this.options.minimumSwipeTime = options.minimumSwipeTime || 110;

// Functions used for as event handlers need usable `this` and must not change to be removable
this.cancel = this.setState.bind(this, this.states.idle);
Expand Down Expand Up @@ -241,7 +244,7 @@ window['Slip'] = (function(){
var move = this.getAbsoluteMovement();

if (move.x > 20 && move.y < Math.max(100, this.target.height)) {
if (this.dispatch(this.target.originalTarget, 'beforeswipe')) {
if (this.dispatch(this.target.originalTarget, 'beforeswipe', {directionX: move.directionX, directionY: move.directionY})) {
this.setState(this.states.swipe);
return false;
} else {
Expand Down Expand Up @@ -316,22 +319,16 @@ window['Slip'] = (function(){
},

onEnd: function() {
var dx = this.latestPosition.x - this.previousPosition.x;
var dy = this.latestPosition.y - this.previousPosition.y;
var velocity = Math.sqrt(dx*dx + dy*dy) / (this.latestPosition.time - this.previousPosition.time + 1);

var move = this.getAbsoluteMovement();
var swiped = velocity > 0.6 && move.time > 110;
var velocity = move.x / move.time;

// How far out has the item been swiped?
var swipedPercent = Math.abs((this.startPosition.x - this.previousPosition.x) / this.container.clientWidth) * 100;

var direction;
if (dx > 0) {
direction = "right";
} else {
direction = "left";
}
var swiped = (velocity > this.options.minimumSwipeVelocity && move.time > this.options.minimumSwipeTime) || (this.options.keepSwipingPercent && swipedPercent > this.options.keepSwipingPercent);

if (swiped) {
if (this.dispatch(this.target.node, 'swipe', {direction: direction, originalIndex: originalIndex})) {
if (this.dispatch(this.target.node, 'swipe', {direction: move.directionX, originalIndex: originalIndex})) {
swipeSuccess = true; // can't animate here, leaveState overrides anim
}
}
Expand Down Expand Up @@ -709,6 +706,8 @@ window['Slip'] = (function(){
x: Math.abs(this.latestPosition.x - this.startPosition.x),
y: Math.abs(this.latestPosition.y - this.startPosition.y),
time:this.latestPosition.time - this.startPosition.time,
directionX:this.latestPosition.x - this.startPosition.x < 0 ? 'left' : 'right',
directionY:this.latestPosition.y - this.startPosition.y < 0 ? 'up' : 'down',
};
},

Expand Down

0 comments on commit 6fec52c

Please sign in to comment.