-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set pointer capture on the right target #1255
Open
NavidZ
wants to merge
3
commits into
stevenwanderski:master
Choose a base branch
from
NavidZ:use-pointer-capture-correctly
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
responsive: true, | ||
slideZIndex: 50, | ||
wrapperClass: 'bx-wrapper', | ||
sliderSlopSize: 5, | ||
|
||
// TOUCH | ||
touchEnabled: true, | ||
|
@@ -1117,19 +1118,22 @@ | |
slider.touch.originalPos = el.position(); | ||
var orig = e.originalEvent, | ||
touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig]; | ||
var chromePointerEvents = typeof PointerEvent === 'function'; | ||
if (chromePointerEvents) { | ||
if (orig.pointerId === undefined) { | ||
return; | ||
} | ||
} | ||
var PointerEventsSupported = typeof PointerEvent === 'function'; | ||
if (PointerEventsSupported) { | ||
if (orig.pointerId === undefined) { | ||
// Skip touch events as the rest of the code runs with pointer events already. | ||
return; | ||
} | ||
} | ||
// record the starting touch x, y coordinates | ||
slider.touch.start.x = touchPoints[0].pageX; | ||
slider.touch.start.y = touchPoints[0].pageY; | ||
|
||
if (slider.viewport.get(0).setPointerCapture) { | ||
// This captures the event stream to the target to make sure even if the pointer leaves | ||
// the slider bounday in the very next move it still keeps the events. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo. Meant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
if (e.target.setPointerCapture) { | ||
slider.pointerId = orig.pointerId; | ||
slider.viewport.get(0).setPointerCapture(slider.pointerId); | ||
e.target.setPointerCapture(slider.pointerId); | ||
} | ||
// store original event data for click fixation | ||
slider.originalClickTarget = orig.originalTarget || orig.target; | ||
|
@@ -1182,8 +1186,23 @@ | |
yMovement = Math.abs(touchPoints[0].pageY - slider.touch.start.y), | ||
value = 0, | ||
change = 0; | ||
// this is swipe | ||
slider.hasMove = true; | ||
|
||
if (xMovement > slider.settings.sliderSlopSize || yMovement > slider.settings.sliderSlopSize) { | ||
// From now on all moves will be considered swipe. | ||
slider.hasMove = true; | ||
|
||
// Capture the pointerevent stream to the slider instead of the element that the pointerdown | ||
// started on. This ensures the start element such as link doesn't get activated when user | ||
// is done with swiping the slider and releases the pointer. | ||
if (slider.viewport.get(0).setPointerCapture && typeof orig.pointerId !== 'undefined') { | ||
slider.viewport.get(0).setPointerCapture(slider.pointerId); | ||
} | ||
} | ||
|
||
// Only move the slider if we determined that we are in swipe mode. This ensures | ||
// users can still click/tap on links even if the pointer moves within sliderSlopSize. | ||
if (!slider.hasMove) | ||
return; | ||
|
||
// x axis swipe | ||
if ((xMovement * 3) > yMovement && slider.settings.preventDefaultSwipeX) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see, all current configuration options have some description in respective README section.
Could you add a short note/confirm what the "slop" value controls (move threshold to discern between slide/click) and what dimensions (pixels) it's measured in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. I missed it. I didn't know. I added one, Does that sound good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Hoping that any of project's maintainers can now race ahead with PR merge and new release 🤞