Skip to content

Commit

Permalink
cleaned up configureWidgets.js file
Browse files Browse the repository at this point in the history
  • Loading branch information
BennoCrafter committed Nov 10, 2023
1 parent 08e4ec8 commit a04c488
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 88 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 0 additions & 8 deletions IMPORTANTTODO.md

This file was deleted.

9 changes: 1 addition & 8 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# TODO

- IMPORTANT: add feature to set the lang and long of weather widget

- add simple adding from custom widgets

- add random notes widget


- add function to save label in index.js file

- clean up configureWidgets.js file
- add vanilla toast lib
5 changes: 4 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
<script defer src="js/configureWidgets.js" type="module"></script>
<script defer src="js/widget.js" type="module"></script>
<script defer src="js/widgetSettingsMenu.js" type="module"></script>
<script defer src="js/editButton.js" type="module"></script>
<script defer src="js/ButtonHandlers/editButton.js" type="module"></script>
<script defer src="js/ButtonHandlers/addWidgetButton.js" type="module"></script>
<script defer src="js/addNew.js" type="module"></script>
<script defer src="js/manageOrder.js" type="module"></script>
<script defer src="js/rePosWidgets.js" type="module"></script>
<script defer src="js/save.js" type="module"></script>
</head>
<body id="body">
<script src="lib/vanilla-toast.min.js"></script>
Expand Down
21 changes: 21 additions & 0 deletions src/js/ButtonHandlers/addWidgetButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { addWidget } from "../configureWidgets.js";

const addButton = document.getElementById("addWidgetButton");
const menu = document.querySelector(".widgetButtonsMenu");

addButton.addEventListener("click", function () {
if (menu.style.display === "none" || menu.style.display === "") {
menu.style.display = "block";
} else {
menu.style.display = "none";
}
});

document.addEventListener("click", function (event) {
if (!menu.contains(event.target) && event.target !== addButton) {
menu.style.display = "none";
} else if (menu.contains(event.target) && event.target !== addButton) {
menu.style.display = "none";
addWidget(event.target.getAttribute("data-widgetType"));
}
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { widgets } from "./configureWidgets.js";
import { widgets } from "../configureWidgets.js";

const editButton = document.getElementById("editButton")
let editMode = false;
Expand Down
3 changes: 3 additions & 0 deletions src/js/Widgets/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export class CalendarWidget extends Widget {
li.appendChild(date);

ul.appendChild(li);
ul.addEventListener("click", (event) => {

})
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/Widgets/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class WeatherWidget extends Widget {
const imgSrc = dayPath.querySelector("#weather-src");
imgSrc.src = `resources/weather-icons/${weatherPath}`;
// set temperature
dayPath.querySelector(".temperature").textContent = temp;
dayPath.querySelector(".temperature").textContent = temp + "°";

// set location
dayPath.querySelector(".location").textContent = this.uniqueWidgetData.loc;
Expand Down
73 changes: 5 additions & 68 deletions src/js/configureWidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { TextBox } from "./Widgets/textBox.js";
import { MediaWidget } from "./Widgets/media.js";
import { WeatherWidget } from "./Widgets/weather.js";
import { CalendarWidget } from "./Widgets/calendar.js";


import {currentProject, currentProjectPage} from "./manageOrder.js"
import { rePosWidgets } from "./rePosWidgets.js";

export let widgets = [];
let widgetData = {};
Expand Down Expand Up @@ -60,7 +63,8 @@ const loadWidgetData = async () =>{
await restoreData()
await loadPage()
}
function addWidget(type){

export function addWidget(type){
const exampleDataExtended = {...exampleData, ...{type: type, page: currentProjectPage, project: currentProject}}
spawnWidget(widgetData[type]["html"], {... widgetData[type]["uniqueWidgetData"]}, new Date().getTime(), type, {... exampleDataExtended})
}
Expand Down Expand Up @@ -89,71 +93,4 @@ function spawnWidget(html, uniqueWidgetData, wId, wType, data){

}

addEventListener("beforeunload", (event) => {
for (let w of widgets){
w.saveData()
}
});



function rePosWidgets(){
let width = window.innerWidth
let height = window.innerHeight
for (let w of widgets) {
const anchorX = w.data.anchorX;
const anchorY = w.data.anchorY;
let newXPos;
let newYPos;

// rePos x
if (anchorX[0] == "right") {
newXPos = width - parseInt(w.uniqueWidgetData.width) - parseInt(anchorX[1]);
} else if (anchorX[0] == "left") {
newXPos = parseInt(anchorX[1]);
}

// rePos y
if (anchorY[0] == "bottom") {
newYPos = height - parseInt(w.uniqueWidgetData.height) - parseInt(anchorY[1]);
} else if (anchorY[0] == "top") {
newYPos = parseInt(anchorY[1]);
}


w.data.xPos = newXPos + "px";
w.data.yPos = newYPos + "px";
w.updatePos();
}

}
const addButton = document.getElementById("addWidgetButton");
const menu = document.querySelector(".widgetButtonsMenu");

addButton.addEventListener("click", function() {
if (menu.style.display === "none" || menu.style.display === "") {
menu.style.display = "block";
} else {
menu.style.display = "none";
}
});

document.addEventListener("click", function(event) {
if (!menu.contains(event.target) && event.target !== addButton) {
menu.style.display = "none";
}else if(menu.contains(event.target) && event.target !== addButton){
menu.style.display = "none";
addWidget(event.target.getAttribute("data-widgetType"))
}
});

loadWidgetData();



window.electronAPI.onSavePage(() => {
for (let w of widgets){
w.saveData()
}
console.log("Saved")
});
32 changes: 32 additions & 0 deletions src/js/rePosWidgets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { widgets } from "./configureWidgets.js";

export function rePosWidgets(){
let width = window.innerWidth
let height = window.innerHeight
for (let w of widgets) {
const anchorX = w.data.anchorX;
const anchorY = w.data.anchorY;
let newXPos;
let newYPos;

// rePos x
if (anchorX[0] == "right") {
newXPos = width - parseInt(w.uniqueWidgetData.width) - parseInt(anchorX[1]);
} else if (anchorX[0] == "left") {
newXPos = parseInt(anchorX[1]);
}

// rePos y
if (anchorY[0] == "bottom") {
newYPos = height - parseInt(w.uniqueWidgetData.height) - parseInt(anchorY[1]);
} else if (anchorY[0] == "top") {
newYPos = parseInt(anchorY[1]);
}


w.data.xPos = newXPos + "px";
w.data.yPos = newYPos + "px";
w.updatePos();
}

}
13 changes: 13 additions & 0 deletions src/js/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { widgets } from "./configureWidgets.js";

window.electronAPI.onSavePage(() => {
for (let w of widgets) {
w.saveData();
}
});

addEventListener("beforeunload", (event) => {
for (let w of widgets) {
w.saveData();
}
});
2 changes: 1 addition & 1 deletion src/js/widget.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getSettingsData, getTarget, handleWidgetSettingsMenu } from "./widgetSettingsMenu.js";
import { editMode } from "./editButton.js";
import { editMode } from "./ButtonHandlers/editButton.js";

const titleHtml = `
<div class="title-bar">
Expand Down

0 comments on commit a04c488

Please sign in to comment.