Merge pull request #1385 from umap-project/tooltip-mouseout
Cancel tooltip on mouseout
This commit is contained in:
commit
20767f7dc6
2 changed files with 6 additions and 4 deletions
|
@ -1736,7 +1736,7 @@ L.U.Editable = L.Editable.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
drawingTooltip: function (e) {
|
drawingTooltip: function (e) {
|
||||||
if (e.layer instanceof L.Marker && e.type != 'editable:drawing:move') {
|
if (e.layer instanceof L.Marker && e.type == 'editable:drawing:start') {
|
||||||
this.map.ui.tooltip({ content: L._('Click to add a marker') })
|
this.map.ui.tooltip({ content: L._('Click to add a marker') })
|
||||||
}
|
}
|
||||||
if (!(e.layer instanceof L.Polyline)) {
|
if (!(e.layer instanceof L.Polyline)) {
|
||||||
|
|
|
@ -135,8 +135,6 @@ L.U.UI = L.Evented.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
tooltip: function (opts) {
|
tooltip: function (opts) {
|
||||||
this.TOOLTIP_ID = Math.random()
|
|
||||||
const id = this.TOOLTIP_ID
|
|
||||||
function showIt() {
|
function showIt() {
|
||||||
if (opts.anchor && opts.position === 'top') {
|
if (opts.anchor && opts.position === 'top') {
|
||||||
this.anchorTooltipTop(opts.anchor)
|
this.anchorTooltipTop(opts.anchor)
|
||||||
|
@ -150,10 +148,11 @@ L.U.UI = L.Evented.extend({
|
||||||
L.DomUtil.addClass(this.parent, 'umap-tooltip')
|
L.DomUtil.addClass(this.parent, 'umap-tooltip')
|
||||||
this._tooltip.innerHTML = opts.content
|
this._tooltip.innerHTML = opts.content
|
||||||
}
|
}
|
||||||
|
this.TOOLTIP_ID = window.setTimeout(L.bind(showIt, this), opts.delay || 0)
|
||||||
|
const id = this.TOOLTIP_ID
|
||||||
function closeIt() {
|
function closeIt() {
|
||||||
this.closeTooltip(id)
|
this.closeTooltip(id)
|
||||||
}
|
}
|
||||||
window.setTimeout(L.bind(showIt, this), opts.delay || 0)
|
|
||||||
if (opts.anchor) {
|
if (opts.anchor) {
|
||||||
L.DomEvent.once(opts.anchor, 'mouseout', closeIt, this)
|
L.DomEvent.once(opts.anchor, 'mouseout', closeIt, this)
|
||||||
}
|
}
|
||||||
|
@ -200,6 +199,9 @@ L.U.UI = L.Evented.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
closeTooltip: function (id) {
|
closeTooltip: function (id) {
|
||||||
|
// Clear timetout even if a new tooltip has been added
|
||||||
|
// in the meantime. Eg. after a mouseout from the anchor.
|
||||||
|
window.clearTimeout(id)
|
||||||
if (id && id !== this.TOOLTIP_ID) return
|
if (id && id !== this.TOOLTIP_ID) return
|
||||||
this._tooltip.className = ''
|
this._tooltip.className = ''
|
||||||
this._tooltip.innerHTML = ''
|
this._tooltip.innerHTML = ''
|
||||||
|
|
Loading…
Reference in a new issue