Skip to content

Commit

Permalink
feature #274 Highlight search terms in the search results listing (ja…
Browse files Browse the repository at this point in the history
…viereguiluz)

This PR was squashed before being merged into the master branch (closes #274).

Discussion
----------

Highlight search terms in the search results listing

It highlights simple words:

![simple_word](https://cloud.githubusercontent.com/assets/73419/7494094/027856b2-f406-11e4-8968-885090a42b44.png)

Multiple words:

![multiple_words](https://cloud.githubusercontent.com/assets/73419/7494098/062ab386-f406-11e4-9371-47950b301fb9.png)

Exact phrases:

![exact_phrases](https://cloud.githubusercontent.com/assets/73419/7494101/09a18418-f406-11e4-8fd0-6a23eb09f20e.png)

And partial phrases:

![partial_phrases](https://cloud.githubusercontent.com/assets/73419/7494105/0d8f1626-f406-11e4-9f81-6bed6eddc963.png)

Commits
-------

4f2ce95 Highlight search terms in the search results listing
  • Loading branch information
javiereguiluz committed May 6, 2015
2 parents 23c89cb + 4f2ce95 commit 626a2fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Resources/public/javascript/jquery.highlight.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Resources/views/css/admin.css.twig
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,17 @@ body.list table tbody td.image img {
max-width: 150px;
}

body.list .table tbody span.highlight {
background: #FFFF99;
border-radius: 2px;
padding: 1px;
}
body.list .table tbody .no-results span.highlight,
body.list .table tbody .actions span.highlight {
background: 0;
border-radius: 0;
}

body.list .pagination {
float: right;
margin: 0;
Expand Down
12 changes: 11 additions & 1 deletion Resources/views/default/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
</tr>
{% else %}
<tr>
<td colspan="{{ _list_item_actions|length > 0 ? fields|length + 1 : fields|length }}">
<td class="no-results" colspan="{{ _list_item_actions|length > 0 ? fields|length + 1 : fields|length }}">
{{ 'search.no_results'|trans(_trans_parameters) }}
</td>
</tr>
Expand Down Expand Up @@ -202,4 +202,14 @@
});
});
</script>

{% if 'search' == app.request.get('action') %}
<script src="{{ asset('bundles/easyadmin/javascript/jquery.highlight.min.js') }}"></script>

<script type="text/javascript">
var _search_query = "{{ app.request.get('query')|default('')|e('js') }}";
// the original query is prepended to allow matching exact phrases in addition to single words
$('#main table tbody').highlight($.merge([_search_query], _search_query.split(' ')));
</script>
{% endif %}
{% endblock %}

0 comments on commit 626a2fb

Please sign in to comment.