1
1
@using Humanizer
2
+ @using Microsoft .Extensions .Configuration
3
+ @inject IConfiguration Configuration
4
+
2
5
@{
3
6
var searchModes = Enum .GetValues (typeof (Shared .SearchMode )).Cast <Shared .SearchMode >().ToList ();
4
7
<div class =" search-bar" >
5
8
<div class =" d-flex ms-auto" >
6
- <input type =" text" class =" form-control" placeholder =" Search for a replay..." onsubmit =" search()" aria-label =" Search" >
9
+ <input
10
+ type =" text"
11
+ class =" form-control"
12
+ placeholder =" Search for a replay..."
13
+ onsubmit =" search()"
14
+ aria-label =" Search"
15
+ data-filter =" @Configuration[" ApiUrl " ]api/Data/username-completion?username=#QUERY#"
16
+ id =" search"
17
+ >
7
18
<button class =" btn-secondary btn dropdown-toggle" type =" button" id =" searchModeButton" style =" margin-left : 1rem ; margin-right : 1rem ;" data-bs-toggle =" dropdown" aria-expanded =" false" >
8
19
@Shared.SearchMode.PlayerOocName.Humanize()
9
20
</button >
10
- <ul class =" dropdown-menu" >
21
+ <ul class =" dropdown-menu no-affect " >
11
22
@foreach ( var mode in searchModes )
12
23
{
13
24
<li ><a class =" dropdown-item" >@mode.Humanize() </a ></li >
18
29
</div >
19
30
}
20
31
32
+ <style >
33
+ /* this is a bit stupid
34
+ so. the autocomplete plugin uses a div dropdown right? but that dropdown is placed directly ON the input,
35
+ we want to move it down, but dont want to move the no-affect dropdown, so we move EVERY dropdown down, but not the no-affect one
36
+ */
37
+ .dropdown-menu {
38
+ margin-top : 2.5rem ;
39
+ }
40
+
41
+ .no-affect {
42
+ margin-top : 0 ;
43
+ }
44
+ </style >
45
+
21
46
<script >
22
47
// This is a script to make the dropdown change the text of the button
23
48
const dropdowns = document .querySelectorAll (' .dropdown-menu a' );
50
75
51
76
// Set the value of the search input to the value of the query
52
77
document .querySelector (' .search-bar input' ).value = new URLSearchParams (window .location .search ).get (' query' );
78
+
79
+ document .addEventListener (' DOMContentLoaded' , e => {
80
+ $ (' #search' ).autocomplete ({
81
+ onItemRendered (el , item ) {
82
+ const currentSelectedSearchMode = document .getElementById (' searchModeButton' ).textContent ;
83
+ if (currentSelectedSearchMode !== " @Shared.SearchMode.PlayerOocName.Humanize()" ) {
84
+ // Currently, autocomplete only supports searching for player names. So delete the item
85
+ item .remove ();
86
+ }
87
+ }
88
+ })
89
+ }, false );
53
90
</script >
0 commit comments