I have a simple popover module that can be added to another view. This popover should listen for clicks or mouseups outside of his own view.
function(app) {
var Popover = app.module();
Popover.Views.Default = Backbone.View.extend({
className: 'popover',
initialize: function(options) {
_.bindAll(this, 'hideOutsideClick');
this.on('toggle', this.toggle);
this.render();
},
afterRender: function() {
//watch for clicks outside current view
$('html').on('click', this.hideOutsideClick);
},
remove: function() {
//cleanup
this.hide();
$('html').off('click', this.hideOutsideClick); this.$el.remove();
},
show: function() {
this.visible = true; this.$el.show();
},
hide: function() {
this.$el.hide(); this.visible = false;
},
toggle: function() {
this.visible ? this.hide() : this.show();
},
hideOutsideClick: function(event){
//on any click this is fired 4 times!!!
}
});
return Popover;
});
My problem is that the hideOutsideCallback is fired 4 times when a click is performed. Why?