It would be great if all elements that trigger an asynchronous request automatically have a 'needsclick' class added to them. It sounds achievable and would be really useful feature for themers.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | fastclick-ajax-needsclick-2217069-5.patch | 1.03 KB | joelstein |
Comments
Comment #1
pere orgaWhy this would be useful?
Comment #2
spazfoxOne reason it might be useful: FastClick prevents the Closed Question module (which relies on AJAX for answer submission and feedback display) from functioning properly on touch devices, as I describe at #2217621: Allow disabling init code per content type. It is quite possible that it interferes with other contrib modules that use AJAX, and it is quite possible that LewisNyman's idea would resolve such problems.
Comment #3
lewisnymanhm, I was under the impression that any element that defines it's own event handlers required the needsclick class but that might not be the case. It's only elements that define their own touchstart handlers?
Comment #4
ruplFastClick works by firing
clickat the same time astouchend, so it's possible that conflicts withtouchendmight arise.https://github.com/ftlabs/fastclick#use-case-1-non-synthetic-click-required
Are there steps to reproduce so that we could inspect what's happening and figure out how widespread this problem is within core or Views or whatever?
Comment #5
joelstein commentedThis is indeed an issue with the default handling attached to ajax submit, button, and image_button elements, which prevents these elements from responding to a 'click' event on touch devices, if FastClick is installed.
Drupal's native ajax system uses the 'mousedown' event on ajax submit, button, and image_button elements instead of the 'click' event (see here), and then prevents the 'click' event from firing (see here). This all happens in ajax_pre_render_element().
You can, of course, bypass this by explicitly setting the 'event' property to 'click', or setting the 'prevent' property to something other than 'click'. But most modules don't do this. We're experiencing this with Webform Stripe.
This issue describes why 'mousedown' was added in the first place:
#216059: AHAH triggered by text input enter key press, breaks e.g. autocomplete
This issue describes what problems were introduced after above was committed:
#634616: Various problems due to AJAX binding to mousedown instead of click
A very simple workaround in the FastClick module would be to add process callbacks to these three elements, and in that callback check if the 'click' event is being prevented. If so, add the 'needsclick' class to the element. Simple!
Comment #7
pere orgaApplied to dev, thanks!
Comment #8
joelstein commentedThanks! I supposed we can mark this as fixed then. :)