Skip to content

Commit

Permalink
Added useCapture, stopPropagation and preventDefault parameters to Do…
Browse files Browse the repository at this point in the history
…mEventAction.
  • Loading branch information
schteppe committed Jun 16, 2016
1 parent 691bdf3 commit 832c3e4
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/goo/fsmpack/statemachine/actions/DomEventAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ DomEventAction.external = {
type: 'string',
description: 'Query selector that matches your DOM element(s). For example, set "canvas" if you want to match all <canvas> elements, or ".myClass" to match all elements with your class.',
'default': 'body'
},{
name: 'Use capture',
key: 'useCapture',
type: 'boolean',
description: '',
'default': true
},{
name: 'Stop propagation',
key: 'stopPropagation',
type: 'boolean',
description: '',
'default': true
},{
name: 'Prevent Default',
key: 'preventDefault',
type: 'boolean',
description: '',
'default': false
}],
transitions: [{
key: 'event',
Expand All @@ -39,13 +57,19 @@ DomEventAction.getTransitionLabel = function (transitionKey, actionConfig) {
};

DomEventAction.prototype.enter = function (fsm) {
this.eventListener = function () {
this.eventListener = function (evt) {
fsm.send(this.transitions.event);
if (this.stopPropagation) {
evt.stopPropagation();
}
if (this.preventDefault) {
evt.preventDefault();
}
}.bind(this);

var elements = this.domElements = document.querySelectorAll(this.querySelector);
for (var i = 0; i < elements.length; i++) {
elements[i].addEventListener(this.eventName, this.eventListener);
elements[i].addEventListener(this.eventName, this.eventListener, !!this.useCapture);
}
};

Expand Down

0 comments on commit 832c3e4

Please sign in to comment.