Skip to content

Commit 13cb1e4

Browse files
committed
added makeshift filter function
1 parent a905e13 commit 13cb1e4

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

.code/templates/index.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<header>
1111
<h1>I-ADOPT Variable Examples</h1>
1212
<p>Your resource for modelled I-ADOPT variables with concepts from different terminologies.</p>
13+
14+
<input type="text" placeholder="Filter Variables ..." id="filter" autocomplete="off" />
15+
<script src="./script.js"></script>
1316
</header>
1417

1518
<main>

.code/templates/script.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(function(){
2+
3+
// schedule update of filter
4+
let filterTimer = null;
5+
document.querySelector( '#filter' )
6+
?.addEventListener( 'input', () => {
7+
if ( filterTimer ) {
8+
clearTimeout( filterTimer );
9+
}
10+
filterTimer = setTimeout( triggerFilter, 200 );
11+
} );
12+
13+
14+
function triggerFilter() {
15+
16+
// get filter term
17+
const term = document.querySelector( '#filter' )?.value || null;
18+
19+
for( const entry of document.querySelectorAll( '.variable-item') ) {
20+
21+
if( term ) {
22+
23+
// only show, if filter term is included
24+
if( ! entry.textContent?.includes( term ) ) {
25+
entry.classList.add( 'hidden' );
26+
} else {
27+
entry.classList.remove( 'hidden' );
28+
}
29+
30+
} else {
31+
32+
// if no filter term is set, show all entries
33+
entry.classList.remove( 'hidden' );
34+
35+
}
36+
}
37+
}
38+
39+
})();

.code/templates/styles.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ body {
2929
color: #333;
3030
line-height: 1.6;
3131
display: grid;
32-
grid-template-rows: 170px calc( 100% - 230px ) 60px;
32+
grid-template-rows: 190px calc( 100% - 250px ) 60px;
3333
grid-template-areas: "top" "center" "bottom";
3434
}
3535

@@ -107,3 +107,11 @@ footer {
107107
width: 80vw;
108108
height: 50vh;
109109
}
110+
111+
#filter {
112+
width: 20em;
113+
max-width: 80%;
114+
}
115+
.hidden {
116+
display: none;
117+
}

0 commit comments

Comments
 (0)