Permalink
Browse files

Add relatedTarget for mouseover/mouseout

  • Loading branch information...
1 parent 1a246a9 commit e56e9cc82df006ac2f14f8286d4973b951e5aeed @davidaurelio davidaurelio committed Dec 12, 2012
Showing with 27 additions and 6 deletions.
  1. +3 −2 src/renderer/renderer_controller.js
  2. +16 −3 src/renderer/svg/svg_event_handlers.js
  3. +8 −1 src/runner/stage.js
@@ -64,10 +64,11 @@ function(tools, EventEmitter, URI) {
});
// Bind to renderer, tunnel user events through to RunnerContext:
- this.renderer.on('userevent', this, function(event, targetId) {
+ this.renderer.on('userevent', this, function(event, targetId, relatedTargetId) {
this.post('userevent', {
event: event,
- targetId: targetId
+ targetId: targetId,
+ relatedTargetId: relatedTargetId
});
});
@@ -8,6 +8,9 @@ define([
], function(tools) {
'use strict';
+ /** @const */
+ var ELEMENT_NODE = 1;
+
var TOUCH_SUPPORT = typeof document == 'undefined' ? false : 'createTouch' in document;
var rMultiEvent = /drag|pointerup|pointerdown|pointermove/;
var rPointerEvent = /click|pointer/;
@@ -23,7 +26,7 @@ define([
* @return {number} The bonsai id of the dom node or -1
*/
function getBonsaiIdOf(node) {
- var id = node && node.getAttribute && node.getAttribute('data-bs-id');
+ var id = node && node.nodeType === ELEMENT_NODE && node.getAttribute('data-bs-id');
return id ? +id : -1; // string '0' evaluates to true
}
@@ -44,7 +47,7 @@ define([
* @return {Node}
*/
function findBonsaiObject(node) {
- while (node && getBonsaiIdOf(node) === -1) {
+ while (node && (node.nodeType !== ELEMENT_NODE || node.hasAttribute('bs-data-id'))) {
node = node.parentNode;
}
return node;
@@ -157,6 +160,7 @@ define([
targetId = 0;
}
+ var relatedTarget;
var event = this._getBasicEventData(domEvent),
clientX = event.clientX,
@@ -242,6 +246,15 @@ define([
// Pass focused element's value to bonsai
event.inputValue = domEvent.target.value;
break;
+
+ case 'mouseover':
+ relatedTarget = domEvent.relatedTarget || domEvent.fromElement;
+ relatedTarget = findBonsaiObject(relatedTarget);
+ break;
+ case 'mouseout':
+ relatedTarget = domEvent.relatedTarget || domEvent.toElement;
+ relatedTarget = findBonsaiObject(relatedTarget);
+ break;
}
data._lastEventPos = [clientX, clientY];
@@ -255,7 +268,7 @@ define([
domEvent.button === 1 || domEvent.button === 0;
}
- this.emit('userevent', event, targetId);
+ this.emit('userevent', event, targetId, relatedTarget && getBonsaiIdOf(relatedTarget));
if (!TOUCH_SUPPORT && rMultiEvent.test(type)) {
// If we're on a non-touch platform (e.g. regular desktop)
View
@@ -136,10 +136,17 @@ define([
this.assetLoader.handleEvent('error', data.id, data.loadData);
break;
case 'userevent':
- var target = data.targetId ? this.registry.displayObjects[data.targetId] : this;
+ var displayObjectsRegistry = this.registry.displayObjects;
+ var targetId = data.targetId;
+ var target = targetId ? displayObjectsRegistry[targetId] : this;
if (target) { // target might have been removed already
var event = data.event;
event.target = target;
+ var relatedTargetId = data.relatedTargetId;
+ if (relatedTargetId === 0 || relatedTargetId > 0) {
+ event.relatedTarget = displayObjectsRegistry[relatedTargetId] || this;
+ }
+
uiEvent(event).emitOn(target);
}
break;

0 comments on commit e56e9cc

Please sign in to comment.