Skip to content

Node.js based forum software built for the modern web

highlight search results

Baris Soner Usakli056171001602
diff --git a/public/css/style.less b/public/css/style.less
index a60ba220b3..5a44a064b0 100644
--- a/public/css/style.less
+++ b/public/css/style.less
@@ -832,7 +832,6 @@ body .navbar .nodebb-inline-block {
.search-result-post {
width: 100%;
- height: 50px;
line-height: 16px;
padding: 5px;
overflow:hidden;
@@ -843,7 +842,5 @@ body .navbar .nodebb-inline-block {
height:48px;
padding-right:10px;
}
- span {
- padding-left:10px;
- }
+
}
\ No newline at end of file
diff --git a/public/src/forum/search.js b/public/src/forum/search.js
new file mode 100644
index 0000000000..9412915cc7
--- /dev/null
+++ b/public/src/forum/search.js
@@ -0,0 +1,14 @@
+(function() {
+
+ $(document).ready(function() {
+ var searchQuery = $('#topics-container').attr('data-search-query');
+
+ $('.search-result-text').each(function(){
+ var text = $(this).html();
+ var regex = new RegExp(searchQuery, 'gi');
+ text = text.replace(regex, '<span class="label label-success">'+searchQuery+'</span>');
+ $(this).html(text);
+ });
+ });
+
+})();
\ No newline at end of file
diff --git a/public/templates/search.tpl b/public/templates/search.tpl
index 19a369600f..c08f82e7c5 100644
--- a/public/templates/search.tpl
+++ b/public/templates/search.tpl
@@ -12,7 +12,7 @@
<div class="category row">
<div class="span12">
- <ul id="topics-container">
+ <ul id="topics-container" data-search-query="{search_query}">
<!-- BEGIN posts -->
<a href="../../topic/{posts.topicSlug}#{posts.pid}" id="tid-{posts.tid}">
<li class="category-item">
@@ -20,7 +20,7 @@
<div class="span12 img-polaroid">
<div class="search-result-post">
<img src="{posts.picture}" />
- <strong>{posts.username}</strong>: {posts.content}
+ <strong>{posts.username}</strong>: <span class="search-result-text">{posts.content}</span>
</div>
</div>
@@ -31,6 +31,5 @@
</ul>
</div>
</div>
-<!--
+
<script type="text/javascript" src="{relative_path}/src/forum/search.js"></script>
--->
\ No newline at end of file