Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'click' event handler breaks iPhone text selection #479

Closed
irace opened this issue Apr 12, 2012 · 8 comments
Closed

'click' event handler breaks iPhone text selection #479

irace opened this issue Apr 12, 2012 · 8 comments

Comments

@irace
Copy link

irace commented Apr 12, 2012

Using the 'click' event handler in the following fashion seems to break text selection on the iPhone.

$('#container').on('click', '.some-class', function() {
    // Anything
});

This prevents the user from selecting text anywhere in the web view, not just the target element matched by the selector.

The reason I am listening for 'click' as opposed to 'tap' events is that HTML5 audio players can apparently only be played/paused from the former.

Please let me know if I'm simply doing something stupid :)

@irace
Copy link
Author

irace commented Apr 12, 2012

I should note that 'mouseup' also appears to have the same behavior (prevents the user from selecting text).

@mislav
Copy link
Collaborator

mislav commented Apr 13, 2012

Interesting (if this is true). You should know that observing a "click" event on a natively non-clickable element (in your case, "#container") on iOS changes the nature of that element slightly. You should definitely try to use tap events when possible. As for HTML5 audio player restrictions, I don't know. You should try it yourself.

@irace
Copy link
Author

irace commented Apr 13, 2012

I have tried it myself. Observing 'click' is the only way I am able to use JavaScript to pause/play the audio element. I would love to somehow be able to observe 'tap' and still have this ability, as to not screw with the native text selection capabilities.

@mislav
Copy link
Collaborator

mislav commented Apr 13, 2012

Observing 'click' is the only way I am able to use JavaScript to pause/play the audio element.

That is bizarre. Are you sure it's not something in your code? Have you tried using native touch events (not ones provided by Zepto) such as "touchend"?

@irace
Copy link
Author

irace commented Apr 13, 2012

Using 'touchend' does fix the issue: it satisfies Mobile Safari's user-initiation policy (http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4) but does not interfere with standard iOS text selection.

Thanks for the suggestion!

@mislav
Copy link
Collaborator

mislav commented Apr 13, 2012

So, is the conclusion that one can't use Zepto-provided "tap" event to interact with Audio elements?

@irace
Copy link
Author

irace commented Apr 13, 2012

Yes, I believe so.

From Apple's documentation:

"This plays the movie: <input type="button" value="Play" onClick="document.myMovie.play()">

This does nothing on iOS: <body onLoad="document.myMovie.play()">"

Apparently Zepto's 'tap' event does not qualify as user initiated in the same way that 'click' events do.

@madrobby
Copy link
Owner

madrobby commented Sep 4, 2013

FWIW, you can use "touchend" on iOS for this. Non-native or events generated in JavaScript can't do certain things like start playing audio or focusing a text field.

Closing stale ticket in favor of #805.

@madrobby madrobby closed this as completed Sep 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants