I wrote an absolutely drop-down menu. I fire a custom event when this menu opens:
ps.DropDown.prototype._onOpenComplete = function() { $(this).trigger('MENU_OPEN', [this]); }
This works fine when I know which instance of ps.DropDown is targeted:
var dd = new ps.DropDown(); $(dd).on('MENU_OPEN', fn);
However, I would like my custom event to appear in window.document if the event is not stopped from propagating. For example:
var dd = new ps.DropDown(); $(dd).on('MENU_OPEN', function(event, instance) { // this would stop bubbling to $(window.document) // event.stopPropagation(); }); $(window.document).on('MENU_OPEN', function(event, instance) { // bubbled! });
Is there a way to accomplish this using jQuery?
EDIT add an example by analogy
Clicking on a button element will trigger an event. This event will continue to bubble up the chain of parent elements until it reaches window.document (unless propagation is stopped by the event listener). I am interested in synthesizing this behavior for custom events, so if event.stopPropagation () is not called, it will bubble in window.document (or $ .event or some other global window, it does not matter)
thesmart
source share