Created
November 21, 2011 22:41
-
-
Save avhm/1384216 to your computer and use it in GitHub Desktop.
Simulate Mouse Events
This file contains hidden or 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
jasmineHelpers.simulateMouseEvent = function(selector, events) { | |
var targets = document.querySelectorAll(selector), | |
dispatch = []; | |
// Create our mouse events and push them onto our event array | |
for (var z in events){ | |
if(events.hasOwnProperty(z)){ | |
var evt = document.createEvent('MouseEvents'); | |
// Init event with sensible defaults | |
evt.initMouseEvent(events[z], true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
dispatch.push(evt); | |
} | |
} | |
// For each element, dispatch one of the passed in events | |
var len = targets.length; while ( len-- ) { | |
for (var x in dispatch){ | |
if(events.hasOwnProperty(x)){ | |
targets[len].dispatchEvent(dispatch[x]); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment