Einige Änderungen (u.a. JavaScripts in /js)
authorMalte Bublitz <malte@rolltreppe3.de>
Sun, 2 Oct 2022 19:57:42 +0000 (21:57 +0200)
committerMalte Bublitz <malte@rolltreppe3.de>
Sun, 2 Oct 2022 19:57:42 +0000 (21:57 +0200)
js/greeting.js [new file with mode: 0644]
js/main.js [new file with mode: 0644]
main.js [deleted file]
mini/greeting.js [deleted file]
mini/index.html
template.inc.php

diff --git a/js/greeting.js b/js/greeting.js
new file mode 100644 (file)
index 0000000..cb6beb8
--- /dev/null
@@ -0,0 +1,137 @@
+"use strict";
+
+var greeting = {
+       /**
+        * Configuration
+        * 
+        * Keys:
+        *   storageKey        {string}   Prefix for localStorage keys
+        *   greetingSelector  {string}   Selector for the element containing the greeting
+        *   defaultHidden     {boolean}  Hidden by default?
+        */
+       config: {
+               storageKey: "greeting",
+               greetingSelector: "header h1",
+               defaultHidden: false,
+       },
+
+       /**
+        * Current greeting
+        */
+       text: "",
+
+       /**
+        * Wether the greeting is hidden
+        */
+       hidden: false,
+       
+       /**
+        * Initialize greeting.js
+        */
+       init: function(greetingSelector = null, storageKey = null, hidden = null){
+               if (greetingSelector !== null) {
+                       greeting.config.greetingSelector = greetingSelector;
+               }
+               if (storageKey !== null) {
+                       greeting.config.storageKey = storageKey;
+               }
+               if (hidden !== null) {
+                       greeting.config.defaultHidden = hidden;
+               }
+               
+               // Read storage
+               greeting.readStorage();
+               
+               // Update/set greeting element's content
+               greeting.update();
+       },
+       
+       /**
+        * Get the HTMLElement matching config.greetingSelector
+        */
+       getElem: function() {
+               return document.querySelector(greeting.config.greetingSelector);
+       },
+       
+       /**
+        * Set greeting.text to the value in localStorage.
+        * If the storage entry did not exist, default to getElem()'s
+        * innerText
+        */
+       readStorage: function(){
+               greeting.text = localStorage.getItem(greeting.config.storageKey + "_text");
+               if (greeting.text == null) {
+                       // migrate old config
+                       greeting.text = localStorage.getItem(greeting.config.storageKey);
+                       if (greeting.text !== null) {
+                               localStorage.setItem(greeting.config.storageKey + "_text", greeting.text);
+                       } else {
+                               // No greeting stored until now
+                               greeting.text = greeting.getElem().innerText;
+                               if (greeting.text.length < 1) {
+                                       greeting.text = "hello";
+                               }
+                       }
+               }
+               
+               greeting.hidden = localStorage.getItem(greeting.config.storageKey + "_hidden");
+               if (greeting.hidden == null) {
+                       // No greeting stored until now
+                       greeting.hidden = greeting.config.defaultHidden;
+               }
+       },
+       
+       /**
+        * Set a new greeting
+        */
+       set: function(newGreeting){
+               if (newGreeting === null || newGreeting.length < 1)
+                       return false;
+               
+               greeting.text = newGreeting;
+               //localStorage.setItem(greeting.config.storageKey, greeting.text);
+               greeting.update();
+       },
+       
+       /**
+        * Update the greeting HTML element by setting it
+        * to greeting.text, and store it in localStorage
+        */
+       update: function(){
+               greeting.getElem().innerText = greeting.text;
+               localStorage.setItem(
+                       greeting.config.storageKey + "_text",
+                       greeting.text
+               );
+               localStorage.setItem(
+                       greeting.config.storageKey + "_hidden",
+                       greeting.hidden
+               );
+       },
+
+       /**
+        * Hide the greeting
+        */
+       hide: function(permanent = false){
+               console.debug('greeting.hide(): Hiding "'+greeting.config.greetingSelector+'"');
+               greeting.getElem().style.display = "none";
+               greeting.getElem().style.visibility = "hidden";
+               if (permanent === true) {
+                       greeting.hidden = true;
+                       greeting.update();
+               }
+       },
+
+       /**
+        * Un-Hide a.k.a. show the greeting
+        */
+       unHide: function(permanent = false){
+               console.debug('greeting.unHide(): Showing "'+greeting.config.greetingSelector+'"');
+               greeting.getElem().style.display = "";
+               greeting.getElem().style.visibility = "";
+               if (permanent === true) {
+                       greeting.hidden = false;
+                       greeting.update();
+               }
+       },
+};
diff --git a/js/main.js b/js/main.js
new file mode 100644 (file)
index 0000000..88b483d
--- /dev/null
@@ -0,0 +1,138 @@
+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 = '<span class="red">\\\\</span>'
+                               + this.whoami_host
+                               + '<span class="red">\\</span>'
+                               + this.whoami_user;
+                       
+               } else {
+                       user_login = this.whoami_user
+                               + '<span class="red">@</span>'
+                               + this.whoami_host;
+                       
+               }
+               
+               this.section.innerHTML = '<p>'+user_login+'</p>';
+       },
+};
+window.notepad = function(selector, storageKey) {
+    //console.log("window.notepad(\""+selector+"\", \""+storageKey+"\")")
+
+    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();
+    
+    document.querySelector(
+        "button#settings"
+    ).onclick = function() {
+        window.whoami.settings();
+        //window.whoami.update();
+    };
+    
+    window.notepad("#notepadContent", "notepad");
+
+    /**
+    * Hide footer
+    */
+    //document.getElementsByTagName("footer")[0].remove()
+};
diff --git a/main.js b/main.js
deleted file mode 100644 (file)
index e7aced2..0000000
--- a/main.js
+++ /dev/null
@@ -1,139 +0,0 @@
-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 = '<span class="red">\\\\</span>'
-                               + this.whoami_host
-                               + '<span class="red">\\</span>'
-                               + this.whoami_user;
-                       
-               } else {
-                       user_login = this.whoami_user
-                               + '<span class="red">@</span>'
-                               + this.whoami_host;
-                       
-               }
-               
-               this.section.innerHTML = '<p>'+user_login+'</p>';
-       },
-};
-window.notepad = function(selector, storageKey) {
-    //console.log("window.notepad(\""+selector+"\", \""+storageKey+"\")")
-
-    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();
-    
-    document.querySelector(
-        "button#settings"
-    ).onclick = function() {
-        window.whoami.settings();
-        //window.whoami.update();
-    };
-    
-    window.notepad("#notepadContent", "notepad");
-
-    /**
-    * Hide footer
-    */
-    //document.getElementsByTagName("footer")[0].remove()
-};
diff --git a/mini/greeting.js b/mini/greeting.js
deleted file mode 100644 (file)
index 93fb2ce..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-var greeting = {
-    config: {
-        storageKey: "greeting",
-        greetingSelector: "header h1"
-    },
-    // current greeting
-    text: "",
-    
-    /**
-     * Initialize greeting.js
-     */
-    init: function(greetingSelector = null, storageKey = null){
-        if (greetingSelector !== null) {
-            greeting.config.greetingSelector = greetingSelector;
-        }
-        if (storageKey !== null) {
-            greeting.config.storageKey = storageKey;
-        }
-        
-        // Read storage
-        greeting.readStorage();
-        
-        // Update/set greeting element's content
-        greeting.update();
-    },
-    
-    /**
-     * Get the HTMLElement matching config.greetingSelector
-     */
-    getElem: function() {
-        return document.querySelector(greeting.config.greetingSelector);
-    },
-    
-    /**
-     * Set greeting.text to the value in localStorage.
-     * If the storage entry did not exist, default to getElem()'s
-     * innerText
-     */
-    readStorage: function(){
-        greeting.text = localStorage.getItem(greeting.config.storageKey);
-        if (greeting.text == null) {
-            // No greeting stored until now
-            greeting.text = greeting.getElem().innerText;
-            if (greeting.text.length < 1) {
-                greeting.text = "hello";
-            }
-        }
-    },
-    
-    /**
-     * Set a new greeting
-     */
-    set: function(newGreeting){
-        if (newGreeting.length < 1)
-            return false;
-        
-        greeting.text = newGreeting;
-        //localStorage.setItem(greeting.config.storageKey, greeting.text);
-        greeting.update();
-    },
-    
-    /**
-     * Update the greeting HTML element by setting it
-     * to greeting.text, and store it in localStorage
-     */
-    update: function(){
-        greeting.getElem().innerText = greeting.text;
-        localStorage.setItem(
-            greeting.config.storageKey,
-            greeting.text
-        );
-    },
-};
index 3c720aa7205368aa0677524e0c788eeed63c51ed..70a34fe3914b629eae9cf6d950f8d53122879e48 100644 (file)
@@ -7,7 +7,7 @@
                
                <title>Startseite</title>
                
-               <link rel="stylesheet" type="text/css" href="../../normalize.css">
+               <link rel="stylesheet" type="text/css" href="https://xyz.malte70.de/css/normalize.min.css">
                <link rel="stylesheet" type="text/css" href="style.css">
         <link rel="icon" type="image/png" sizes="512x512" href="https://dev.malte70.de/tango-icons/img/go-home-512.png">
        </head>
@@ -26,7 +26,7 @@
                        </section>
                </main>
                
-        <script type="text/javascript" src="greeting.js"></script>
+        <script type="text/javascript" src="../js/greeting.js"></script>
                <script type="text/javascript">
                        window.onload = function() {
                                var _useragent = navigator.userAgent;
index a8d4b691687840bba5045d432376ddcca41043a2..c303e2784733ee3e664fcc8ec33e1579f1e65208 100644 (file)
@@ -118,20 +118,20 @@ foreach ($Data["Links"] as $LinkRow) {
                </main>
 <?php if ($Data["JS"]): ?>
                <footer>
-                   <p>
-                       <button type="button" id="settings">Settings&hellip;</button>
-                   </p>
+                       <p>
+                               <button type="button" id="settings">Settings&hellip;</button>
+                       </p>
                        <p>
                                &copy; <?=$Data["Footer"]["CopyrightYear"]?> <a href="<?=$Data["Footer"]["AuthorURL"]?>" rel="me nofollow"><?=$Data["Footer"]["AuthorName"]?></a>
                                &middot; <a href="https://ftp.malte70.de/pub/malte70-startseite.tar.gz" download>Download (.tar.gz)</a>
                        </p>
                </footer>
                
-               <!--<script src="main.js"></script>-->
+               <!--<script src="js/main.js"></script>-->
                <script>
-                   <?php
-                   require("main.js");
-                   ?>
+                       <?php
+                       require("js/main.js");
+                       ?>
                </script>
 <?php endif; ?>
        </body>