Skip to content

Commit

Permalink
added icon and hotkey for the searchbar: /. (Closes #93)
Browse files Browse the repository at this point in the history
  • Loading branch information
redimp committed Mar 13, 2024
1 parent 0fa0f05 commit daf9f4a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
22 changes: 21 additions & 1 deletion otterwiki/static/css/otterwiki.css
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,24 @@ mark {
.dark-mode .spoiler > .spoiler-button {
color: #9e9e9e;
background-color: rgba(255, 255, 255, 0.2);
}
}

.top-search {
display: flex;
position: relative;
}

.top-search::after {
top: .5rem;
right: 1rem;
position: absolute;
content: "/";
padding: .2rem .8rem;
border: solid 1px rgba(128,128,128,.4);
border-radius: .4rem;
color: rgba(128,128,128,.4);
font-size: 1.3rem;
line-height: 1.5rem;
height: 2.2rem;
width: 2.2rem;
}
14 changes: 14 additions & 0 deletions otterwiki/static/js/otterwiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,17 @@ var MathJax = {
}
};

/* Hot Keys */
window.addEventListener("keypress", function() {
var isInputElement = event.srcElement instanceof HTMLInputElement;
var isTextAreaElement = event.srcElement instanceof HTMLTextAreaElement;

if(isInputElement || isTextAreaElement) {
return;
}

if (document.getElementById("search-query") != null && event.key === '/') {
document.getElementById("search-query").focus();
event.preventDefault();
}
});
8 changes: 5 additions & 3 deletions otterwiki/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
{% block navbarmain %}
<!-- Navbar start -->
<nav class="navbar">
<div class="navbar-content">
<div class="navbar-content relative">
<button id="toggle-sidebar-btn" class="btn btn-action" type="button" onclick="halfmoon.toggleSidebar()">
<i class="fas fa-bars"></i>
</button>
Expand All @@ -89,8 +89,10 @@
{% endblock %}
<div class="navbar-content ml-auto">
{% block navbarsearch %}
<form action="{{ url_for("search") }}" method="post">
<input name="query" type="text" class="form-control mr-5" placeholder="Search">
<form action="{{ url_for("search") }}" method="post" class="relative">
<span class="top-search">
<input id="search-query" name="query" type="text" class="form-control mr-5" placeholder="Search" style="padding-right: 3.5rem;">
</span>
</form>
{% endblock %}
{% block navbardropdown_outer %}
Expand Down
5 changes: 4 additions & 1 deletion otterwiki/templates/search.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{# vim: set et ts=8 sts=4 sw=4 ai: #}
{% extends "wiki.html" %}
{% block navbarsearch %}
{# don't display two searchbars #}
{% endblock %}
{% block content %}
<div class="w-600 mw-full">
<div class="card">
<h2 class="card-title">Search</h2>
<form action="{{url_for("search")}}" method="POST" class="form-inline">
<div class="form-group">
<input type="text" class="form-control" name="query" id="query" placeholder="Search term" value="{{query if query}}" autofocus>
<input type="text" class="form-control" name="query" id="search-query" placeholder="Search term" value="{{query if query}}" autofocus onfocus="this.setSelectionRange(this.value.length,this.value.length);">
</div>
{#
<div class="form-group">
Expand Down

0 comments on commit daf9f4a

Please sign in to comment.