Skip to content

Commit f1b2543

Browse files
committed
Added asset search field
1 parent ac66547 commit f1b2543

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

_includes/asset.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{%- assign thumb_base = "" -%}
1010
{%- assign thumb = "/images/asset-nothumb.jpg" -%}
1111
{%- endif -%}
12-
<div class='asset clickable left light-text compact {{ asset.tags | join: "%%" | replace: " ", "" | split: "%%" | join: " " | downcase }}'>
12+
<div class='asset clickable left light-text compact {{ asset.tags | join: "%%" | replace: " ", "" | split: "%%" | join: " " | downcase }}' data-name="{{ asset.name }}" data-description="{{ asset.description }}">
1313
<a href="/assets/{{ include.id }}">
1414
<div id="image" style="background: url('{{thumb_base}}{{ thumb }}') center/cover; padding: 0; margin: 0; height: 190px">
1515
</div>

_includes/assetgrid.html

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
<div class="row">
44
<h4>{{ include.title }}</h4>
5+
6+
<input id="search" class="assetsearch" type="text" placeholder="Type to filter..."/>
7+
<script type="text/javascript">
8+
const search = document.getElementById('search');
9+
const inputHandler = function(e) {
10+
const assets = document.getElementsByClassName("asset");
11+
const searchFor = e.target.value.toLowerCase();
12+
for (var i = 0; i < assets.length; i++) {
13+
const asset = assets[i];
14+
const name = asset.dataset.name.toString().toLowerCase();
15+
const description = asset.dataset.description.toString().toLowerCase();
16+
const visible = (searchFor == "" || name.indexOf(searchFor) != -1 || description.indexOf(searchFor) != -1);
17+
asset.style.display = visible ? "block" : "none";
18+
};
19+
}
20+
search.addEventListener('input', inputHandler);
21+
search.addEventListener('propertychange', inputHandler); // for IE8
22+
</script>
23+
524
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); grid-gap: 2rem; padding: 0px;">
625
{%- for id in assetids -%}
726
{% include asset.html id=id %}

_includes/tagfilter.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="row compact" style="margin-bottom: 30px">
22
{%- assign alltags = site.data.assetindex | map: "tags" -%}
33
{%- assign tags = alltags | uniq | sort -%}
4-
<p>FILTER</p>
4+
<p>TAGS</p>
55
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); grid-gap: 0 1rem; font-size: 0.9em;">
66
{%- if include.tag -%}
77
{%- assign class="" -%}
@@ -20,6 +20,7 @@
2020
<a class="filter {{ class }}" href="/tags/{{ include.sort }}/{{ tag | replace: ' ' | downcase }}">{{ tag }} ({{ tagged_assets.size }})</a>
2121
{%- endfor -%}
2222
</div>
23+
2324
<br/>
2425
{%- if include.tag -%}
2526
<p>SORT BY: <a href="/tags/stars/{{ include.tag }}">Stars</a>, <a href="/tags/timestamp/{{ include.tag }}">Latest</a></p>

_layouts/assetportal.html

+10-4
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@ <h1>Asset portal</h1>
1616
{% include secondary_button.html link="/submit_asset" text="Submit asset" %}
1717
</div>
1818
</div>
19+
1920
{%- assign sort_order = page.sort | default: "stars" -%}
2021
{%- if page.tag -%}
2122
{%- assign tag = site.data.tags[page.tag] -%}
2223
{%- assign tagid = tag.id -%}
24+
{%- include tagfilter.html tag=tagid sort=sort_order -%}
25+
{%- else -%}
26+
{%- include tagfilter.html sort=sort_order -%}
27+
{%- endif -%}
28+
29+
{%- assign sort_order = page.sort | default: "stars" -%}
30+
{%- if page.tag -%}
31+
{%- assign tag = site.data.tags[page.tag] -%}
2332
{%- assign assetname = tag.name -%}
2433
{%- assign assetids = tag.assets | sort: sort_order | reverse | map: "id" -%}
25-
26-
{%- include tagfilter.html tag=tagid sort=sort_order -%}
2734
{%- include assetgrid.html assetids=assetids showfilter=true title=assetname -%}
2835
{%- else -%}
2936
{%- assign assetids = site.data.assetindex | sort: sort_order | reverse | map: "id" -%}
30-
31-
{%- include tagfilter.html sort=sort_order -%}
3237
{%- include assetgrid.html assetids=assetids showfilter=true title="All" -%}
3338
{%- endif -%}
39+
3440
<div class="row" style="margin-top: 30px">
3541
<div class="columns ten"><br/></div>
3642
<div class="columns two">{% include secondary_button.html link="/submit_asset" text="Submit asset" %}</div>

css/defold.scss

+15
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,21 @@ input[type="submit"]:hover {
542542
border-color: var(--lightest) !important;
543543
}
544544

545+
/*******************************************************************************
546+
* Text input styling
547+
******************************************************************************/
548+
549+
input[type=text].assetsearch {
550+
color: var(--lighter) !important;
551+
background-color: transparent !important;
552+
border-top: none !important;
553+
border-left: none !important;
554+
border-right: none !important;
555+
border-bottom: 1px solid var(--lighter);
556+
line-height: 80%;
557+
padding: 0px;
558+
}
559+
545560
/*******************************************************************************
546561
* Limit width of images in examples, manuals and tutorials.
547562
* Also center them

0 commit comments

Comments
 (0)