Commit 0687ee4f2c0f8e7d922b40c1d3d710ffbe2db57d

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent ab66733b

Highlight Searched Terms

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
public/software-catalog.js
... ... @@ -111,11 +111,39 @@
111 111 pagination.html(result_pagination);
112 112 software_count.html(result_software_count);
113 113 show_head_message();
  114 + highlight_searched_terms();
114 115  
115   - setTimeout(function(){
116   - console.log("fgdjfgdsh");
  116 + hide_load_after_ajax();
  117 + }
  118 +
  119 +
  120 + function hide_load_after_ajax() {
  121 + if ($("#overlay_loading_modal").is(":visible")) {
117 122 close_loading();
118   - }, 1000);
  123 + setTimeout(hide_load_after_ajax, 1000);
  124 + }
  125 + }
  126 +
  127 +
  128 + function highlight_searched_terms() {
  129 + var searched_terms = $("#search-input").val();
  130 +
  131 + if( searched_terms.length === 0 ) {
  132 + return undefined;
  133 + }
  134 +
  135 + var content_result = $(".search-content-result");
  136 + var regex = new RegExp("("+searched_terms.replace(/\s/g, "|")+")", "gi");
  137 +
  138 + content_result.each(function(i, e){
  139 + var element = $(e);
  140 +
  141 + var new_text = element.text().replace(regex, function(text) {
  142 + return "<strong>"+text+"</strong>";
  143 + });
  144 +
  145 + element.html(new_text);
  146 + });
119 147 }
120 148  
121 149  
... ...
views/search/_full_community.html.erb
... ... @@ -10,11 +10,11 @@
10 10 <div class="search-community-content-block">
11 11 <span>
12 12 <% link_name = software.acronym.blank? ? community.name : "#{software.acronym} - #{community.name}" %>
13   - <h4>
  13 + <h4 class="search-content-result">
14 14 <%= link_to_homepage(link_name, community.identifier) %>
15 15 </h4>
16 16 </span>
17   - <span>
  17 + <span class="search-content-result">
18 18 <% body_stripped = strip_tags(software.finality) %>
19 19 <%= excerpt(body_stripped, body_stripped.first(3), 200) if body_stripped %>
20 20 </span>
... ...