Add config option to automatically call preventDefault() on the onclick event #13

Merged
merged 1 commit into from Dec 1, 2012

2 participants

@tomds

It would save a lot of code if when binding a tap event on an element, you could add a config variable to automatically call preventDefault() whenever this element receives an click event.

I would say it is a pretty common use case of this library to replace the click event with the tap event so it will work equally well on touch and non-touch devices. It is also often the case that you are binding this event to e.g. an <a> element, which tends to require a preventDefault(). Obviously it's not always the case, hence why I'm suggesting it as an option. But I think this is a good alternative to having to bind an extra event handler on every element just to call preventDefault().

Usage:

var a = $('body a').Touchable({preventClick: true});
a.on('tap', function (e) {
    alert('tap');
});

This stops us from having to repeatedly write:

a.on('click', function (e) {
    e.preventDefault();
});
@dotmaster dotmaster merged commit c686964 into dotmaster:master Dec 1, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment