Skip to content

Instantly share code, notes, and snippets.

@ZeroBugBounce
Created June 19, 2014 14:50
Show Gist options
  • Save ZeroBugBounce/6ab7d0b961f6940f7fc5 to your computer and use it in GitHub Desktop.
Save ZeroBugBounce/6ab7d0b961f6940f7fc5 to your computer and use it in GitHub Desktop.
Forwarding of events from one UI element or set of elements to another
// this shows forwarding jQuery events to native events
// where the target is hard-coded
forwardEventTo: function(e) {
var iframeDocument = this.$el.find('iframe')[0].contentWindow.document;
var target = iframeDocument.elementFromPoint(e.offsetX, e.offsetY);
if (target) {
var props = _.extend(e.originalEvent, {
srcElement: target,
target: target,
toElement: target
});
var event = new MouseEvent(e.originalEvent.type, props);
target.dispatchEvent(event);
if(e.originalEvent.type === 'click') {
target.focus();
}
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment