0

Now I'm developing mobile app based on html5 and phoneGap.The JS famework is ember.The specification of the app requires to respond to long-press gesture. But the long-press event isn't ember build-in event.

What should I do to recognize the gesture and connect to event handling(controller or route)?

  • Do you have some sort of JavaScript library that handles long presses? If so, you could create an Ember view and use that to handle a long press DOM event. – claptimes Dec 24 '13 at 13:44
  • Here's an SO [answer](http://stackoverflow.com/questions/2625210/long-press-in-javascript) that has a a script. – claptimes Dec 24 '13 at 13:45
  • Ember can't handle long-press. I use touchStart and touchEnd events to handle the problem. – Li Bingqing Dec 25 '13 at 05:43

1 Answers1

0

I was able to accomplish this with mouseUp and mouseDown but you can use the touchStart and touchEnd events I'm sure. See here

I setup a jsbin, but here's the relevant code:

var myfunction = function() { 
  alert('held');
}

App.ApplicationView = Ember.View.extend({
  mouseDown: function(e){
   var runLater = Ember.run.later(this, myfunction, 1000);
    this.set('pressed', runLater);
  },

  mouseUp: function (e) { 
    Ember.run.cancel(this.get('pressed'));
  }
})
claptimes
  • 1,615
  • 15
  • 20
  • What should I do If I want to access the attribute of view in "myfunction"? For example, I want to send an event to the relative controller. – Li Bingqing Dec 25 '13 at 06:02