Custom binding for long click


#1

I want to create a custom event called lngclick - that will fire only if the mouse is clicking on an element for a long period of time.

I would like to use it like this:
<button lngclick.delegate="myFunc()"></button>

(just like native DOM events)
aurelia custom attribute is expecting a value as bind, but I want to use delegate just like native events capturing.

someone here have already made something similar?


#2

I think you answered it yourself with “just like native DOM events”

All that command does is to add event listener specified. If you wish to use the same command, i think you will have to go for trigger and a binding behavior or implement a new command in SyntaxInterpreter


#3

sounds good.
is there a demo/article/tutorial/blog post on SyntaxInterpreter?


#4

Unfortunately no blog/article that I could fine. But i have made this https://github.com/bigopon/aurelia-style-binding-command-plugin that pokes SyntaxInterpreter. Maybe you can have a look for an example there. Let me know if you have any q :smile:


#5

ok great.
thanks for your help.


#6

I ended up going an easier path.
I liked what long-press-event did here
by adding a listener to the document, you can catch and emit long-click events that can be used like regular DOM events by aurelia.

I also created a plugin for other to benefit.


#7

That’s awesome. Would be even more if you could list it in aurelia-awesome in here https://github.com/aurelia-contrib/awesome-aurelia or contribute it to https://github.com/aurelia-contrib :smile:

And tbh, it feels like a more proper way to do it to me.