From f133475405bd13d47de48e2afe8fd7f03614cf69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 18 Jun 2016 23:06:17 +0200 Subject: [PATCH] Implement MouseEvent#currentTarget and document MouseEvent#target. Relates to #995 --- src/core/Emitter.js | 8 +++++++- src/event/MouseEvent.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/core/Emitter.js b/src/core/Emitter.js index a83275ba..1b75b965 100644 --- a/src/core/Emitter.js +++ b/src/core/Emitter.js @@ -80,10 +80,14 @@ var Emitter = { var handlers = this._callbacks && this._callbacks[type]; if (!handlers) 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 // won't throw us off track here: handlers = handlers.slice(); + if (setTarget) + event.currentTarget = this; for (var i = 0, l = handlers.length; i < l; i++) { if (handlers[i].apply(this, args) === false) { // If the handler returns false, prevent the default behavior @@ -94,6 +98,8 @@ var Emitter = { break; } } + if (setTarget) + delete event.currentTarget; return true; }, diff --git a/src/event/MouseEvent.js b/src/event/MouseEvent.js index 667f1b5a..0a3ca604 100644 --- a/src/event/MouseEvent.js +++ b/src/event/MouseEvent.js @@ -51,6 +51,25 @@ var MouseEvent = Event.extend(/** @lends MouseEvent# */{ * @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 /** * @name MouseEvent#delta