Mapping Touchscreen Events to Mouse Events
-
Yes, I will read up on them right now. I just finished writing all the comments in my event mapping script, and I'm glad to be done with all that. No more dev work for me today. Although I don't think it's possible to be so bored that you'd go through and read it all, I'll post a link to the script anyway. https://chromosphere.com/chromosphere/scripts/js/ui/events/ui_touch_functions_d_f.js[^]
You're right, I'd have to be really bored. :laugh:
Jeremy Falcon
-
Jeremy Falcon wrote:
Maybe some code will help. A fiddle... Using events as a proxy.
That's interesting. I've never used the bind method, let alone inside an addEventListener method. If I were to use that approach, then how would I set the event parameters if that bind method is located inside a click event listener? Let's say that I needed to run a passive event, such as mousemove within a click event listener. Click events are non-passive, yet mousemove events are passive. Passive events can't be canceled (without some effort, anyway), yet click events are cancelable. What if the click event is set to bubble, and the mousemove event needs to propagate as capture? I don't know how that could be done. Without being able to set those custom parameters for events, and event listeners, nothing would work. Perhaps if I added the parameters into the method as arguments, that might be possible. The solution I have now works great. It's as simple as it could possibly be. It's efficient, and every element in the DOM is automatically enabled for use with touch interaction. To make that possible, I only had to write a single subroutine. I'd say it only took a couple of minutes to write up and I'm all done. It seems to be an ideal solution in every way. If there's a better way to go about it, then I'm open to ideas.
Steve Raw wrote:
If I were to use that approach, then how would I set the event parameters if that bind method is located inside a click event listener? Let's say that I needed to run a passive event, such as mousemove within a click event listener
It's the same way. I should say though, you seem to be stuck on this idea of calling one event from another. That's not the way to go, regardless if it's passive or active. Something like bind works on any function though, but that's not the important bit. I don't recommend doing this at all, but to answer the question (this time without bind just for illustration): [Fiddle](https://jsfiddle.net/jfalcon/f5c0xz9s/38/). The key takeaway should be using the proxy approach.
Steve Raw wrote:
What if the click event is set to bubble, and the mousemove event needs to propagate as capture?
They are two independent events. Bubbling or canceling one won't affect the other. You may need to take a step back at your code and the way you've done things, take a breather, and look at the big picture man. This is like crossing streams in Ghostbusters. Something is gonna blow up. :laugh:
Steve Raw wrote:
Without being able to set those custom parameters for events, and event listeners, nothing would work.
If it's a proxy, you can use any params you want for the real handler. The first fiddle showed that, with only passing the id as a single param.
Steve Raw wrote:
It's efficient, and every element in the DOM is automatically enabled for use with touch interaction.
You mentioned 1,000 event listeners, trust me... there's room for improvement man. I promise. :laugh:
Steve Raw wrote:
and every element in the DOM is automatically enabled for use with touch interaction
That's just it, if every element has a listener attached to it, then not only will your site be slow but you've made it extremely difficult for your users to user the site... they can click the wrong thing. Just because you can do something, doesn't mean you should. I promise.
Steve Raw wrote:
To make that possible, I only had to write a single subroutine.
If your 1,000 events are calling the same routine, that's using a proxy.
Jeremy Falcon<
-
Steve Raw wrote:
If I were to use that approach, then how would I set the event parameters if that bind method is located inside a click event listener? Let's say that I needed to run a passive event, such as mousemove within a click event listener
It's the same way. I should say though, you seem to be stuck on this idea of calling one event from another. That's not the way to go, regardless if it's passive or active. Something like bind works on any function though, but that's not the important bit. I don't recommend doing this at all, but to answer the question (this time without bind just for illustration): [Fiddle](https://jsfiddle.net/jfalcon/f5c0xz9s/38/). The key takeaway should be using the proxy approach.
Steve Raw wrote:
What if the click event is set to bubble, and the mousemove event needs to propagate as capture?
They are two independent events. Bubbling or canceling one won't affect the other. You may need to take a step back at your code and the way you've done things, take a breather, and look at the big picture man. This is like crossing streams in Ghostbusters. Something is gonna blow up. :laugh:
Steve Raw wrote:
Without being able to set those custom parameters for events, and event listeners, nothing would work.
If it's a proxy, you can use any params you want for the real handler. The first fiddle showed that, with only passing the id as a single param.
Steve Raw wrote:
It's efficient, and every element in the DOM is automatically enabled for use with touch interaction.
You mentioned 1,000 event listeners, trust me... there's room for improvement man. I promise. :laugh:
Steve Raw wrote:
and every element in the DOM is automatically enabled for use with touch interaction
That's just it, if every element has a listener attached to it, then not only will your site be slow but you've made it extremely difficult for your users to user the site... they can click the wrong thing. Just because you can do something, doesn't mean you should. I promise.
Steve Raw wrote:
To make that possible, I only had to write a single subroutine.
If your 1,000 events are calling the same routine, that's using a proxy.
Jeremy Falcon<
-
I haven't had the chance to read up on bind, call, and apply yet. I'll see if I can make use of them as you suggest. I've got a dentist's appointment. I've got 8 minutes to get there. I'll write more later. :thumbsup:
Good luck, buddy.
Jeremy Falcon