From 3a4b8c4cb6b2e623e649e6cf3b3585b53f589b15 Mon Sep 17 00:00:00 2001 From: Lewis B Date: Thu, 5 Jan 2017 05:42:26 +1000 Subject: [PATCH] Fixed hover events for HTML elements (#2539) --- lib/timeline/component/ItemSet.js | 50 ++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index 16e7c48d..022e4f18 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -1875,6 +1875,13 @@ ItemSet.prototype._onMouseOver = function (event) { var item = this.itemFromTarget(event); if (!item) return; + // Item we just left + var related = this.itemFromRelatedTarget(event); + if (item === related) { + // We haven't changed item, just element in the item + return; + } + if (item.getTitle()) { if (item.popup == null) { item.setPopup(new Popup(this.body.dom.root)); @@ -1897,6 +1904,13 @@ ItemSet.prototype._onMouseOut = function (event) { var item = this.itemFromTarget(event); if (!item) return; + // Item we are going to + var related = this.itemFromRelatedTarget(event); + if (item === related) { + // We aren't changing item, just element in the item + return; + } + if (item.popup != null) { item.popup.hide(); } @@ -2118,6 +2132,24 @@ ItemSet._getItemRange = function(itemsData) { } }; +/** + * Find an item from an element: + * searches for the attribute 'timeline-item' in the element's tree + * @param {HTMLElement} element + * @return {Item | null} item + */ +ItemSet.prototype.itemFromElement = function(element) { + var cur = element; + while (cur) { + if (cur.hasOwnProperty('timeline-item')) { + return cur['timeline-item']; + } + cur = cur.parentNode; + } + + return null; +}; + /** * Find an item from an event target: * searches for the attribute 'timeline-item' in the event target's element tree @@ -2125,15 +2157,17 @@ ItemSet._getItemRange = function(itemsData) { * @return {Item | null} item */ ItemSet.prototype.itemFromTarget = function(event) { - var target = event.target; - while (target) { - if (target.hasOwnProperty('timeline-item')) { - return target['timeline-item']; - } - target = target.parentNode; - } + return this.itemFromElement(event.target); +}; - return null; +/** + * Find an item from an event's related target: + * searches for the attribute 'timeline-item' in the related target's element tree + * @param {Event} event + * @return {Item | null} item + */ +ItemSet.prototype.itemFromRelatedTarget = function(event) { + return this.itemFromElement(event.relatedTarget); }; /**