Skip to content

Commit

Permalink
Add basic in-page filter
Browse files Browse the repository at this point in the history
Fixes #52.
  • Loading branch information
wlonk committed Nov 16, 2017
1 parent a6b32ea commit 1e8b1a5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions assets/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,28 @@ window.Herman = (function base(Herman, $) {
$(window).on('resize', fitIframesToContent);
};

function filterSiblings(selector, filter) {
$(`${selector} ~ section`).each((idx, node) => {
if (filter !== '') {
if (node.id.includes(filter)) {
$(node).show();
} else {
$(node).hide();
}
} else {
$(node).show();
}
});
}
Herman.initializePageFilters = function initializePageFilters() {
$('#page-filter').submit(function(event) {
event.preventDefault();
return false;
});
$('#page-filter input').keyup(function() {
filterSiblings('#page-filter', $('#page-filter input').val());
});
};

return Herman;
})(window.Herman || {}, window.jQuery);
1 change: 1 addition & 0 deletions assets/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ window.Herman = (function init(Herman, $) {
Herman.initializeToggles();
Herman.initializeTabs();
Herman.initializeIframes();
Herman.initializePageFilters();
});

return Herman;
Expand Down
5 changes: 5 additions & 0 deletions templates/filter_form.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% import 'utility.macros.j2' as utility %}

<form id="page-filter">
<input placeholder="filter">
</form>
1 change: 1 addition & 0 deletions templates/group.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{% endblock %}

{% block main %}
{% include 'filter_form.j2' %}
{% for item in items %}
{% set type = item.context.type %}
{% include 'item/_item.j2' %}
Expand Down

0 comments on commit 1e8b1a5

Please sign in to comment.