Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(ngScenario): provide event parameters as object
Browse files Browse the repository at this point in the history
BREAKING CHANGE: browserTrigger now uses an eventData object instead of direct parameters for mouse events.
To migrate, place the `keys`,`x` and `y` parameters inside of an object and place that as the third parameter
for the browserTrigger function.
  • Loading branch information
matsko committed Sep 6, 2013
1 parent 32ad292 commit 28f56a3
Show file tree
Hide file tree
Showing 4 changed files with 471 additions and 99 deletions.
54 changes: 41 additions & 13 deletions src/ngScenario/browserTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@
* not specified.
*
* @param {Object} element Either a wrapped jQuery/jqLite node or a DOMElement
* @param {string} eventType Optional event type.
* @param {Array.<string>=} keys Optional list of pressed keys
* (valid values: 'alt', 'meta', 'shift', 'ctrl')
* @param {number} x Optional x-coordinate for mouse/touch events.
* @param {number} y Optional y-coordinate for mouse/touch events.
* @param {string} eventType Optional event type
* @param {Object=} eventData An optional object which contains additional event data (such as x,y coordinates, keys, etc...) that
* are passed into the event when triggered
*/
window.browserTrigger = function browserTrigger(element, eventType, keys, x, y) {
window.browserTrigger = function browserTrigger(element, eventType, eventData) {
if (element && !element.nodeName) element = element[0];
if (!element) return;

eventData = eventData || {};
var keys = eventData.keys;
var x = eventData.x;
var y = eventData.y;

var inputType = (element.type) ? element.type.toLowerCase() : null,
nodeName = element.nodeName.toLowerCase();

Expand Down Expand Up @@ -86,8 +89,38 @@
}
return ret;
} else {
var evnt = document.createEvent('MouseEvents'),
originalPreventDefault = evnt.preventDefault,
var evnt;
if(/transitionend/.test(eventType)) {
if(window.WebKitTransitionEvent) {
evnt = new WebKitTransitionEvent(eventType, eventData);
evnt.initEvent(eventType, false, true);
}
else {
evnt = document.createEvent('TransitionEvent');
evnt.initTransitionEvent(eventType, null, null, null, eventData.elapsedTime);
}
}
else if(/animationend/.test(eventType)) {
if(window.WebKitAnimationEvent) {
evnt = new WebKitAnimationEvent(eventType, eventData);
evnt.initEvent(eventType, false, true);
}
else {
evnt = document.createEvent('AnimationEvent');
evnt.initAnimationEvent(eventType, null, null, null, eventData.elapsedTime);
}
}
else {
evnt = document.createEvent('MouseEvents');
x = x || 0;
y = y || 0;
evnt.initMouseEvent(eventType, true, true, window, 0, x, y, x, y, pressed('ctrl'), pressed('alt'),
pressed('shift'), pressed('meta'), 0, element);
}

if(!evnt) return;

var originalPreventDefault = evnt.preventDefault,
appWindow = element.ownerDocument.defaultView,
fakeProcessDefault = true,
finalProcessDefault,
Expand All @@ -100,11 +133,6 @@
return originalPreventDefault.apply(evnt, arguments);
};

x = x || 0;
y = y || 0;
evnt.initMouseEvent(eventType, true, true, window, 0, x, y, x, y, pressed('ctrl'), pressed('alt'),
pressed('shift'), pressed('meta'), 0, element);

element.dispatchEvent(evnt);
finalProcessDefault = !(angular['ff-684208-preventDefault'] || !fakeProcessDefault);

Expand Down
Loading

0 comments on commit 28f56a3

Please sign in to comment.