Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Delayed tooltip popup #4238

Merged
merged 1 commit into from
Jan 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion lib/timeline/component/ItemSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1521,6 +1547,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();

Expand Down Expand Up @@ -2004,10 +2036,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();
}
Expand All @@ -2029,6 +2062,7 @@ ItemSet.prototype._onMouseOut = function (event) {
return;
}

this.clearPopupTimer();
if (this.popup != null) {
this.popup.hide();
}
Expand All @@ -2042,6 +2076,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) {
Expand Down