initial version
This commit is contained in:
60
src/client/js/PresentsHandler.ts
Normal file
60
src/client/js/PresentsHandler.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
export class PresentsHandler {
|
||||
presents: {
|
||||
isBought: boolean,
|
||||
image: string,
|
||||
name: string,
|
||||
description: string
|
||||
link: string
|
||||
}[] = [];
|
||||
|
||||
async loadPresents() {
|
||||
this.presents = require("./presents").default;
|
||||
await this.updateStates();
|
||||
}
|
||||
|
||||
async updateStates() {
|
||||
//TODO vom server laden
|
||||
this.presents[3].isBought = true;
|
||||
}
|
||||
|
||||
async showPresents() {
|
||||
const presentContainer = document.getElementById("present-container");
|
||||
const presentTemplate = document.getElementById("present-template");
|
||||
presentTemplate.remove();
|
||||
presentTemplate.removeAttribute("id");
|
||||
|
||||
await this.loadPresents();
|
||||
|
||||
presentContainer.innerText = "";
|
||||
console.log(this.presents);
|
||||
this.presents.forEach(present => {
|
||||
const element = <HTMLLinkElement>presentTemplate.cloneNode(true);
|
||||
(<HTMLImageElement>element.querySelector(".present-image")).src = present.image;
|
||||
(<HTMLElement>element.querySelector(".present-name")).innerText = present.name;
|
||||
(<HTMLElement>element.querySelector(".present-description")).innerText = present.description;
|
||||
element.href = present.link;
|
||||
|
||||
const checkboxElement = element.querySelector(".present-checkbox");
|
||||
if (present.isBought) {
|
||||
checkboxElement.classList.add("checked");
|
||||
}
|
||||
|
||||
checkboxElement.addEventListener("click", async e => {
|
||||
e.preventDefault();
|
||||
await this.setPresentIsBought(present, !present.isBought);
|
||||
if (present.isBought) {
|
||||
checkboxElement.classList.add("checked");
|
||||
} else {
|
||||
checkboxElement.classList.remove("checked");
|
||||
}
|
||||
})
|
||||
|
||||
presentContainer.appendChild(element);
|
||||
})
|
||||
}
|
||||
|
||||
private async setPresentIsBought(present: { isBought: boolean; image: string; name: string; description: string; link: string }, isBought: boolean) {
|
||||
//TODO auf Server updaten
|
||||
present.isBought = isBought;
|
||||
}
|
||||
}
|
||||
63
src/client/js/index.ts
Normal file
63
src/client/js/index.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import * as $ from "jquery";
|
||||
import "foundation-sites/dist/js/foundation.es6";
|
||||
import {PresentsHandler} from "./PresentsHandler";
|
||||
|
||||
const templates = {
|
||||
home: require("../html/home.html"),
|
||||
unterkunft: require("../html/unterkunft.html"),
|
||||
tagesablauf: require("../html/tagesablauf.html"),
|
||||
geschenke: require("../html/geschenke.html"),
|
||||
}
|
||||
|
||||
async function startPresents(){
|
||||
await new PresentsHandler().showPresents();
|
||||
}
|
||||
|
||||
const callbacks = {
|
||||
home: () => {},
|
||||
unterkunft: () => {},
|
||||
tagesablauf: () => {},
|
||||
geschenke: startPresents,
|
||||
}
|
||||
|
||||
$(document).foundation();
|
||||
|
||||
$(function () {
|
||||
const mainDiv = document.getElementById("main-content-container");
|
||||
const container = document.getElementById("main-content");
|
||||
const img = document.getElementById("home-img-container");
|
||||
|
||||
let currentSite = "home";
|
||||
|
||||
//Scroll-Element
|
||||
mainDiv.addEventListener("scroll", e => {
|
||||
console.log("scrolling!", e);
|
||||
});
|
||||
|
||||
|
||||
//Navigation
|
||||
container.innerHTML = templates.home;
|
||||
document.querySelectorAll(".menu li[data-site]").forEach((elem: HTMLElement) => {
|
||||
elem.addEventListener("click", () => {
|
||||
const oldActive = document.querySelector(".menu .active");
|
||||
if (oldActive){
|
||||
oldActive.classList.remove("active");
|
||||
}
|
||||
elem.classList.add("active");
|
||||
|
||||
container.innerHTML = templates[elem.dataset["site"]];
|
||||
if (elem.dataset["img"] === "1"){
|
||||
img.classList.remove("hidden");
|
||||
}
|
||||
else {
|
||||
img.classList.add("hidden");
|
||||
}
|
||||
|
||||
currentSite = elem.dataset["site"];
|
||||
|
||||
if (typeof callbacks[currentSite] === "function"){
|
||||
callbacks[currentSite]();
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
49
src/client/js/presents.ts
Normal file
49
src/client/js/presents.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
export default [{
|
||||
isBought: false,
|
||||
image: require("../img/geschenke/test.jpg").default,
|
||||
name: "Akku-Bohrer",
|
||||
description: "Der von BOSCH, weil ich den schon immer mal haben wollte",
|
||||
link: "http://www.onlinewahn.de/ende.htm",
|
||||
}, {
|
||||
isBought: true,
|
||||
image: require("../img/geschenke/test.jpg").default,
|
||||
name: "Windows",
|
||||
description: "Bisher konnte ich es mir nicht leisten und musste immer auf eine Web-Version zurückgreifen",
|
||||
link: "https://www.windows93.net/",
|
||||
},{
|
||||
isBought: false,
|
||||
image: require("../img/geschenke/test.jpg").default,
|
||||
name: "Akku-Bohrer",
|
||||
description: "Der von BOSCH, weil ich den schon immer mal haben wollte",
|
||||
link: "http://www.onlinewahn.de/ende.htm",
|
||||
}, {
|
||||
isBought: false,
|
||||
image: require("../img/geschenke/test.jpg").default,
|
||||
name: "Windows",
|
||||
description: "Bisher konnte ich es mir nicht leisten und musste immer auf eine Web-Version zurückgreifen",
|
||||
link: "https://www.windows93.net/",
|
||||
},{
|
||||
isBought: false,
|
||||
image: require("../img/geschenke/test.jpg").default,
|
||||
name: "Akku-Bohrer",
|
||||
description: "Der von BOSCH, weil ich den schon immer mal haben wollte",
|
||||
link: "http://www.onlinewahn.de/ende.htm",
|
||||
}, {
|
||||
isBought: false,
|
||||
image: require("../img/geschenke/test.jpg").default,
|
||||
name: "Windows",
|
||||
description: "Bisher konnte ich es mir nicht leisten und musste immer auf eine Web-Version zurückgreifen",
|
||||
link: "https://www.windows93.net/",
|
||||
},{
|
||||
isBought: false,
|
||||
image: require("../img/geschenke/test.jpg").default,
|
||||
name: "Akku-Bohrer",
|
||||
description: "Der von BOSCH, weil ich den schon immer mal haben wollte",
|
||||
link: "http://www.onlinewahn.de/ende.htm",
|
||||
}, {
|
||||
isBought: false,
|
||||
image: require("../img/geschenke/test.jpg").default,
|
||||
name: "Windows",
|
||||
description: "Bisher konnte ich es mir nicht leisten und musste immer auf eine Web-Version zurückgreifen",
|
||||
link: "https://www.windows93.net/",
|
||||
},]
|
||||
Reference in New Issue
Block a user