mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
FastAPI: use internal typeahead and remove jquery
Awesome! Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
2835dd89ea
commit
3a74f76ff9
6 changed files with 20 additions and 35 deletions
|
@ -83,10 +83,7 @@ async def add_security_headers(request: Request, call_next: typing.Callable):
|
|||
# Add CSP header.
|
||||
nonce = request.user.nonce
|
||||
csp = "default-src 'self'; "
|
||||
script_hosts = [
|
||||
"ajax.googleapis.com",
|
||||
"cdn.jsdelivr.net"
|
||||
]
|
||||
script_hosts = []
|
||||
csp += f"script-src 'self' 'nonce-{nonce}' " + ' '.join(script_hosts)
|
||||
# It's fine if css is inlined.
|
||||
csp += "; style-src 'self' 'unsafe-inline'"
|
||||
|
|
|
@ -93,4 +93,14 @@
|
|||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bootstrap typeahead for the homepage. -->
|
||||
<script type="text/javascript" src="/static/js/typeahead-home.js"></script>
|
||||
|
||||
<!-- Stub inline javascript with a nonce. Used for testing purposes. -->
|
||||
<script type="text/javascript" nonce={{ request.user.nonce }}>
|
||||
function NONEXISTENT() {}
|
||||
NONEXISTENT();
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -12,5 +12,8 @@
|
|||
<link rel="alternate" type="application/rss+xml"
|
||||
title="Newest Packages RSS" href="/rss/">
|
||||
|
||||
<!-- Include local typeahead -->
|
||||
<script type="text/javascript" src="/static/js/typeahead.js"></script>
|
||||
|
||||
<title>AUR ({{ language }}) - {{ title | tr }}</title>
|
||||
</head>
|
||||
|
|
|
@ -6,6 +6,5 @@
|
|||
<body>
|
||||
{% include 'partials/navbar.html' %}
|
||||
{% extends 'partials/body.html' %}
|
||||
{% include 'partials/typeahead.html' %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="/static/js/bootstrap-typeahead.min.js"></script>
|
||||
<script type="text/javascript" nonce="{{ request.user.nonce }}">
|
||||
$(document).ready(function() {
|
||||
$('#pkgsearch-field').typeahead({
|
||||
source: function(query, callback) {
|
||||
$.getJSON('/rpc', {type: "suggest", arg: query}, function(data) {
|
||||
callback(data);
|
||||
});
|
||||
},
|
||||
matcher: function(item) { return true; },
|
||||
sorter: function(items) { return items; },
|
||||
menu: '<ul class="pkgsearch-typeahead"></ul>',
|
||||
items: 20,
|
||||
updater: function(item) {
|
||||
document.location = '/packages/' + item;
|
||||
return item;
|
||||
}
|
||||
}).attr('autocomplete', 'off');
|
||||
|
||||
$('#pkgsearch-field').keydown(function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
var selectedItem = $('ul.pkgsearch-typeahead li.active');
|
||||
if (selectedItem.length == 0) {
|
||||
$('#pkgsearch-form').submit();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
6
web/html/js/typeahead-home.js
Normal file
6
web/html/js/typeahead-home.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const input = document.getElementById('pkgsearch-field');
|
||||
const form = document.getElementById('pkgsearch-form');
|
||||
const type = 'suggest';
|
||||
typeahead.init(type, input, form);
|
||||
});
|
Loading…
Add table
Reference in a new issue