Read the statement by Michael Teeuw here.
Module Position
-
@dherl0623 ty Ik I can change it in there, but would have been cool to change during runtime so I can blend the module in at whatever place I currently need it ;) Well can’t change when it’s not possible
-
@maxbachmann there is now magicmirror api for it, but you could manipulate the dom and set the module in a different region manually.
-
@strawberry-3-141
How can I do that in there (sorry I am a absolute noob with the dom) -
I just asked my friend google:
var d = document.getElementById(wrapper); d.style.left = newx_pos; d.style.top = newy_pos;is that how to do it?
-
@maxbachmann no, you would get the module itself, the wrapper has an id with the identifier of the module, then you would get the wrapper of the position and would call appendChild with your module
-
@strawberry-3-141 Can you help me with how that would look like in software? I am sorry this project is the first time I use javascript at all and absolutely clueless when it’s about the dom
-
// get the module to move with it's identifier var clock = document.getElementById('module_0_clock'); // append it to the region you like document.querySelector('div.region.top.left div.container').appendChild(clock);it will work only if you already have a module in that position, otherwise you need to ovverride the style to display block
document.querySelector('div.region.top.left div.container').style.display = 'block';that’s it
-
@strawberry-3-141 So I always have to know wether there is already a element in that region? Is there a way to check all modules and return the ID’s of the elements that are in this position?
-
@strawberry-3-141 and where to add that? is that already the “end code”? I tried in the domupdate function and it did not work, so I guess that was wrong
-
it is safe to always run the code so you don’t need to check if there is a module necessarily.
it is not related to the get dom function, you can put it where ever you want except node_helper (because its not executed in the browser)
can you post the code of your module or upload it to github, then i can have a look
-
In general I want to add it to all kind of modules so I can change the position when sending them a socketmessage to do so
-
@maxbachmann i wouldn’t place that code in other modules, you can perform that from your module for every module, this isn’t magicmirror related. its pure dom manipulation.
-
Ah did not know that ;) well yes then it’s definetly in my program. All my program does so far is subscribe to a mqtt broker, load some data and according to this show/hide modules. Now I want to add the possibility to move modules to different positions.
Can send the current code later -
@strawberry-3-141 so in general use all 3 commands and then it works in both senarios? where can I find the right ID for each module?
-
@maxbachmann you can get all modules https://github.com/MichMich/MagicMirror/tree/master/modules#module-selection then iterate over them and when you find the module execute the cmds
const moduleToMove = 'clock'; const targetRegion = 'top.left'; MM.getModules().enumerate((module) => { if (module.name === moduleToMove) { const instance = document.getElementById(module.identifier); const region = document.querySelector(`div.region.${targetRegion} div.container`); region.appendChild(instance); region.style.display = 'block'; } });something similar to this
-
@strawberry-3-141 ty that works.
Added the possibility
region.insertBefore(instance, region.childNodes[0])so I can prepend and append the module
-
If you look in your css folder you will find the main.css file. Open it and you will find all the regions. Compare them to where you have you modules set and it should help you figure it out.
-
@justjim1220 it already works the way @strawberry-3-141 proposed :)
Only thing I am not quite sure about yet is when can I use const?
I have the code in socketmessagereceived. Can I use const in there when I do only give the variable one value each time it runs the function? Because for me it seems like the variables still exist when the function gets called again which would mean const does not work -
Sorry, still kinda new with this, that is beyond my scope!
-
@justjim1220 Same for me I am absolutely new to javascript. I generally know the system const because I use a lot of c++, but testing here seems like the variables actually get not deleted after SocketNotificationreceived function ends. And I have absolutely no clue on when to use the type let and which advantage it offers over var, because on some variables let works on others only var. const actually never worked in there.
I have my code here not fully ready yet:
socketNotificationReceived: function(notification, payload) { if (notification === 'HIDE_SHOW') { var obj = JSON.parse(payload.data.toString()); var max = obj.slots.length; for (let i = 0; i < max; ++i){ if (obj.slots[i].slotName === "HIDE" || obj.slots[i].slotName === "SHOW") { var HideShow = obj.slots[i].slotName; } } for (let i = 0; i < max; ++i){ if (obj.slots[i].slotName === "MODULE") { var Module = obj.slots[i].value.value; break; } } var Message = HideShow + "_" + Module; const moduleToMove = 'clock'; const targetRegion = 'top.left'; MM.getModules().enumerate((module) => { if (module.name === moduleToMove) { const instance = document.getElementById(module.identifier); const region = document.querySelector(`div.region.${targetRegion} div.container`); region.appendChild(instance); //region.insertBefore(instance, region.childNodes[0]) region.style.display = 'block'; } }); this.loaded = true; this.sendNotification(Message); } if (notification === 'ERROR') { this.sendNotification('SHOW_ALERT', payload); } }So at which positions would it be better to use const/let instead of var? And how is the performance of them? Because in c++ I definetly use const a lot for variables or member functions
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login