Created
June 19, 2014 14:50
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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