|
@@ -1,177 +0,0 @@
|
|
|
-<!DOCTYPE html>
|
|
|
-<html>
|
|
|
-<head>
|
|
|
-<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
-<style>
|
|
|
-#wrapper{
|
|
|
- width: 30%;
|
|
|
- max-height: 80vh;
|
|
|
- overflow: hidden;
|
|
|
-}
|
|
|
-.person {
|
|
|
- background-color: #ddd;
|
|
|
- color: #444;
|
|
|
- cursor: pointer;
|
|
|
- padding: 18px;
|
|
|
- width: 100%;
|
|
|
- border: none;
|
|
|
- text-align: left;
|
|
|
- outline: none;
|
|
|
- font-size: 15px;
|
|
|
- transition: 0.4s;
|
|
|
-}
|
|
|
-
|
|
|
-#offline .person{
|
|
|
- background-color: #eee;
|
|
|
-}
|
|
|
-
|
|
|
-#offline .person:hover, #online .person:hover {
|
|
|
- background-color: #bbb;
|
|
|
-}
|
|
|
-
|
|
|
-.extend {
|
|
|
- padding: 0 18px;
|
|
|
- display: none;
|
|
|
- overflow: hidden;
|
|
|
-}
|
|
|
-
|
|
|
-img{
|
|
|
- width: 90px;
|
|
|
- float: left;
|
|
|
- margin-right: 20px;
|
|
|
- margin-top: 10px;
|
|
|
-}
|
|
|
-</style>
|
|
|
-<script>
|
|
|
-
|
|
|
-</script>
|
|
|
-</head>
|
|
|
-<body>
|
|
|
-
|
|
|
-<h2>Tabelle</h2>
|
|
|
-
|
|
|
-<div id="wrapper">
|
|
|
- <div id="online">
|
|
|
- </div>
|
|
|
- <p></p>
|
|
|
- <div id="offline">
|
|
|
- </div>
|
|
|
-</div>
|
|
|
-
|
|
|
-<button onclick="sortDivs()">Sort</button>
|
|
|
-<button onclick="changeStatus()">Status</button>
|
|
|
-
|
|
|
-
|
|
|
-<script>
|
|
|
-//TODO: external script
|
|
|
-
|
|
|
-// global array of objects
|
|
|
-var persons = [
|
|
|
- {name: "Martin", fullName: "Martin Venzl", status: "online", speed: 2},
|
|
|
- {name: "Simon", fullName: "Simon Ellinger", status: "online", speed: 4},
|
|
|
- {name: "Lukas", fullName: "Lukas Wagner", status: "online", speed: 1},
|
|
|
- {name: "Bernie", fullName: "Bernadette Hammerle", status: "online", speed: 3},
|
|
|
-
|
|
|
- {name: "tester1", fullName: "Testperson 1", status: "online", speed: 0},
|
|
|
- {name: "tester2", fullName: "Testperson 2", status: "offline", speed: 6}
|
|
|
-];
|
|
|
-
|
|
|
-// create div for every person in persons array
|
|
|
-function createDivs(){
|
|
|
- for (person of persons) {
|
|
|
- div = document.createElement('div');
|
|
|
- div.className = "person";
|
|
|
- div.id = person.name;
|
|
|
- div.setAttribute("data-status", person.status);
|
|
|
- pushPersonToDiv(div);
|
|
|
- updateDivContent(person);
|
|
|
-
|
|
|
- // add event listener to extend every person div
|
|
|
- div.addEventListener("click", function(event) {
|
|
|
- this.classList.toggle("active");
|
|
|
- var targetElement = event.target || event.srcElement;
|
|
|
- var extend = targetElement.children[0];
|
|
|
- if (extend.style.display === "block") {
|
|
|
- extend.style.display = "none";
|
|
|
- } else {
|
|
|
- extend.style.display = "block";
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-createDivs();
|
|
|
-
|
|
|
-
|
|
|
-// update the content inside the div of one person
|
|
|
-// TODO: only execute if something has changed
|
|
|
-function updateDivContent(person){
|
|
|
- var id = person.name;
|
|
|
- var div = document.getElementById(id);
|
|
|
- div.dataset.status = person.status;
|
|
|
- if (person.status=="online") {
|
|
|
- div.innerHTML = person.name +
|
|
|
- " (" + person.speed + " - " + person.status + ")" +
|
|
|
- "<div class=\'extend\'>" +
|
|
|
- "<img src=\'foto.png\'/>" +
|
|
|
- "<p>" + person.fullName + "</p>" +
|
|
|
- "<p>Geschwindigkeit: " + person.speed + "</p>" +
|
|
|
- "<p>Status: " + person.status + "</p>" +
|
|
|
- "</div>";
|
|
|
- }else{
|
|
|
- div.innerHTML = person.name +
|
|
|
- " (" + person.status + ")" +
|
|
|
- "<div class=\'extend\'>" +
|
|
|
- "<img src=\'foto.png\'/>" +
|
|
|
- "<p>" + person.fullName + "</p>" +
|
|
|
- "<p>Geschwindigkeit: " + person.speed + "</p>" +
|
|
|
- "<p>Status: " + person.status + "</p>" +
|
|
|
- "</div>";
|
|
|
- }
|
|
|
- pushPersonToDiv(div);
|
|
|
-}
|
|
|
-
|
|
|
-// convert nodes to array
|
|
|
-//function getPersonArray(){
|
|
|
-// var nodes = document.getElementsByClassName("person");
|
|
|
-// var personArray = [];
|
|
|
-// for (node of nodes) {
|
|
|
-// personArray.push(node);
|
|
|
-// }
|
|
|
-// return personArray;
|
|
|
-//}
|
|
|
-
|
|
|
-// put every person in the right div (online or offline)
|
|
|
-function pushPersonToDiv(personDiv){
|
|
|
- if (personDiv.dataset.status=="online"){
|
|
|
- document.getElementById("online").appendChild(personDiv);
|
|
|
- }else{
|
|
|
- document.getElementById("offline").appendChild(personDiv);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// change the status from every person
|
|
|
-// TODO: check if status changed in intervall
|
|
|
-function changeStatus(){
|
|
|
- for (person of persons) {
|
|
|
- if (person.status=="online"){
|
|
|
- person.status = "offline";
|
|
|
- updateDivContent(person);
|
|
|
- }else{
|
|
|
- person.status = "online";
|
|
|
- updateDivContent(person);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// comparing the speed
|
|
|
-// TODO: get speed from ?
|
|
|
-function sortDivs(){
|
|
|
- persons.sort(function(a, b){return b.speed - a.speed});
|
|
|
- persons.forEach(updateDivContent);
|
|
|
-}
|
|
|
-
|
|
|
-</script>
|
|
|
-
|
|
|
-</body>
|
|
|
-</html>
|