Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created September 9, 2010 14:22
Show Gist options
  • Save 3rd-Eden/571923 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/571923 to your computer and use it in GitHub Desktop.
if( json.css3 ){
var css = json.css3,
qsa = document.querySelectorAll( css.selector ),
element = qsa[ css.index ];
// https://developer.mozilla.org/en/DOM/document.createEvent
// https://developer.mozilla.org/en/DOM/event.initMouseEvent
if( element ){
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent(
"click", //the string to set the event's type to. Possible types for mouse events include: click, mousedown, mouseup, mouseover, mousemove, mouseout.
true, //whether or not the event can bubble. Sets the value of event.bubbles.
true, //whether or not the event's default action can be prevented. Sets the value of event.cancelable.
window, //the Event's AbstractView. You should pass the window object here. Sets the value of event.view.
0, //the Event's mouse click count. Sets the value of event.detail.
0, //the Event's screen x coordinate. Sets the value of event.screenX.
0, //the Event's screen y coordinate. Sets the value of event.screenY.
json.response.x, //the Event's client x coordinate. Sets the value of event.clientX.
json.response.y, //the Event's client y coordinate. Sets the value of event.clientY.
false, //whether or not control key was depressed during the Event. Sets the value of event.ctrlKey.
false, //whether or not alt key was depressed during the Event. Sets the value of event.altKey.
false, //whether or not shift key was depressed during the Event. Sets the value of event.shiftKey.
false, //whether or not meta key was depressed during the Event. Sets the value of event.metaKey.
json.response.button, //the Event's mouse event.button.
null //the Event's related EventTarget. Only used with some event types (e.g. mouseover and mouseout). In other cases, pass null.
);
return element.dispatchEvent( evt );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment