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

Commit

Permalink
Update ItemSet.js (#4238)
Browse files Browse the repository at this point in the history
Delay the tooltip popup on items for 500ms.
  • Loading branch information
daRoof authored and mojoaxel committed Jan 30, 2019
1 parent 773d973 commit 9de41d6
Showing 1 changed file with 40 additions and 1 deletion.
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 @@ -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();

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

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

0 comments on commit 9de41d6

Please sign in to comment.