Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: simple typeahead search #1335

Merged
merged 11 commits into from
Aug 9, 2024
17 changes: 17 additions & 0 deletions public/resources/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,29 @@ section {
font-size: 20px;
background: #fff;
}
.filter-details {
padding: 20px 30px;
}
.box input { /* Filter text input */
padding: 10px;
font-size: 16px;
border: 1px solid #ededed;
border-radius: 4px;
/* fill out to parent */
width: 100%;
}
.item {
background: #fff;
height: 191px;
border: 1px solid #ededed;
border-top: none;
}
.filter-item {
background: #fbfbfb;
height: 150px;
border: 1px solid #ededed;
border-top: none;
}
.item:nth-child(odd) {
background-color: #fbfbfb;
}
Expand Down
26 changes: 24 additions & 2 deletions public/templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,39 @@
el.setSelectionRange(0, el.value.length);
return false;
}

function filter() {
var filter = document.getElementById('filter').value.toLowerCase();
var items = document.getElementsByClassName('item');
for (var i = 0; i < items.length; i++) {
var item = items[i];
var dataName = item.getAttribute('data-name')?.toLowerCase() ?? '';
var dataIdentifier = item.getAttribute('data-id')?.toLowerCase() ?? '';
item.hidden = !(dataName.indexOf(filter) > -1 || dataIdentifier.indexOf(filter) > -1);
}
}
</script>
</head>
<body>
<section>
<h1 class="title {{#if is_light}}light{{/if}}"><img src="{{public_url}}images/logo.png{{&key_query}}" alt="TileServer GL" /></h1>
<h2 class="subtitle">Vector {{#if is_light}}<s>and raster</s>{{else}}and raster{{/if}} maps with GL styles</h2>
<h2 class="box-header">Filter</h2>
<!-- filter box -->
<div class="box">
<div class="filter-item">
<div class="filter-details">
<h3>Filter styles and data by name or identifier</h3>
<!-- filter input , needs to call filter() when content changes...-->
<input id="filter" type="text" oninput="filter()" placeholder="Start typing name or identifier" />
</div>
</div>
</div>
{{#if styles}}
<h2 class="box-header">Styles</h2>
<div class="box">
{{#each styles}}
<div class="item">
<div class="item" data-id="{{@key}}" data-name="{{name}}">
{{#if thumbnail}}
<img src="{{public_url}}styles/{{@key}}/{{thumbnail}}{{&../key_query}}" alt="{{name}} preview" />
{{else}}
Expand Down Expand Up @@ -70,7 +92,7 @@
<h2 class="box-header">Data</h2>
<div class="box">
{{#each data}}
<div class="item">
<div class="item" data-id="{{@key}}" data-name="{{tileJSON.name}}">
{{#if thumbnail}}
<img src="{{public_url}}data/{{@key}}/{{thumbnail}}{{&../key_query}}" alt="{{name}} preview" />
{{else}}
Expand Down
Loading