use callbacks in animateElement to avoid re-animation

This commit is contained in:
tophf 2017-08-31 13:23:12 +03:00
parent 58b52b0bf0
commit fa5ebb8958
3 changed files with 12 additions and 8 deletions

View File

@ -169,7 +169,7 @@ function animateElement(
element, { element, {
className = 'highlight', className = 'highlight',
removeExtraClasses = [], removeExtraClasses = [],
remove = false, onComplete,
} = {}) { } = {}) {
return element && new Promise(resolve => { return element && new Promise(resolve => {
element.addEventListener('animationend', function _() { element.addEventListener('animationend', function _() {
@ -180,9 +180,9 @@ function animateElement(
// This is helpful to clean-up on the same frame // This is helpful to clean-up on the same frame
...removeExtraClasses ...removeExtraClasses
); );
// TODO: investigate why animation restarts if the elements is removed in .then() // TODO: investigate why animation restarts for 'display' modification in .then()
if (remove) { if (typeof onComplete === 'function') {
element.remove(); onComplete.call(element);
} }
resolve(); resolve();
}); });

View File

@ -45,8 +45,10 @@ function messageBox({
function resolveWith(value) { function resolveWith(value) {
unbindGlobalListeners(); unbindGlobalListeners();
setTimeout(messageBox.resolve, 0, value); setTimeout(messageBox.resolve, 0, value);
animateElement(messageBox.element, {className: 'fadeout', remove: true}) animateElement(messageBox.element, {
.then(removeSelf); className: 'fadeout',
onComplete: removeSelf,
});
} }
function createElement() { function createElement() {

View File

@ -312,8 +312,10 @@ Object.assign(handleEvent, {
}; };
function confirm(ok) { function confirm(ok) {
window.onkeydown = null; window.onkeydown = null;
animateElement(box, {className: 'lights-on'}) animateElement(box, {
.then(() => (box.dataset.display = false)); className: 'lights-on',
onComplete: () => (box.dataset.display = false),
});
if (ok) { if (ok) {
deleteStyleSafe({id}).then(() => { deleteStyleSafe({id}).then(() => {
// update view with 'No styles installed for this site' message // update view with 'No styles installed for this site' message