Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom module positions #3231

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ _This release is scheduled to be released on 2024-01-01._

### Added

- custom module positions
reason see e.g.

- https://github.com/MichMich/MagicMirror/issues/3212
- https://forum.magicmirror.builders/topic/18069/multiple-modules-in-a-region/17

usage:

- define own module positions as html in `config.js`, key is `modulePositions`
- define own css styles in a new file in the `css` directory, the name of this file is specified in `config.js`, key is `modulePositionsCss`

### Removed

### Updated
Expand Down
84 changes: 0 additions & 84 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ sup {
pointer-events: auto;
}

.region.bottom .module {
margin-top: var(--gap-modules);
margin-bottom: 0;
}

.no-wrap {
white-space: nowrap;
overflow: hidden;
Expand All @@ -160,82 +155,3 @@ sup {
.pre-line {
white-space: pre-line;
}

/**
* Region Definitions.
*/

.region {
position: absolute;
}

.region.fullscreen {
position: absolute;
inset: calc(-1 * var(--gap-body-top)) calc(-1 * var(--gap-body-right)) calc(-1 * var(--gap-body-bottom)) calc(-1 * var(--gap-body-left));
pointer-events: none;
}

.region.right {
right: 0;
text-align: right;
}

.region.top {
top: 0;
}

.region.top.center,
.region.bottom.center {
left: 50%;
transform: translateX(-50%);
}

.region.top.right,
.region.top.left,
.region.top.center {
top: 100%;
}

.region.bottom {
bottom: 0;
}

.region.bottom.right,
.region.bottom.center,
.region.bottom.left {
bottom: 100%;
}

.region.bar {
width: 100%;
text-align: center;
}

.region.third,
.region.middle.center {
width: 100%;
text-align: center;
transform: translateY(-50%);
}

.region.upper.third {
top: 33%;
}

.region.middle.center {
top: 50%;
}

.region.lower.third {
top: 66%;
}

.region.left {
text-align: left;
}

.region table {
width: 100%;
border-spacing: 0;
border-collapse: separate;
}
83 changes: 83 additions & 0 deletions css/module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Region Definitions.
*/

.region.bottom .module {
margin-top: var(--gap-modules);
margin-bottom: 0;
}

.region {
position: absolute;
}

.region.fullscreen {
position: absolute;
inset: calc(-1 * var(--gap-body-top)) calc(-1 * var(--gap-body-right)) calc(-1 * var(--gap-body-bottom)) calc(-1 * var(--gap-body-left));
pointer-events: none;
}

.region.right {
right: 0;
text-align: right;
}

.region.top {
top: 0;
}

.region.top.center,
.region.bottom.center {
left: 50%;
transform: translateX(-50%);
}

.region.top.right,
.region.top.left,
.region.top.center {
top: 100%;
}

.region.bottom {
bottom: 0;
}

.region.bottom.right,
.region.bottom.center,
.region.bottom.left {
bottom: 100%;
}

.region.bar {
width: 100%;
text-align: center;
}

.region.third,
.region.middle.center {
width: 100%;
text-align: center;
transform: translateY(-50%);
}

.region.upper.third {
top: 33%;
}

.region.middle.center {
top: 50%;
}

.region.lower.third {
top: 66%;
}

.region.left {
text-align: left;
}

.region table {
width: 100%;
border-spacing: 0;
border-collapse: separate;
}
21 changes: 2 additions & 19 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<link rel="icon" href="data:;base64,iVBORw0KGgo=" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/#MODULE_CSS#" />
<link rel="stylesheet" type="text/css" href="fonts/roboto.css" />
<link rel="stylesheet" type="text/css" href="vendor/node_modules/animate.css/animate.min.css" />
<!-- custom.css is loaded by the loader.js to make sure it's loaded after the module css files. -->
Expand All @@ -21,25 +22,7 @@
</script>
</head>
<body>
<div class="region fullscreen below"><div class="container"></div></div>
<div class="region top bar">
<div class="container"></div>
<div class="region top left"><div class="container"></div></div>
<div class="region top center"><div class="container"></div></div>
<div class="region top right"><div class="container"></div></div>
</div>
<div class="region upper third"><div class="container"></div></div>
<div class="region middle center"><div class="container"></div></div>
<div class="region lower third">
<div class="container"><br /></div>
</div>
<div class="region bottom bar">
<div class="container"></div>
<div class="region bottom left"><div class="container"></div></div>
<div class="region bottom center"><div class="container"></div></div>
<div class="region bottom right"><div class="container"></div></div>
</div>
<div class="region fullscreen above"><div class="container"></div></div>
#MODULE_POSITIONS#
<script type="text/javascript" src="socket.io/socket.io.js"></script>
<script type="text/javascript" src="vendor/node_modules/nunjucks/browser/nunjucks.min.js"></script>
<script type="text/javascript" src="js/defaults.js"></script>
Expand Down
3 changes: 3 additions & 0 deletions js/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const defaults = {
// (interval 30 seconds). If startup-timestamp has changed the client reloads the magicmirror webpage.
checkServerInterval: 30 * 1000,
reloadAfterServerRestart: false,
modulePositions:
'<div class="region fullscreen below"><div class="container"></div></div><div class="region top bar"><div class="container"></div><div class="region top left"><div class="container"></div></div><div class="region top center"><div class="container"></div></div><div class="region top right"><div class="container"></div></div></div><div class="region upper third"><div class="container"></div></div><div class="region middle center"><div class="container"></div></div><div class="region lower third"><div class="container"><br /></div></div><div class="region bottom bar"><div class="container"></div><div class="region bottom left"><div class="container"></div></div><div class="region bottom center"><div class="container"></div></div><div class="region bottom right"><div class="container"></div></div></div><div class="region fullscreen above"><div class="container"></div></div>',
modulePositionsCss: "module.css",

modules: [
{
Expand Down
8 changes: 7 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,13 @@ const MM = (function () {
* update notification is not visible.
*/
const updateWrapperStates = function () {
const positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
let livePos = config.modulePositions.replaceAll('"', "").split("<div class=");
let positions = [];
for (let i in livePos) {
if (!livePos[i].includes("/div") && livePos[i].length > 0) {
positions.push(livePos[i].replace("region ", "").replace(">", "").replace(" ", "_"));
}
}

positions.forEach(function (position) {
const wrapper = selectWrapper(position);
Expand Down
2 changes: 2 additions & 0 deletions js/server_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ function getHtml(req, res) {
configFile = global.configuration_file;
}
html = html.replace("#CONFIG_FILE#", configFile);
html = html.replace("#MODULE_POSITIONS#", config.modulePositions);
html = html.replace("#MODULE_CSS#", config.modulePositionsCss);

res.send(html);
}
Expand Down