Skip to content

Commit

Permalink
allow native touch scrolling
Browse files Browse the repository at this point in the history
+ Only allow dragging or scrolling, not both by default
+ transparent tap-highlight-color
+ upgrade unidragger to ~1.1.2
+ changelog

Fixes #41, #67, #97
  • Loading branch information
desandro committed Apr 27, 2015
1 parent 7d02766 commit 862b9b7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"get-style-property": "~1.0.4",
"doc-ready": "~1.0.4",
"classie": "~1.0.1",
"unidragger": "~1.1.0",
"unidragger": "~1.1.2",
"fizzy-ui-utils": "~1.0.0",
"tap-listener": "~1.1.0"
},
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

### v1.0.1

+ Allowed native scrolling for touch devices. Fixed [#67](https://github.com/metafizzy/flickity/issues/67), [#97](https://github.com/metafizzy/flickity/issues/97), [#41](https://github.com/metafizzy/flickity/issues/41)
+ Allowed clicks on all inputs and textareas, for [#105](https://github.com/metafizzy/flickity/issues/105)
+ Fixed IE10 `body.blur()` bug. Fixed #
+ Upgraded [Unidragger](https://github.com/metafizzy/unidragger) to `v1.1.3` [tap-listener](https://github.com/metafizzy/tap-listener) to `v1.1.0`

## v1.0.0

+ Add commercial licensing
Expand Down
2 changes: 2 additions & 0 deletions css/flickity.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ http://flickity.metafizzy.co
/* draggable */

.flickity-enabled.is-draggable {
-webkit-tap-highlight-color: transparent;
tap-highlight-color: transparent;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
Expand Down
32 changes: 18 additions & 14 deletions js/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ proto.unbindDrag = function() {
delete this.isDragBound;
};

proto.hasDragStarted = function( moveVector ) {
return Math.abs( moveVector.x ) > 3;
};

proto._uiChangeDrag = function() {
delete this.isFreeScrolling;
};
Expand Down Expand Up @@ -145,13 +141,21 @@ proto.pointerDownFocus = function( event ) {
}
};

// ----- move ----- //

proto.pointerMove = function( event, pointer ) {
var moveVector = this._dragPointerMove( event, pointer );
this.touchVerticalScrollMove( event, pointer, moveVector );
this._dragMove( event, pointer, moveVector );
this.dispatchEvent( 'pointerMove', event, [ pointer, moveVector ] );
};

proto.hasDragStarted = function( moveVector ) {
return !this.isTouchScrolling && Math.abs( moveVector.x ) > 3;
};

// ----- up ----- //

proto.pointerUp = function( event, pointer ) {
delete this.isTouchScrolling;
classie.remove( this.viewport, 'is-pointer-down' );
Expand All @@ -175,25 +179,23 @@ function getPointerWindowY( pointer ) {
}

proto.touchVerticalScrollMove = function( event, pointer, moveVector ) {
if ( !this.options.touchVerticalScroll || !touchScrollEvents[ event.type ] ) {
// do not scroll if already dragging, if disabled
var touchVerticalScroll = this.options.touchVerticalScroll;
// if touchVerticalScroll is 'withDrag', allow scrolling and dragging
var canNotScroll = touchVerticalScroll == 'withDrag' ? !touchVerticalScroll :
this.isDragging || !touchVerticalScroll;
if ( canNotScroll || !touchScrollEvents[ event.type ] ) {
return;
}
// don't start vertical scrolling until pointer has moved 16 pixels in a direction
if ( !this.isTouchScrolling && Math.abs( moveVector.y ) > 16 ) {
// don't start vertical scrolling until pointer has moved 10 pixels in a direction
if ( !this.isTouchScrolling && Math.abs( moveVector.y ) > 10 ) {
// start touch vertical scrolling
// scroll & pointerY when started
this.startScrollY = window.pageYOffset;
this.pointerWindowStartY = getPointerWindowY( pointer );
// start scroll animation
this.isTouchScrolling = true;
}
if ( !this.isTouchScrolling ) {
return;
}
// scroll window
var scrollDelta = this.pointerWindowStartY - getPointerWindowY( pointer );
var scrollY = this.startScrollY + scrollDelta;
window.scroll( window.pageXOffset, scrollY );
};

// -------------------------- dragging -------------------------- //
Expand All @@ -205,6 +207,8 @@ proto.dragStart = function( event, pointer ) {
};

proto.dragMove = function( event, pointer, moveVector ) {
preventDefaultEvent( event );

this.previousDragX = this.x;

var movedX = moveVector.x;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"get-size": "~1.2.2",
"desandro-get-style-property": "~1.0.4",
"wolfy87-eventemitter": "~4.2.11",
"unidragger": "~1.1.0",
"unidragger": "~1.1.2",
"fizzy-ui-utils": "~1.0.0",
"tap-listener": "~1.1.0"
},
Expand Down

0 comments on commit 862b9b7

Please sign in to comment.