From 0ade9bafff14e9acb421a6bfe8937e8e30d24476 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 4 Sep 2014 15:01:01 +1000 Subject: [PATCH] FIX: highlight in yellow, not blue FEATURE: highlight in title --- app/assets/javascripts/discourse/lib/highlight.js | 4 ++-- app/assets/javascripts/discourse/views/post_view.js | 2 +- .../discourse/views/search-results-type.js.es6 | 8 +++++++- app/assets/stylesheets/common/base/header.scss | 4 ++++ lib/search/grouped_search_results.rb | 8 +------- spec/components/search_spec.rb | 2 +- spec/controllers/search_controller_spec.rb | 2 +- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/highlight.js b/app/assets/javascripts/discourse/lib/highlight.js index f35e8546fcb..0a6b9e0b271 100644 --- a/app/assets/javascripts/discourse/lib/highlight.js +++ b/app/assets/javascripts/discourse/lib/highlight.js @@ -70,7 +70,7 @@ jQuery.extend({ }); jQuery.fn.unhighlight = function (options) { - var settings = { className: 'highlight', element: 'span' }; + var settings = { className: 'highlight-strong', element: 'span' }; jQuery.extend(settings, options); return this.find(settings.element + "." + settings.className).each(function () { @@ -81,7 +81,7 @@ jQuery.fn.unhighlight = function (options) { }; jQuery.fn.highlight = function (words, options) { - var settings = { className: 'highlight', element: 'span', caseSensitive: false, wordsOnly: false }; + var settings = { className: 'highlight-strong', element: 'span', caseSensitive: false, wordsOnly: false }; jQuery.extend(settings, options); if (words.constructor === String) { diff --git a/app/assets/javascripts/discourse/views/post_view.js b/app/assets/javascripts/discourse/views/post_view.js index f316af35ef6..bc7fe08f8af 100644 --- a/app/assets/javascripts/discourse/views/post_view.js +++ b/app/assets/javascripts/discourse/views/post_view.js @@ -289,7 +289,7 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, { if(this._highlighted){ cooked.unhighlight(); } - cooked.highlight(highlight); + cooked.highlight(highlight.split(/\s+/)); this._highlighted = true; } else if(this._highlighted){ diff --git a/app/assets/javascripts/discourse/views/search-results-type.js.es6 b/app/assets/javascripts/discourse/views/search-results-type.js.es6 index 1ed3d355e2c..e914d2ceb8f 100644 --- a/app/assets/javascripts/discourse/views/search-results-type.js.es6 +++ b/app/assets/javascripts/discourse/views/search-results-type.js.es6 @@ -4,5 +4,11 @@ export default Ember.CollectionView.extend({ tagName: 'li', classNameBindings: ['selected'], templateName: Discourse.computed.fmt('parentView.displayType', "search/%@_result") - }) + }), + didInsertElement: function(){ + var term = this.get('controller.term'); + if(!_.isEmpty(term)) { + this.$().highlight(term.split(/\s+/)); + } + } }); diff --git a/app/assets/stylesheets/common/base/header.scss b/app/assets/stylesheets/common/base/header.scss index d043a989d7f..506cc036c67 100644 --- a/app/assets/stylesheets/common/base/header.scss +++ b/app/assets/stylesheets/common/base/header.scss @@ -335,3 +335,7 @@ padding: 4px 6px; margin-left: 6px; } + +.highlight-strong { + background-color: dark-light-diff($highlight, $secondary, 40%, -50%); +} diff --git a/lib/search/grouped_search_results.rb b/lib/search/grouped_search_results.rb index 574e827df56..742b1493b6b 100644 --- a/lib/search/grouped_search_results.rb +++ b/lib/search/grouped_search_results.rb @@ -30,13 +30,7 @@ class Search terms = @term.split(/\s+/) blurb = TextHelper.excerpt(cooked, terms.first, radius: 100) blurb = TextHelper.truncate(cooked, length: 200) if blurb.blank? - blurb = Sanitize.clean(blurb) - - terms.each do |term| - blurb.gsub!(Regexp.new("(#{Regexp.escape(term)})", Regexp::IGNORECASE), "\\1") - end - - blurb + Sanitize.clean(blurb) end def add(object) diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 0ac9a78c384..f47698c4c5e 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -145,7 +145,7 @@ describe Search do p = result.posts[0] p.topic.id.should == topic.id p.id.should == reply.id - result.blurb(p).should == "this reply has no quotes" + result.blurb(p).should == "this reply has no quotes" end end diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index a0e075a4a6c..5d4d9e2930b 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -15,7 +15,7 @@ describe SearchController do response.should be_success data = JSON.parse(response.body) data['posts'][0]['id'].should == my_post.id - data['posts'][0]['blurb'].should == 'this is my really awesome post' + data['posts'][0]['blurb'].should == 'this is my really awesome post' data['topics'][0]['id'].should == my_post.topic_id end end