Verified Commit 2b9b4eb8 authored by Jakob Moser's avatar Jakob Moser
Browse files

Add hotkey

parent 74f98529
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -46,6 +46,21 @@ get_header();
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta name="description" content="<?php echo wp_strip_all_tags(get_the_excerpt()); ?>" />

        <script>
            addEventListener("keydown", (event) => {
                if(event.target.tagName === "INPUT" || event.target.tagName === "TEXTAREA" || event.target.contenteditable) {
                    // User typed in an input field or a text area or an arbitrary element which is editable, don't mess with that.
                    return
                }

                if(event.key === "/") {
                    const isEnglish = document.querySelector("html").lang.startsWith("en")
                    showSearchModal(isEnglish)
                    event.preventDefault()
                }
            })
        </script>

        <?php wp_head(); ?>
    </head>
    <body class="<?php echo is_admin_bar_showing() ? 'has-admin-bar' : '';?>">
@@ -53,6 +68,15 @@ get_header();
            <form method="get" action="/">
                <input type="search" name="s" placeholder="Suchen..."><button>🔍</button>
            </form>
            <script>
                function showSearchModal(isEnglish) {
                    const searchModal = document.querySelector("#search-modal")
                    searchModal.querySelector("form").action = isEnglish ? "/en/" : "/"
                    searchModal.querySelector("input[type='search']").placeholder = isEnglish ? "Search..." : "Suchen..."

                    searchModal.showModal()
                }
            </script>
        </dialog>
        <header>
            <div>
@@ -64,12 +88,7 @@ get_header();
                <script>
                    document.querySelector("[lang*='en'] a[href$='/en/search/'], [lang*='de'] a[href$='/suchen/']").addEventListener("click", (event) => {
                        const isEnglish = event.target.href.includes("/en/")
                        const searchModal = document.querySelector("#search-modal")

                        searchModal.querySelector("form").action = isEnglish ? "/en/" : "/"
                        searchModal.querySelector("input[type='search']").placeholder = isEnglish ? "Search..." : "Suchen..."

                        searchModal.showModal()
                        showSearchModal(isEnglish)                        
                        event.preventDefault()
                    })
                </script>
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
 * Author: personads :: Maximilian Müller-Eberstein (ursprüngliche Version und Design); Jakob Moser
 * Author URI: https://personads.me/
 *
 * Version: 2.17.2
 * Version: 2.17.3-alpha
 * Requires PHP: 8.0
 *
 * License: GNU General Public License v3.0