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

Function createDomObjects

js/main.js:11–64  ·  view source on GitHub ↗

* Create dom objects for all modules that are configured for a specific position.

()

Source from the content-addressed store, hash-verified

9 * Create dom objects for all modules that are configured for a specific position.
10 */
11async function createDomObjects () {
12 const domCreationPromises = [];
13
14 modules.forEach(function (module) {
15 if (typeof module.data.position !== "string") {
16 return;
17 }
18
19 let haveAnimateIn = null;
20 // check if have valid animateIn in module definition (module.data.animateIn)
21 if (module.data.animateIn && AnimateCSSIn.indexOf(module.data.animateIn) !== -1) haveAnimateIn = module.data.animateIn;
22
23 const wrapper = selectWrapper(module.data.position);
24
25 const dom = document.createElement("div");
26 dom.id = module.identifier;
27 dom.className = module.name;
28
29 if (typeof module.data.classes === "string") {
30 dom.className = `module ${dom.className} ${module.data.classes}`;
31 }
32
33 dom.style.order = (typeof module.data.order === "number" && Number.isInteger(module.data.order)) ? module.data.order : 0;
34
35 dom.opacity = 0;
36 wrapper.appendChild(dom);
37
38 const moduleHeader = document.createElement("header");
39 moduleHeader.innerHTML = module.getHeader();
40 moduleHeader.className = "module-header";
41 dom.appendChild(moduleHeader);
42
43 if (typeof module.getHeader() === "undefined" || module.getHeader() !== "") {
44 moduleHeader.style.display = "none;";
45 } else {
46 moduleHeader.style.display = "block;";
47 }
48
49 const moduleContent = document.createElement("div");
50 moduleContent.className = "module-content";
51 dom.appendChild(moduleContent);
52
53 domCreationPromises.push(createModuleDom(module, haveAnimateIn));
54 });
55
56 updateWrapperStates();
57
58 try {
59 await Promise.all(domCreationPromises);
60 _sendNotification("DOM_OBJECTS_CREATED");
61 } catch (error) {
62 Log.error(error);
63 }
64}
65
66/**
67 * Create and render a module DOM, then notify the module.

Callers 1

modulesStartedFunction · 0.85

Calls 5

selectWrapperFunction · 0.85
createModuleDomFunction · 0.85
updateWrapperStatesFunction · 0.85
_sendNotificationFunction · 0.85
getHeaderMethod · 0.80

Tested by

no test coverage detected