Roshdy
Roshdy

Reputation: 1812

How to listen to variable event in Meteor Template event?

The question basically is how to convert this:

var evt = 'click' || 'touchstart'; // Based on some logic
$('.selector').on(evt, function(){});

into Meteor event handler

Template.MyTemp.events({
    ....??? : function(e, t){}
});

UPDATE

Based on the comments below, seems like chrome is the problem, as it sets the touch events passive = true.

So the new question would be:

How to set the passive property for event listeners in Blaze Template Events?

Upvotes: 2

Views: 170

Answers (1)

Michel Floyd
Michel Floyd

Reputation: 20227

You can specify multiple events in a single handler by using a / as a delimiter between the event types. docs

Template.MyTemp.events({
  'click/touchstart .selector'(e,t){
    e.preventDefault(); // prevents default click after touchstart
    // your handler
  }
});

In english:

for the template MyTemp handle click or touchstart events on the selector class.

This is also useful reading: touch and mouse

Upvotes: 1

Related Questions