Implement MouseEvent#currentTarget and document MouseEvent#target.

Relates to #995
This commit is contained in:
Jürg Lehni 2016-06-18 23:06:17 +02:00
parent f97143d37d
commit f133475405
2 changed files with 26 additions and 1 deletions

View file

@ -80,10 +80,14 @@ var Emitter = {
var handlers = this._callbacks && this._callbacks[type]; var handlers = this._callbacks && this._callbacks[type];
if (!handlers) if (!handlers)
return false; return false;
var args = [].slice.call(arguments, 1); var args = [].slice.call(arguments, 1),
setTarget = event && 'target' in event &&
!('currentTarget' in event);
// Create a clone of the handlers list so changes caused by on / off // Create a clone of the handlers list so changes caused by on / off
// won't throw us off track here: // won't throw us off track here:
handlers = handlers.slice(); handlers = handlers.slice();
if (setTarget)
event.currentTarget = this;
for (var i = 0, l = handlers.length; i < l; i++) { for (var i = 0, l = handlers.length; i < l; i++) {
if (handlers[i].apply(this, args) === false) { if (handlers[i].apply(this, args) === false) {
// If the handler returns false, prevent the default behavior // If the handler returns false, prevent the default behavior
@ -94,6 +98,8 @@ var Emitter = {
break; break;
} }
} }
if (setTarget)
delete event.currentTarget;
return true; return true;
}, },

View file

@ -51,6 +51,25 @@ var MouseEvent = Event.extend(/** @lends MouseEvent# */{
* @type Point * @type Point
*/ */
/**
* The item that dispatched the event. It is different from
* {@link #currentTarget} when the event handler is called during
* the bubbling phase of the event.
*
* @name MouseEvent#target
* @type Item
*/
/**
* The current target for the event, as the event traverses the scene graph.
* It always refers to the element the event handler has been attached to as
* opposed to {@link #target} which identifies the element on
* which the event occurred.
*
* @name MouseEvent#currentTarget
* @type Item
*/
// DOCS: document MouseEvent#delta // DOCS: document MouseEvent#delta
/** /**
* @name MouseEvent#delta * @name MouseEvent#delta