4

I am trying to translate this js code into ruby code

document.ontouchstart ? 'touchstart' : 'click';

I am using opal-browser to get browser functionality. My current attempt is this:

touch = Browser::Event::Touch.new puts touch.start?

However this returns the error: Uncaught TypeError: Cannot read property 'type' of undefined

When I checked the error trace the error seems to be coming from a missing name property in the Touch class.

Hoping Opal community can help me out here

1 Answers1

1

If you want to check if touch is supported you need to call Event::Touch.supported?.

For the error, it's happening because .new expects the event object as parameter, if you want to create a new event object you need to call .construct.

In retrospect it would have probably been better to have .construct be .new, and .new be .wrap or something on that line.

meh.
  • 96
  • 1
  • 4