5

It seems like long-press event is not part of the Polymer's specifications.

How would you implement that ?

I thought about using a behavior and using down and up event with some debounce tricks to manage such a new event but that means I have to make a custom element to use this behavior and can't for example use it directly on any elements I want like :

<div on-long-press="_cheese">...</div>

which is not convenient.

Would you have other solutions ?

vdegenne
  • 12,272
  • 14
  • 80
  • 106
  • You asked this question on the exact day that I was wondering the same :) – Andre Jun 23 '15 at 15:01
  • @Andre please join the chat room for talking about it (http://chat.stackoverflow.com/rooms/81301/polymer) – vdegenne Jun 23 '15 at 15:11
  • Have you tried the `on-hold` or `on-holdpulse` [events](https://www.polymer-project.org/0.5/docs/polymer/touch.html#basic-usage)? – Kutyel Jul 03 '15 at 06:35

2 Answers2

2

You don't have to make a custom element for this. This is what polymer behaviors are for. They provide a way for different polymer elements to share common behaviors.

As for the actual javascript for implementing the long-press you can get ideas from this question.

Community
  • 1
  • 1
es_code
  • 390
  • 1
  • 11
  • as I said in my question, I know how to implement such an event, and I know that I can use behaviors. I was just wondering if I could get the same effect using other aspect of the framework. like the on-tap attribute which is not one of the specifications of html. – vdegenne Jun 28 '15 at 08:51
  • I am not aware of anything that is documented, but you can try to follow the [Gestures source code](https://github.com/Polymer/polymer/blob/master/src/standard/gestures.html#L464) in registering your own event in Polymer.Gestures similar to the way `on-tap` is registered. – es_code Jun 28 '15 at 09:06
1

You can use a Vaadin gesture for this.

https://github.com/vaadin/vaadin-context-menu/blob/master/vaadin-long-touch.html

<paper-button on-vaadin-long-touch="function"></paper-button>

KVNA
  • 847
  • 1
  • 11
  • 24