Browse Source

Fixed hover events for HTML elements (#2539)

fix2580
Lewis B 7 years ago
committed by yotamberk
parent
commit
3a4b8c4cb6
1 changed files with 42 additions and 8 deletions
  1. +42
    -8
      lib/timeline/component/ItemSet.js

+ 42
- 8
lib/timeline/component/ItemSet.js View File

@ -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);
};
/**

Loading…
Cancel
Save