From 2f0ac6ff7396745bf2a273c45b85a302da8db1f7 Mon Sep 17 00:00:00 2001 From: Malte Bublitz Date: Mon, 3 Oct 2022 05:34:29 +0200 Subject: [PATCH] Einstellungs-Dialog --- css/dialog.css | 111 +++++++++++++++++++++++++++++ index.php | 12 +++- js/greeting.js | 2 - js/main.js | 140 +++++------------------------------- js/new-tab.js | 2 + js/notepad.js | 27 +++++++ js/settings.js | 30 ++++++++ js/whoami.js | 182 +++++++++++++++++++++++++++++++++++++++++++++++ template.inc.php | 71 +++++++++++++++--- tty/index.php | 4 +- 10 files changed, 443 insertions(+), 138 deletions(-) create mode 100644 css/dialog.css create mode 100644 js/notepad.js create mode 100644 js/settings.js create mode 100644 js/whoami.js diff --git a/css/dialog.css b/css/dialog.css new file mode 100644 index 0000000..b5b2f13 --- /dev/null +++ b/css/dialog.css @@ -0,0 +1,111 @@ +/** + * dialog.css + */ + + +/* for GnuPG key details + https://github.com/GoogleChrome/dialog-polyfill */ +dialog { + border: .1em solid #ff8000; + padding: 1em; + background: /*#2e3436*/ #444; + color: #eee; + + position: fixed; + top: 50%; + transform: translate(0, -50%); + + width: 18em; + max-width: 100%; + + height: 12em; + max-height: 100%; + + position: fixed; + + z-index: 100; + + left: 50%; + top: 50%; + + /* Use this for centering if unknown width/height */ + transform: translate(-50%, -50%); + + /* If known, negative margins are probably better (less chance of blurry text). */ + /* margin: -200px 0 0 -200px; */ + + box-shadow: 0 0 60px 10px rgba(0, 0, 0, 0.9); +} + +dialog h3 { + margin: 0 0 1.5em; +} + +dialog button.close { + position: absolute; + top: .3em; + right: .3em; + font-size: 3em; + font-family: "Source Sans Pro", sans-serif; + font-weight: 300; + border: 0; + background: none; + cursor: pointer; + color: #d3d7cf; + line-height: .75em; +} + +dialog button.close:focus { + outline: 0; +} + +dialog::backdrop { /* native */ + background-color: rgba(0, 0, 0, 0.9); +} +dialog + .backdrop { /* polyfill */ + background-color: rgba(0, 0, 0, 0.6); +} + + + +/******************************************************************** + * * + * fade-in effekt * + * * + ********************************************************************/ + +@keyframes appear { + 0% { + display: none; + opacity: 0; + } + 1% { + display: block; + opacity: 0; + transform: scale(0); + } + 100% { + opacity: 1; + transform: scale(1); + } +} + +dialog { + /* Fade on */ + visibility: visible; + opacity: 1 + /*transition: opacity 0.5s linear;*/ + animation: appear .5s ease-in-out; +} + +dialog:not([open]) { + visibility: hidden; + opacity: 0; + transition: transform .3s ease-in-out, opacity .3s ease-in-out; +} + + + +#settings_form div { + margin: 0 0 .6em; +} \ No newline at end of file diff --git a/index.php b/index.php index 03ee351..815cb46 100644 --- a/index.php +++ b/index.php @@ -20,14 +20,21 @@ $Data = Array( //"Title" => "Homepage @ ".$host, "Title" => "Homepage", "Author" => "malte70@".$host, - "Stylesheet" => "css/style.css", + //"Stylesheet" => "css/style.css", + "Stylesheets" => Array("css/style.css", "css/dialog.css"), //"Icon" => "https://xyz.malte70.de/img/icons_tango/go-home-512.png", "Icon" => "img/favicon.png", ), "Links" => NULL, "Notepad" => true, "WhoAmI" => "john_doe@pc", - "JS" => true, + "JS" => Array( + //"js/greeting.js", // + "js/whoami.js", // WhoAmI greeting (headline) + "js/notepad.js", // local notes + //"js/settings.js", + "js/main.js" // onLoad logic + ), "Search" => "Google", // Google/searX "Footer" => Array( "CopyrightYear" => date("Y"), @@ -59,4 +66,3 @@ if ($lang == "de") { require_once("template.inc.php"); -?> diff --git a/js/greeting.js b/js/greeting.js index cb6beb8..1d5af49 100644 --- a/js/greeting.js +++ b/js/greeting.js @@ -1,5 +1,3 @@ -"use strict"; - var greeting = { /** * Configuration diff --git a/js/main.js b/js/main.js index 88b483d..5ad0a46 100644 --- a/js/main.js +++ b/js/main.js @@ -1,132 +1,21 @@ -window.whoami = { - init: function() { - console.log("whoami.init()"); - if (!this.section) { - this.section = document.getElementById("whoami") - } - - this.whoami_user = localStorage.getItem("whoami_user"); - this.whoami_host = localStorage.getItem("whoami_host"); - this.whoami_format = localStorage.getItem("whoami_format"); - - if (!this.whoami_user) { - console.log("Asking for username"); - this.whoami_user = prompt("Your user name", "malte70"); - if (this.whoami_user === null) - this.whoami_user = "malte70"; - } - if (!this.whoami_host) { - console.log("Asking for hostname"); - this.whoami_host = prompt("Hostname", "localhost"); - if (this.whoami_host === null) - this.whoami_host = "pc"; - } - if (!this.whoami_format) { - console.log("Asking for format"); - this.whoami_format = prompt("Format (unix|windows)", "unix"); - if (this.whoami_format === null) - this.whoami_format = "windows"; - } - - /*var urlParams = new URLSearchParams(window.location.search); - if (!urlParams.has('user')) { - this.whoami_user = null; - } else { - this.whoami_user = urlParams.get('user'); - this.whoami_host = "PLUTO"; - }*/ - }, - deinit: function() { - localStorage.removeItem("whoami_user"); - localStorage.removeItem("whoami_host"); - localStorage.removeItem("whoami_format"); - }, - settings: function() { - console.log("whoami.settings()"); - this.whoami_user = prompt("Your user name", localStorage.getItem("whoami_user")); - this.whoami_host = prompt("Hostname", localStorage.getItem("whoami_host")); - this.whoami_format = prompt("Format (unix|windows)", localStorage.getItem("whoami_format")); - - if (this.whoami_user === null) - this.whoami_user = "malte70"; - if (this.whoami_host === null) { - if (localStorage.getItem("whoami_host") !== null) { - this.whoami_host = localStorage.getItem("whoami_host"); - } else { - this.whoami_host = "pc"; - } - } - if (this.whoami_format === null) - this.whoami_format = "windows"; - - console.table( - [ - ["whoami_user", this.whoami_user], - ["whoami_host", this.whoami_host], - ["whoami_format", this.whoami_format], - ] - ); - - this.update(); - }, - update: function() { - // Update localstorage - localStorage.setItem("whoami_user", this.whoami_user); - localStorage.setItem("whoami_host", this.whoami_host); - localStorage.setItem("whoami_format", this.whoami_format); - - if (this.whoami_format.toLowerCase() == "windows") { - if (this.whoami_user == "root" || this.whoami_user == "admin") - this.whoami_user = "Administrator"; - - if (this.whoami_host == this.whoami_host.toLowerCase() && this.whoami_host != "localhost") - this.whoami_host = this.whoami_host.toUpperCase() - - // strip domain from fqdn - this.whoami_host = this.whoami_host.substr( - 0, - this.whoami_host.indexOf(".") - ); - user_login = '\\\\' - + this.whoami_host - + '\\' - + this.whoami_user; - - } else { - user_login = this.whoami_user - + '@' - + this.whoami_host; - - } - - this.section.innerHTML = '

'+user_login+'

'; - }, -}; -window.notepad = function(selector, storageKey) { - //console.log("window.notepad(\""+selector+"\", \""+storageKey+"\")") +/** + * Main JavaScript logic + */ - elem = document.querySelector(selector); - if (localStorage.getItem(storageKey) !== null) { - console.log("window.notepad(): Loading from LocalStorage") - elem.innerHTML = localStorage.getItem("notepad"); - } - elem.addEventListener("focusout", function() { - console.log("window.notepad(): Focus lost. Storing on LocalStorage"); - localStorage.setItem(storageKey, document.querySelector(selector).innerHTML); - }); - //document.querySelector(selector).onclick = function() { - // localStorage.setItem(storageKey, document.querySelector(selector).innerHTML); - //}; -}; -window.onload = function() { - window.whoami.init(); - window.whoami.update(); +// (() => { + + +window.onload = () => { + whoami.init(); + whoami.update(); + //whoami.settings2(); document.querySelector( "button#settings" ).onclick = function() { - window.whoami.settings(); + //window.whoami.settings(); //window.whoami.update(); + whoami.settings2(); }; window.notepad("#notepadContent", "notepad"); @@ -135,4 +24,9 @@ window.onload = function() { * Hide footer */ //document.getElementsByTagName("footer")[0].remove() + + + }; + +// })(); diff --git a/js/new-tab.js b/js/new-tab.js index 59b1b6c..4085108 100644 --- a/js/new-tab.js +++ b/js/new-tab.js @@ -1,3 +1,5 @@ +"use strict"; + window.onload = function() { var _useragent = navigator.userAgent; var _lang = navigator.language.replace("-", "_"); diff --git a/js/notepad.js b/js/notepad.js new file mode 100644 index 0000000..f0a2131 --- /dev/null +++ b/js/notepad.js @@ -0,0 +1,27 @@ +/** + * Creates a notepad from an contenteditable element. + * + * Sets the element's content from localStorage, and writes + * updated content everytime a "focusout" event is raised back + * to localStorage. + * + * @param {string} selector string Selector for the