Improved icon search.

This commit is contained in:
William Boman 2014-10-21 01:53:52 +02:00
parent c1768c1f8a
commit f9cd96b667
2 changed files with 15 additions and 4 deletions

View File

@ -15,7 +15,7 @@
<div class="row fontawesome-icon-list">
{% for icon in icons %}
<div class="fa-hover col-md-3 col-sm-4 filter-icon"
data-filter=" {{ icon.class }}{% for alias in icon.aliases %} {{ alias }}{% endfor %}{% for filter in icon.filter %} {{ filter }}{% endfor %}">
data-filter="{{ icon.class }}{% for alias in icon.aliases %}|{{ alias }}{% endfor %}{% for filter in icon.filter %}|{{ filter }}{% endfor %}">
<a href="{{ page.relative_path }}icon/{{ icon.id }}"><i class="fa fa-{{ icon.class }}"></i> fa-{{ icon.class }}{% if icon.alias_of %} <span class="text-muted">(alias)</span>{% endif %}</a>
</div>
{% endfor %}

View File

@ -32,12 +32,12 @@ $(function() {
var resultsCount = 0;
$icons.each(function() {
var filter = $(this).attr('data-filter')
var show = filter.match(' '+val);
var filter = $(this).attr('data-filter').split('|');
var show = inFilter(val, filter);
if (!show) {
if (val.slice(-1) === 's') {
// Try to be smart. Make plural terms singular.
show = filter.match(' '+val.slice(0, -1));
show = inFilter(val.slice(0, -1), filter);
}
}
if (show) resultsCount++;
@ -53,6 +53,17 @@ $(function() {
}).trigger('keyup');
}
function inFilter(val, filter) {
var found = false;
for (var i = 0; i < filter.length; i++) {
if (filter[i].match(val)) {
found = true;
break;
}
}
return found;
}