0

The Emblem syntax guide shows you can attach actions to an element like this

a click="toggleHeader" my plain text

which compiles to this in handlebars:

<a {{action toggleHeader on="click"}}>my plain text</a>

For multiple event listeners on the same element, can you do something like this

a click="toggleHeader" touchEnd="toggleHeader"

or

<a {{action toggleHeader on="click touchEnd"}}>x</a>

I've tried both, but neither work.


Is it even necessary to attach multiple event listeners when trying to make clicking in the browser behave the same way as touching in mobile or touch screens?

If Ember already has convenience methods that account for web and mobile events, can you point me to the reference. This link does not qualify because it just lists names, and doesn't tell you if any are composite event listeners.

Hopefully, as the line between laptops and touch screens become blurred, we'll eventually have vanilla jQuery that accounts for both types with one method (unless the combined packages exists already).

GJK
  • 37,023
  • 8
  • 55
  • 74
ahnbizcad
  • 10,491
  • 9
  • 59
  • 85

1 Answers1

1

As this JSBin will show you, you can't have multiple events trigger the same action using the inline action helper. There's been discussions about adding this type of functionality, but I believe they've all ended with the Ember team suggesting you use a view instead of the inline action helper.

So I'm guessing the reason that Emblem won't output what you want is because it's not valid Ember code. I suggest using a view or a component to achieve what you want.

GJK
  • 37,023
  • 8
  • 55
  • 74
  • I'm not sure I understand how components or views solves this problem. The component templates still utilize the action helper. I'd really appreciate an example or short explanation. I've read the guides but this aspect of having multiple listener on the same element is not clear to me. – ahnbizcad Apr 14 '15 at 04:05
  • 1
    You don't need to use the action helper, you can [define event handlers on in the view](http://guides.emberjs.com/v1.11.0/views/handling-events/) that will be called by Ember automatically. – GJK Apr 14 '15 at 04:09