Permalink
Browse files

Call preventDefault on events handled through {{action}}

The idea is that we'd like to be able to use arbitrary view methods as
action handlers. As it is, they need to `return false` or call
`e.preventDefault()` to be usable as handlers.

For the (presumably few) cases where default handling is desired, we can
still register our own handlers/delegates with jQuery, or use event
handling on views or with eventManagers, which does not have automatic
preventDefault/stopPropagation.
  • Loading branch information...
joliss committed May 31, 2012
1 parent b0814e7 commit 4b7b13f6f594a32b5abdc7419d22478f5f549328
@@ -67,8 +67,18 @@ ActionHelper.registerAction = function(actionName, eventName, target, view, cont
`jQuery.Event` object as its argument. The `jQuery.Event` object will be extended to include
a `view` property that is set to the original view interacted with (in this case the `aView` object).
### Event Propagation
Events triggered through the action helper will automatically have
`.preventDefault()` and `.stopPropagation()` called on them. You do not need
to do so in your event handlers, and you do not need to return `false`.
If you need the default handler to trigger, or if you need propagation,
you should either register your own event handler, or use event methods on
your view class.
### Specifying an Action Target
A `target` option can be provided to change which object will receive the method call. This option must be
a string representing a path to an object:
@@ -139,6 +139,7 @@ Ember.EventDispatcher = Ember.Object.extend(
handler = action.handler;
if (action.eventName === eventName) {
evt.preventDefault();
evt.stopPropagation();
return handler(evt);
}
@@ -166,6 +167,7 @@ Ember.EventDispatcher = Ember.Object.extend(
var handler = object[eventName];
if (Ember.typeOf(handler) === 'function') {
result = handler.call(object, evt, view);
// Do not preventDefault in eventManagers.
evt.stopPropagation();
}
else {
@@ -71,6 +71,8 @@ Ember.View.states.hasElement = {
// Handle events from `Ember.EventDispatcher`
handleEvent: function(view, eventName, evt) {
if (view.has(eventName)) {
// Handler should be able to re-dispatch events, so we don't
// preventDefault or stopPropagation.
return view.fire(eventName, evt);
} else {
return true; // continue event propagation

0 comments on commit 4b7b13f

Please sign in to comment.