From 0687ee4f2c0f8e7d922b40c1d3d710ffbe2db57d Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Tue, 3 Feb 2015 15:16:18 -0200 Subject: [PATCH] Highlight Searched Terms --- public/software-catalog.js | 34 +++++++++++++++++++++++++++++++--- views/search/_full_community.html.erb | 4 ++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/public/software-catalog.js b/public/software-catalog.js index 22d4e3d..2b5e8d0 100644 --- a/public/software-catalog.js +++ b/public/software-catalog.js @@ -111,11 +111,39 @@ pagination.html(result_pagination); software_count.html(result_software_count); show_head_message(); + highlight_searched_terms(); - setTimeout(function(){ - console.log("fgdjfgdsh"); + hide_load_after_ajax(); + } + + + function hide_load_after_ajax() { + if ($("#overlay_loading_modal").is(":visible")) { close_loading(); - }, 1000); + setTimeout(hide_load_after_ajax, 1000); + } + } + + + function highlight_searched_terms() { + var searched_terms = $("#search-input").val(); + + if( searched_terms.length === 0 ) { + return undefined; + } + + var content_result = $(".search-content-result"); + var regex = new RegExp("("+searched_terms.replace(/\s/g, "|")+")", "gi"); + + content_result.each(function(i, e){ + var element = $(e); + + var new_text = element.text().replace(regex, function(text) { + return ""+text+""; + }); + + element.html(new_text); + }); } diff --git a/views/search/_full_community.html.erb b/views/search/_full_community.html.erb index b990f0e..9570ba9 100644 --- a/views/search/_full_community.html.erb +++ b/views/search/_full_community.html.erb @@ -10,11 +10,11 @@
<% link_name = software.acronym.blank? ? community.name : "#{software.acronym} - #{community.name}" %> -

+

<%= link_to_homepage(link_name, community.identifier) %>

- + <% body_stripped = strip_tags(software.finality) %> <%= excerpt(body_stripped, body_stripped.first(3), 200) if body_stripped %> -- libgit2 0.21.2