stoffeastrom / touche Goto Github PK
View Code? Open in Web Editor NEWGestures library for desktop and touch devices
License: MIT License
Gestures library for desktop and touch devices
License: MIT License
We need to handle MSPointer events.
If window.navigator.msPointerEnabled bind the MSPointerDown/MSPointerMove/MSPointerUp.
Set -ms-touch-action: none; for the binding element so the events gets directed to javascript code
event.pointerType -> mouse, pen, touch
This means that taps on inline styled elements will be ignored and scrollbar detection on elements with borders can fail.
We need to introduce a getValidTarget which would traverse up the DOM until we have a "valid" element. That element should be set as relatedTarget. If we do T.utils.getRect for that valid element the gestures could use that instead of doing it themselves.
Maybe we also could introduce "selector". So it would traverse up to matched selector. If not matched it will not trigger
We need to have a buildstep so we can keep an up-to-date touche.min.js
for easy distribution.
If you on desktop tab to a <button>
, and press the spacekey, I would assume that a tap event would be triggered, but it isn't as of now.
Browsers apply the :active
pseudo class so it seems logical.
This is fixed in chrome canary (https://code.google.com/p/chromium/issues/detail?id=14204)
IE 10 still has the issue (https://connect.microsoft.com/IE/feedback/details/783058/scrollbar-trigger-mousedown-but-not-mouseup)
Don't know if we should do anything about this in Touché but we are aware of the issue.
One hack is to check if the event.target.scrollHeight > event.target.getBoundingClientRect().height for vertical scroll and vice versa for horizontal. If either is true the mousedown was on the scrollbar.
If options.which is an array make sure to check to whole array. Backward compability should be possible. Check if its an array else work as before
Fallback on getBoundingClientRect
The isOtherFlowStarted function only checks if the flow is started, but the flow should not be considered started if it's already ended.
So the code should be like:
flow.started && !flow.ended
options, etz
How should we handle double tap and cancellation of tap?
The double tap definition should handle this. Add the possibility to delay the tap from the double tap and either trigger double tap or the tap gesture
IE10 vs IE11 has different detection on pointer events. IE11 is following the w3c spec so change the detection to check for window.MSPointerEvent or window.PointerEvent. Add a util function to detect if it's a mouse or not.
For doubletap we do T(elem).on(this) and T(elem).off('tap'). If we only want to do off on a certain gesture we need to make sure to remove the correct instance and not all for the type 'tap'.
Given you have attached Touché with swipe to an element and you click on the scrollbar belonging to that element, swipe gets started by never ended (compared to clicking on the actual element, which also ends the swipe).
Test case:
<!DOCTYPE html>
<html>
<head>
<style>
.outer {
height: 200px;
width: 200px;
overflow: auto;
border: 1px solid gray;
}
.inner {
height: 600px;
width: 600px;
}
</style>
</head>
<body>
<div class="outer">
<div class="inner">inner</div>
</div>
<script src="touche.min.js"></script>
<script>
var element = document.getElementsByClassName("outer")[0];
Touche( element ).swipe( {
options: {
preventDefault: false,
radiusThreshold: 1
},
start: function ( nativeEvent, data ) {
console.log("touche start");
},
update: function ( nativeEvent, data ) {
console.log("touche update");
},
end: function ( nativeEvent, data ) {
console.log("touche end");
}
} );
</script>
</body>
</html>
Since firefox can't handle to do a getScreenCTM on the SVG element we need to do it on the target element.
Currently, there's a lot of overhead when defining a gesture. There's object merging for options, default empty callbacks and so on. I'd like to see a cleaner, more easily understood API for defining gestures.
Below is a proposed way of a cleaner API.
Touche.add('gesturename', {
options: {},
init: function() {},
start: function() {},
update: function() {},
end: function() {},
cancel: function() {}
});
init
is the only required key in the gesture definition. All others (options
, start
, update
, end
, cancel
) are optional.
options
are defined default values, e.g. thresholds and so on that are specific to the gestureinit
handles any logic that should be run when the gesture is bound to an elementstart
is triggered when the gesture manager of that element deems it appropriate to start the gestureupdate
is triggered whenever the gesture has been started and there's movement (either by finger, timer, mouse etc.)end
is triggered if the gesture successfully ended, this is what most people would want to usecancel
is triggered if the element's gesture manager has seen another gesture that has been fulfilled or if the user somehow cancelled the interaction (e.g. touchcancel
or similar)Let's open up a discussion around this so the API is simple to use.
Double tap options is not used on the underlying tap gesture. The tap should get the doubletap options! I.e preventDefault:false should work.
http://lists.w3.org/Archives/Public/public-webevents/2012OctDec/0023.html
This is an issue for the touch specification. It seems that a mouseup is fired though.
Instead of using event.stopPropagation() it would be nice to expose a function that prevent gestures with optional [exceptThisGestureHandler] parameter.
Looked into this.
The way to solve this would be to have an static function
T.preventGestures = function(excludeHandler) {
T.cache.data.filter(function(obj) {
return (excludeHandler ? obj.context !== excludeHandler : true);
}).forEach(function(obj) {
obj.context.prevented = true;
});
};
and a check
this.handleEvent = function(event) {
var events = T.utils.getEvents(),
flowType = T.utils.getFlowType(event.type);
if(events.start.some(function(val) {
return event.type === val;
})) {
if(this.isOtherFlowStarted(flowType)) {
return;
}
if(this.prevented) {
this.prevented = false;
return;
}
//... left out
This way it would be possible to prevent gestures if needed.
Instead of doing:
Touche.tap(elem, opts).swipe(elem, opts);
the user can do:
Touche.wrap(elem).tap(opts).swipe(opts);
// or:
Touche(elem).tap(opts).swipe(opts);
All events triggered by touché gestures should have a relatedTarget
property so we can know which element it originated from, or is related to.
Make sure to have the js files in same order when concatenating / demo page
We should listen to dragstart
, drag
, dragend
events in that case to make sure the tap is triggered/cancelled.
I.e.
tapstart -> dragstart -> tapcancel since it has become another gesture (native drag)
All gestures should have the data parameter set. If the gesture has specific data just add it to the data object
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.