From 9de41d6f916c49fa280939611f726a96e2461c4d Mon Sep 17 00:00:00 2001 From: daRoof <35702045+daRoof@users.noreply.github.com> Date: Wed, 30 Jan 2019 21:08:41 +0100 Subject: [PATCH] Update ItemSet.js (#4238) Delay the tooltip popup on items for 500ms. --- lib/timeline/component/ItemSet.js | 41 ++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index 46246144..485c5fe2 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -192,6 +192,7 @@ function ItemSet(body, options) { this.selection = []; // list with the ids of all selected nodes this.popup = null; + this.popupTimer = null; this.touchParams = {}; // stores properties while dragging this.groupTouchParams = {}; @@ -480,6 +481,8 @@ ItemSet.prototype.markDirty = function(options) { * Destroy the ItemSet */ ItemSet.prototype.destroy = function() { + this.clearPopupTimer(); + this.hide(); this.setItems(null); this.setGroups(null); @@ -536,6 +539,29 @@ ItemSet.prototype.show = function() { } }; +/** + * Activates the popup timer to show the given popup after a fixed time. + */ +ItemSet.prototype.setPopupTimer = function (popup) { + this.clearPopupTimer(); + if (popup) { + this.popupTimer = setTimeout( + function () { + popup.show() + }, 500); + } +}; + +/** + * Clears the popup timer for the tooltip. + */ +ItemSet.prototype.clearPopupTimer = function () { + if (this.popupTimer != null) { + clearTimeout(this.popupTimer); + this.popupTimer = null; + } +}; + /** * Set selected items by their id. Replaces the current selection * Unknown id's are silently ignored. @@ -1533,6 +1559,12 @@ ItemSet.prototype._onDragStartAddItem = function (event) { * @private */ ItemSet.prototype._onDrag = function (event) { + // deactivate tooltip window + this.clearPopupTimer(); + if (this.popup != null) { + this.popup.hide(); + } + if (this.touchParams.itemProps) { event.stopPropagation(); @@ -2016,10 +2048,11 @@ ItemSet.prototype._onMouseOver = function (event) { event.clientX - util.getAbsoluteLeft(container) + container.offsetLeft, event.clientY - util.getAbsoluteTop(container) + container.offsetTop ); - this.popup.show(); + this.setPopupTimer(this.popup); } else { // Hovering over item without a title, hide popup // Needed instead of _just_ in _onMouseOut due to #2572 + this.clearPopupTimer(); if (this.popup != null) { this.popup.hide(); } @@ -2041,6 +2074,7 @@ ItemSet.prototype._onMouseOut = function (event) { return; } + this.clearPopupTimer(); if (this.popup != null) { this.popup.hide(); } @@ -2054,6 +2088,11 @@ ItemSet.prototype._onMouseMove = function (event) { var item = this.itemFromTarget(event); if (!item) return; + if (this.popupTimer != null) { + // restart timer + this.setPopupTimer(this.popup); + } + if (this.options.showTooltips && this.options.tooltip.followMouse) { if (this.popup) { if (!this.popup.hidden) {