Skip to content

Commit

Permalink
review animateCSS rules
Browse files Browse the repository at this point in the history
  • Loading branch information
bugsounet committed Sep 2, 2023
1 parent e53cf30 commit c3e2719
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const MM = (function () {
// create the domCreationPromise with AnimateCSS (with animateIn of module definition)
// or just display it
var domCreationPromise;
if (haveAnimateIn) domCreationPromise = updateDom(module, 500, null, null, true);
if (haveAnimateIn) domCreationPromise = updateDom(module, 1000, null, haveAnimateIn, true);
else domCreationPromise = updateDom(module, 0);

domCreationPromises.push(domCreationPromise);
Expand Down Expand Up @@ -166,7 +166,8 @@ const MM = (function () {
return;
}

if (createAnimatedDom) {
if (createAnimatedDom && animateIn !== null) {
// Log.log(`${module.identifier} createAnimatedDom (${animateIn})`);
updateModuleContent(module, newHeader, newContent);
if (!module.hidden) {
showModule(module, speed, null, { animate: animateIn });
Expand Down Expand Up @@ -274,16 +275,24 @@ const MM = (function () {
// can't be override with options.animate
else if (options.animate && _AnimateCSSOut.indexOf(options.animate) !== -1) haveAnimateName = options.animate;

if (!haveAnimateName) moduleWrapper.style.transition = `opacity ${speed / 1000}s`;
else {
Log.log(`${module.identifier} Has animateOut: ${haveAnimateName}`);
if (haveAnimateName) {
// with AnimateCSS
// Log.log(`${module.identifier} Has animateOut: ${haveAnimateName}`);
await AnimateCSS(module.identifier, haveAnimateName, speed / 1000);
}

moduleWrapper.style.opacity = 0;
moduleWrapper.classList.add("hidden");
// AnimateCSS is now done
moduleWrapper.style.opacity = 0;
moduleWrapper.classList.add("hidden");
moduleWrapper.style.position = "fixed";

if (!haveAnimateName) {
updateWrapperStates();
if (typeof callback === "function") {
callback();
}
} else {
// default MM² Animate
moduleWrapper.style.transition = `opacity ${speed / 1000}s`;
moduleWrapper.style.opacity = 0;
moduleWrapper.classList.add("hidden");
module.showHideTimer = setTimeout(function () {
// To not take up any space, we just make the position absolute.
// since it's fade out anyway, we can see it lay above or
Expand All @@ -297,14 +306,6 @@ const MM = (function () {
callback();
}
}, speed);
} else {
// AnimateCSS is now done
moduleWrapper.style.position = "fixed";

updateWrapperStates();
if (typeof callback === "function") {
callback();
}
}
} else {
// invoke callback even if no content, issue 1308
Expand All @@ -321,7 +322,7 @@ const MM = (function () {
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the show method.
*/
const showModule = function (module, speed, callback, options = {}) {
const showModule = async function (module, speed, callback, options = {}) {
// remove lockString if set in options.
if (options.lockString) {
const index = module.lockStrings.indexOf(options.lockString);
Expand Down Expand Up @@ -372,19 +373,20 @@ const MM = (function () {
const dummy = moduleWrapper.parentElement.parentElement.offsetHeight;
moduleWrapper.style.opacity = 1;

if (!haveAnimateName) {
if (haveAnimateName) {
// with AnimateCSS
// Log.log(`${module.identifier} Has animateIn: ${haveAnimateName}`);
await AnimateCSS(module.identifier, haveAnimateName, speed / 1000);
if (typeof callback === "function") {
callback();
}
} else {
// default MM² Animate
module.showHideTimer = setTimeout(function () {
if (typeof callback === "function") {
callback();
}
}, speed);
} else {
Log.log(`${module.identifier} Has animateIn: ${haveAnimateName}`);
AnimateCSS(module.identifier, haveAnimateName, speed / 1000).then(() => {
if (typeof callback === "function") {
callback();
}
});
}
} else {
// invoke callback
Expand Down

0 comments on commit c3e2719

Please sign in to comment.