ftlabs / fastclick

Polyfill to remove click delays on browsers with touch UIs
MIT License
18.66k stars 3.23k forks source link

Handling of elements which should be excluded #73

Closed codejet closed 11 years ago

codejet commented 11 years ago

I don't know if this was discussed before, but instead of having to add the "needsclick" class in the markup, wouldn't it be a good idea to (also) allow developers to pass in classes of elements which should be excluded into the constructor? Or have you tested this approach and discarded it for some reason? It tried it the other day, and it seemed to work quite well.

dryabov commented 11 years ago

I would prefer inclusive list, e.g. "a, a > *, button, input", but I'm not sure it can be implemented easily (unlikely querySelectorAll is good solution). In my opinion, it's better to override FastClick.prototype.needsClick with your own code.

mattcg commented 11 years ago

@dryabov Assuming support for matchesSelector, it should be easy to implement.

@codejet Are you happy to override FastClick.prototype.needsClick in your own application code?

dryabov commented 11 years ago

@mattcg Thank you, I forgot matchesSelector method. Last time I read about it, there were prefixed versions only and "recommended" code was like

var de = document.documentElement,
    matches = de.matchesSelector
           || de.mozMatchesSelector
           || de.webkitMatchesSelector
           || de.oMatchesSelector
           || de.msMatchesSelector;
matches.call(element, selector);

but anyway it's faster any other solution.

Do you know how well it's supported by mobile devices?

codejet commented 11 years ago

Thanks a lot for your replies, guys.

As mentioned, my first attempt was to change the code so that the constructor accepts an array of classes, and it seems to work quite well (though there might be a some performance impact when working with several classes). If I just overwrite FastClick.prototype.needsClick, I would have to hardcode the classes of the elements which should be excluded into the method, or store them in a static property or something, but I think that's still a feasible option.

I was primarily interested in finding out if other users might have asked about the possibility to use existing classes of elements to be excluded instead of adding another class to their markup, and/or if you guys at ftlabs had maybe dropped this approach for some reason.