mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 07:46:58 +02:00
Let D3 handle the delay rather than using setTimeout
This also fixes a race condition where it was possible to lose a flash message that was created while the previous one was transitioning away.
This commit is contained in:
+12
-20
@@ -1,12 +1,13 @@
|
||||
import * as d3 from 'd3';
|
||||
|
||||
var timeout;
|
||||
|
||||
|
||||
export function uiFlash(showDuration, fadeDuration) {
|
||||
showDuration = showDuration || 1500;
|
||||
fadeDuration = fadeDuration || 250;
|
||||
|
||||
d3.select('#flash').selectAll('.content')
|
||||
.interrupt();
|
||||
|
||||
var content = d3.select('#flash').selectAll('.content')
|
||||
.data([0]);
|
||||
|
||||
@@ -15,24 +16,15 @@ export function uiFlash(showDuration, fadeDuration) {
|
||||
.attr('class', 'content fillD')
|
||||
.merge(content);
|
||||
|
||||
if (timeout) {
|
||||
window.clearTimeout(timeout);
|
||||
}
|
||||
|
||||
timeout = window.setTimeout(function() {
|
||||
content
|
||||
.transition()
|
||||
.duration(fadeDuration)
|
||||
.style('opacity', 0)
|
||||
.style('transform', 'scaleY(.1)')
|
||||
.on('end', function() {
|
||||
content.remove();
|
||||
timeout = null;
|
||||
});
|
||||
|
||||
return true;
|
||||
}, showDuration);
|
||||
|
||||
content
|
||||
.transition()
|
||||
.delay(showDuration)
|
||||
.duration(fadeDuration)
|
||||
.style('opacity', 0)
|
||||
.style('transform', 'scaleY(.1)')
|
||||
.on('interrupt end', function() {
|
||||
content.remove();
|
||||
});
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user