Reputation: 2234
So I have a main view that has a collection of objects inside of it. The objects are going to be sliding left and right in a carousel.
I have an event that binds on mousedown inside of the main view to track how far they roll the mouse during that time. However, if they roll off of main view element while still holding down the mouse, I still want to be tracking distance and also the moment when the mouseup event is fired.
What would be a good way to integrate a UI logic like this that starts with a local backbone view but has events that trigger off of the element? I feel there are some traps, especially in terms of future legibility if I were to spread out the functionality over global and local views.
Upvotes: 1
Views: 134
Reputation: 38772
I think you have to move the mouse event catcher out of the CarouselView. Actually is not so weird.
You can define an ElasticView which el
is body
. It contains the CarouselView and its main job is to listen the mousedown in the CarouselView.$el
and also can listen in the mouseup in the document.body
.
It can also comunicate directly with the CarouselView if you add it as a param in the ElasticView constructor. Or the communication can be done by an EventAggregator or a common Model or something.
Upvotes: 2