MCPcopy
hub / github.com/MagicMirrorOrg/MagicMirror / _showModule

Function _showModule

js/main.js:328–417  ·  view source on GitHub ↗

* Show the module. * @param {Module} module The module to show. * @param {number} speed The speed of the show animation. * @param {() => void} callback Called when the animation is done. * @param {object} [options] Optional settings for the show method.

(module, speed, callback, options = {})

Source from the content-addressed store, hash-verified

326 * @param {object} [options] Optional settings for the show method.
327 */
328function _showModule (module, speed, callback, options = {}) {
329 // remove lockString if set in options.
330 if (options.lockString) {
331 const index = module.lockStrings.indexOf(options.lockString);
332 if (index !== -1) {
333 module.lockStrings.splice(index, 1);
334 }
335 }
336
337 // Check if there are no more lockStrings set, or the force option is set.
338 // Otherwise cancel show action.
339 if (module.lockStrings.length !== 0 && options.force !== true) {
340 Log.log(`Will not show ${module.name}. LockStrings active: ${module.lockStrings.join(",")}`);
341 if (typeof options.onError === "function") {
342 options.onError(new Error("LOCK_STRING_ACTIVE"));
343 }
344 return;
345 }
346 // reset all animations if needed
347 if (module.hasAnimateOut) {
348 removeAnimateCSS(module.identifier, module.hasAnimateOut);
349 Log.debug(`${module.identifier} Force remove animateOut (in show): ${module.hasAnimateOut}`);
350 module.hasAnimateOut = false;
351 }
352 if (module.hasAnimateIn) {
353 removeAnimateCSS(module.identifier, module.hasAnimateIn);
354 Log.debug(`${module.identifier} Force remove animateIn (in show): ${module.hasAnimateIn}`);
355 module.hasAnimateIn = false;
356 }
357
358 module.hidden = false;
359
360 // If forced show, clean current lockStrings.
361 if (module.lockStrings.length !== 0 && options.force === true) {
362 Log.log(`Force show of module: ${module.name}`);
363 module.lockStrings = [];
364 }
365
366 const moduleWrapper = document.getElementById(module.identifier);
367 if (moduleWrapper !== null) {
368 clearTimeout(module.showHideTimer);
369
370 // haveAnimateName for verify if we are using AnimateCSS library
371 // we check AnimateCSSIn Array for validate it
372 // and finally return the animate name or `null` (for default MM² animation)
373 let haveAnimateName = null;
374 // check if have valid animateOut in module definition (module.data.animateIn)
375 if (module.data.animateIn && AnimateCSSIn.indexOf(module.data.animateIn) !== -1) haveAnimateName = module.data.animateIn;
376 // can't be override with options.animate
377 else if (options.animate && AnimateCSSIn.indexOf(options.animate) !== -1) haveAnimateName = options.animate;
378
379 if (!haveAnimateName) moduleWrapper.style.transition = `opacity ${speed / 1000}s`;
380 // Restore the position. See _hideModule() for more info.
381 moduleWrapper.style.position = "static";
382 moduleWrapper.classList.remove("hidden");
383
384 updateWrapperStates();
385

Callers 2

updateDomWithContentFunction · 0.85
showModuleFunction · 0.85

Calls 4

removeAnimateCSSFunction · 0.85
updateWrapperStatesFunction · 0.85
addAnimateCSSFunction · 0.85
onErrorMethod · 0.45

Tested by

no test coverage detected