Reputation: 29301
I'm trying to bind a couple of functions to a click event. Here's what I've got:
var Foreground = Backbone.Marionette.Layout.extend({
el: $('body'),
events: {
'click': 'tryResetContextMenu onClickDeselectCollections'
},
// Whenever the user clicks on any part of the UI that isn't a multi-select item, deselect the multi-select items.
onClickDeselectCollections: function (event) {
console.log("deselect collections");
var isMultiSelectItem = $(event.target).hasClass('multiSelectItem');
var isChildMultiSelectItem = $(event.target).closest('.multiSelectItem').length > 0;
if (!isMultiSelectItem && !isChildMultiSelectItem) {
this.deselectCollections();
}
},
// If a click occurs and the default isn't prevented, reset the context menu groups to hide it.
// Child elements will call event.preventDefault() to indicate that they have handled the context menu.
tryResetContextMenu: function (event) {
console.log("resetting context menu items");
if (event.isDefaultPrevented()) {
// TODO: I don't think this is the proper way to do this. I should be showing a new view with top/left defined?
this.contextMenu.currentView.show({
top: event.pageY,
// Show the element just slightly offset as to not break onHover effects.
left: event.pageX + 1
});
} else {
// Clearing the groups of the context menu will cause it to become hidden.
ContextMenuItems.reset();
}
}
});
Both functions don't fire, but work fine individually. Is this functionality supported?
Upvotes: 3
Views: 1515
Reputation: 4129
Do like this :
events: {
'click': function(event) {
this.tryResetContextMenu(event);
this.onClickDeselectCollections(event);
}
},
Upvotes: 5