From ab2a7fa1080a06695b982ed13b763db3f7d0b708 Mon Sep 17 00:00:00 2001 From: relikd Date: Fri, 21 Feb 2020 11:11:44 +0100 Subject: [PATCH] Initial --- LICENSE | 7 ++++ README.md | 8 ++++ index.html | 64 +++++++++++++++++++++++++++++ script.js | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++ style.css | 71 +++++++++++++++++++++++++++++++++ 5 files changed, 265 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 index.html create mode 100644 script.js create mode 100644 style.css diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8647a27 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2020 Oleg Geier + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..bc1593f --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Soli-WG + +Der solidarische WG Kosten Rechner. [Hier ausprobieren](https://relikd.github.io/Soli-WG/). + + +## License + +[MIT License](https://opensource.org/licenses/MIT) diff --git a/index.html b/index.html new file mode 100644 index 0000000..c82654b --- /dev/null +++ b/index.html @@ -0,0 +1,64 @@ + + + + + WG Kosten + + + + + + + + + + +

WG Kosten

+

Nachzahlung? Mietkosten ausfüllen, Zusatzkosten frei lassen.

+
+
+ + +

Kosten die nach Fläche aufgeteilt werden (z.B. Kaltmiete, Heizung)

+
+ + +

Kosten die nach Person aufgeteilt werden (z.B. Internet, Strom, Telefon)

+
+ + +

Summe aller Räume in Quadratmetern

+
+
+ +

Zimmer

+
+ +
+ + +
+
+

Solidaritätsfaktor:

+ +
+
+ + + + diff --git a/script.js b/script.js new file mode 100644 index 0000000..e9ed166 --- /dev/null +++ b/script.js @@ -0,0 +1,115 @@ +window.addEventListener('load', function() { + function replInpt(n){ + let t=getTemplate("input-template") + let x=t.firstElementChild; x.id=n.id; x.classList=n.classList + n.hasAttribute("optional") ? x.min=0 : x.required=true + t.lastElementChild.innerHTML=n.getAttribute("sign") + n.parentNode.replaceChild(t,n) + } + let x=document.getElementsByTagName("NUM") + for(var i=x.length-1;i>=0;i--) replInpt(x[i]) + readGET() + toggleOptions() + soliChanged() + $_id("rent").focus() +}) +function $_id(t){return document.getElementById(t)} +function leaveInput(n){n.value=Math.abs(Number(n.value)); update()} +function nextInput(e){ + if(e.key==="Enter"&&(e.target.value||!e.target.required)){ + if(e.target.classList.contains("add-person")) addPerson(e.target) + else focusNextInput(e.target) + } +} +function focusNextInput(n){ + if(n.id!=="qm"){ + let x=document.getElementsByTagName("INPUT") + for(var i=0;i2?v-1:1); update() +} +function addRoom(n,sz=null,ct=1,cli=false){ + let x=getTemplate("room-template"), y=x.querySelector("input") + y.value=sz; x.querySelector(".residents>i").innerHTML=ct + n.parentNode.insertBefore(x,n) + if(!cli){ update(); y.focus() } +} +function delRoom(n){n.parentNode.parentNode.removeChild(n.parentNode); update()} +function soliChanged(){ + $_id("soli-val").innerHTML=$_id("soli").value + update() +} +function toggleOptions(n) { + let x=$_id("options"), ul=x.previousElementSibling + x.className=x.className ? "" : "close" + x.style=x.className ? "display:none" : "" + ul.style="list-style-type:disclosure-"+(x.className ? "closed" : "open") +} +function getTemplate(t){return $_id(t).firstElementChild.cloneNode(true)} +function setError(t){let x=$_id("error"); x.innerHTML=t; x.hidden=!t} +function update() { + setError("") + writeGET() + let r=$_id("rooms"), + cl=r.querySelectorAll(".residents>span") + for(var i=0;ia+b,0), c=lr.reduce((a,b)=>a+b,0) + if(s>qm) return setError("Die Zimmer sind größer als die gesamte Wohnung") + let z=(shared+rent*(1-s/qm))/c + let avg=(shared+rent)/c + for(var i=0;i0?t+"="+x+"&":"")} + let x=$_id("rooms").querySelectorAll(".room") + var qr=[] + for(var i=0;ii").innerHTML) + qr.push(c>1 ? s+":"+c : s) + } + let qq=q("rent")+q("shared")+q("qm")+q("soli")+"r="+qr.join("-") + let link=$_id("shortlink") + link.href=location.pathname+"?"+qq + link.innerHTML="?"+qq + // history.replaceState(null,"", "?"+qq) +} \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..8ad299a --- /dev/null +++ b/style.css @@ -0,0 +1,71 @@ +#error{ + position:fixed; top:0; left:0; width:100%; + background:#A00; color:white; + text-align:center; + font-size:1.2em; + padding:12px; +} +body{ + max-width: 1200px; + font-family:sans-serif; + padding:20px; + background:#FFF; + color:#444; +} +#shortlink{ + color: unset; + font-size: 0.4em +} +/* Grid Layout */ +section{display:flex; flex-flow:row wrap} +section>*{ + min-height:80px; + min-width:80px; + max-width:300px; + margin:3px; + padding:1em; + background:#BCD; +} +#add-room{font-size:3em; line-height:0} +/* Residents */ +.residents>i{color:#555} +.residents>i::before{content:"("} +.residents>i::after{content:"x)"} +.residents>button{margin:2em 1em 0} +.residents>span::after{content:" €"} +.room{position:relative} +.room>button{position:absolute; top:0; right:0; scale:.75} +/* Customize Input Field */ +.inpt{display:inline-table} +.inpt>input{width:5em} +.inpt>*{ + display:table-cell; + padding:4px 6px; + border:1px solid #CCC; +} +.inpt>span{ + color:#555; + background:#EEE; + vertical-align:middle; + border-left:0; + font-size:80%; +} +#soli-val{display:inline-block; width:2.5em} +#soli-val:after{content:"%"} +#soli{width:100%; padding:0; margin:1em 0 0} +/* Customize Button */ +input:invalid{background:#FE8} +button:hover{background:#CCC} +button{ + padding:4px 6px; + border:1px solid #CCC; + background:#EEE; +} +/* Dark Mode */ +@media(prefers-color-scheme:dark){ + body{background:#000; color:#FFF} + section>*{background:#123} + button{border:1px solid #444; background:#222; color:#FFF} + button:hover{background:#444} + .residents>i{color:#BBB} +} \ No newline at end of file