Is it possible to bind events on body element inside a view?
For example this doesn't work
Backbone.View.extend({
el : "#some element here",
events : {
"mouseup body" : "onMouseUp"
}
});
Thanks in advance
Is it possible to bind events on body element inside a view?
For example this doesn't work
Backbone.View.extend({
el : "#some element here",
events : {
"mouseup body" : "onMouseUp"
}
});
Thanks in advance
I think is not possible.
Backbone.View.events uses internally this.$el.delegate which internally uses CSS selector which looks like doesn't support upwards selection.
You can instead add a position: absolute
div into your el
DOM element and make it transparent and fullscreen it. And then capture events from there.
Well I think I found a working solution!
In the initialize function I do
$('body').bind('mouseup', this.onMouseUp);
And it works like charm! :)
EDIT
Actually there is a big problem with that! The this is bind on the body and not on the view. So I have a parameter "pressed" and when I access it with this.pressed it tries to find it in the body....
EDIT
The solution I found to the problem above is to pass in the bind parameters a reference to this like:
$('body').bind('mouseup',{thisView : this}, this.onMouseUp);
And now it works like charm :P