Re: Phasing out mouse compatibility events on tap?

On 16/01/2015 18:08, Matt Gaunt wrote:
> The end goal of my comment is: what does a sane API look like - touch
> events result from touch, mouse events result from mouse, nothing more,
> nothing less.
>
> I agree doing compat events is great for older sites and we shouldn't
> try and guess if the site is "old" or not - it's too late in the game
> for that to be using anything like the viewport meta tag.

DOCTYPE switching, perhaps? I jest, of course...

> So how about we just move to having an api to disable compat mouse
> events? I would love this and by default, no behavior change.

My preference would definitely be a new method, a la 
e.preventMouseCompatibilityEvents() (or something a bit more terse, but 
I'd rather be explicit enough to avoid confusion).

Only question is: as "click" is currently handled as a compatibility 
event as well in the TE model, would the above also kill "click"? I 
guess it wouldn't be a deal-breaker if it did, mind, and would keep 
things straightforward enough (i.e. wouldn't change the definition of 
"compatibility event" - after we specify that definition in the TE 
Errata/v.2). In fact, if it did, that would also make the naive

var clickEvent =  ('ontouchstart' in window ? 'touchend' : 'click');
blah.addEventListener(clickEvent, function() { ... }, false);

pattern redundant, and instead allow for BOTH touchend and click to be 
added as event listeners, since the click could be explicitly suppressed.

foo.addEventListener('touchstart', function(e) {
     e.MouseCompatibilityEvents();
     ...
}, false);

/* doubled-up event listeners */

foo.addEventListener('touchend', someFunction, false);
foo.addEventListener('click', someFunction, false);

This is conceptually very similar to some of the current advice (for iOS 
and old Android WebKit at least, where no other method to remove the 
300ms delay is available - see 
http://patrickhlauke.github.io/touch/tests/results/#suppressing-300ms-delay)

foo.addEventListener('touchstart', function(e) {
     e.preventDefault();
}, false);

/* doubled-up event listeners */

foo.addEventListener('touchend', someFunction, false);
foo.addEventListener('click', someFunction, false);

but without the side effect that preventDefault() has of also killing 
scrolling, zooming, etc.

Anyway, sorry, rambling away...but hopefully makes some kind of sense.

P
-- 
Patrick H. Lauke

www.splintered.co.uk | https://github.com/patrickhlauke
http://flickr.com/photos/redux/ | http://redux.deviantart.com
twitter: @patrick_h_lauke | skype: patrick_h_lauke

Received on Friday, 16 January 2015 21:04:35 UTC