FIX: highlight in yellow, not blue

FEATURE: highlight in title
This commit is contained in:
Sam 2014-09-04 15:01:01 +10:00
parent ba4363d8fc
commit 0ade9bafff
7 changed files with 17 additions and 13 deletions

View File

@ -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) {

View File

@ -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){

View File

@ -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+/));
}
}
});

View File

@ -335,3 +335,7 @@
padding: 4px 6px;
margin-left: 6px;
}
.highlight-strong {
background-color: dark-light-diff($highlight, $secondary, 40%, -50%);
}

View File

@ -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), "<span class='highlighted'>\\1</span>")
end
blurb
Sanitize.clean(blurb)
end
def add(object)

View File

@ -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 <span class='highlighted'>quotes</span>"
result.blurb(p).should == "this reply has no quotes"
end
end

View File

@ -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 <span class=\'highlighted\'>awesome</span> post'
data['posts'][0]['blurb'].should == 'this is my really awesome post'
data['topics'][0]['id'].should == my_post.topic_id
end
end