code cosmetics: animateElement() 'highlight' by default

This commit is contained in:
tophf 2017-06-27 23:00:24 +03:00
parent 1aa5c11b10
commit dc846aa7dd
3 changed files with 10 additions and 5 deletions

View File

@ -246,7 +246,7 @@ function importFromString(jsonString) {
const styleElement = $('#style-' + event.target.dataset.id); const styleElement = $('#style-' + event.target.dataset.id);
if (styleElement) { if (styleElement) {
scrollElementIntoView(styleElement); scrollElementIntoView(styleElement);
animateElement(styleElement, {className: 'highlight'}); animateElement(styleElement);
} }
}; };
for (const block of $$('details')) { for (const block of $$('details')) {

9
dom.js
View File

@ -46,8 +46,13 @@ function scrollElementIntoView(element) {
} }
function animateElement(element, {className, removeExtraClasses = [], remove = false}) { function animateElement(
return new Promise(resolve => { element, {
className = 'highlight',
removeExtraClasses = [],
remove = false,
} = {}) {
return element && new Promise(resolve => {
element.addEventListener('animationend', function _() { element.addEventListener('animationend', function _() {
element.removeEventListener('animationend', _); element.removeEventListener('animationend', _);
element.classList.remove( element.classList.remove(

View File

@ -342,7 +342,7 @@ Object.assign(handleEvent, {
delete(event, entry) { delete(event, entry) {
const id = entry.styleId; const id = entry.styleId;
const {name} = BG.cachedStyles.byId.get(id) || {}; const {name} = BG.cachedStyles.byId.get(id) || {};
animateElement(entry, {className: 'highlight'}); animateElement(entry);
messageBox({ messageBox({
title: t('deleteStyleConfirm'), title: t('deleteStyleConfirm'),
contents: name, contents: name,
@ -420,7 +420,7 @@ function handleUpdate(style, {reason, method} = {}) {
} }
filterAndAppend({entry}); filterAndAppend({entry});
if (!entry.matches('.hidden') && reason != 'import') { if (!entry.matches('.hidden') && reason != 'import') {
animateElement(entry, {className: 'highlight'}); animateElement(entry);
scrollElementIntoView(entry); scrollElementIntoView(entry);
} }