mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 03:23:43 +08:00
FIX: highlight in yellow, not blue
FEATURE: highlight in title
This commit is contained in:
parent
ba4363d8fc
commit
0ade9bafff
|
@ -70,7 +70,7 @@ jQuery.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
jQuery.fn.unhighlight = function (options) {
|
jQuery.fn.unhighlight = function (options) {
|
||||||
var settings = { className: 'highlight', element: 'span' };
|
var settings = { className: 'highlight-strong', element: 'span' };
|
||||||
jQuery.extend(settings, options);
|
jQuery.extend(settings, options);
|
||||||
|
|
||||||
return this.find(settings.element + "." + settings.className).each(function () {
|
return this.find(settings.element + "." + settings.className).each(function () {
|
||||||
|
@ -81,7 +81,7 @@ jQuery.fn.unhighlight = function (options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
jQuery.fn.highlight = function (words, 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);
|
jQuery.extend(settings, options);
|
||||||
|
|
||||||
if (words.constructor === String) {
|
if (words.constructor === String) {
|
||||||
|
|
|
@ -289,7 +289,7 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
|
||||||
if(this._highlighted){
|
if(this._highlighted){
|
||||||
cooked.unhighlight();
|
cooked.unhighlight();
|
||||||
}
|
}
|
||||||
cooked.highlight(highlight);
|
cooked.highlight(highlight.split(/\s+/));
|
||||||
this._highlighted = true;
|
this._highlighted = true;
|
||||||
|
|
||||||
} else if(this._highlighted){
|
} else if(this._highlighted){
|
||||||
|
|
|
@ -4,5 +4,11 @@ export default Ember.CollectionView.extend({
|
||||||
tagName: 'li',
|
tagName: 'li',
|
||||||
classNameBindings: ['selected'],
|
classNameBindings: ['selected'],
|
||||||
templateName: Discourse.computed.fmt('parentView.displayType', "search/%@_result")
|
templateName: Discourse.computed.fmt('parentView.displayType', "search/%@_result")
|
||||||
})
|
}),
|
||||||
|
didInsertElement: function(){
|
||||||
|
var term = this.get('controller.term');
|
||||||
|
if(!_.isEmpty(term)) {
|
||||||
|
this.$().highlight(term.split(/\s+/));
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -335,3 +335,7 @@
|
||||||
padding: 4px 6px;
|
padding: 4px 6px;
|
||||||
margin-left: 6px;
|
margin-left: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.highlight-strong {
|
||||||
|
background-color: dark-light-diff($highlight, $secondary, 40%, -50%);
|
||||||
|
}
|
||||||
|
|
|
@ -30,13 +30,7 @@ class Search
|
||||||
terms = @term.split(/\s+/)
|
terms = @term.split(/\s+/)
|
||||||
blurb = TextHelper.excerpt(cooked, terms.first, radius: 100)
|
blurb = TextHelper.excerpt(cooked, terms.first, radius: 100)
|
||||||
blurb = TextHelper.truncate(cooked, length: 200) if blurb.blank?
|
blurb = TextHelper.truncate(cooked, length: 200) if blurb.blank?
|
||||||
blurb = Sanitize.clean(blurb)
|
Sanitize.clean(blurb)
|
||||||
|
|
||||||
terms.each do |term|
|
|
||||||
blurb.gsub!(Regexp.new("(#{Regexp.escape(term)})", Regexp::IGNORECASE), "<span class='highlighted'>\\1</span>")
|
|
||||||
end
|
|
||||||
|
|
||||||
blurb
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add(object)
|
def add(object)
|
||||||
|
|
|
@ -145,7 +145,7 @@ describe Search do
|
||||||
p = result.posts[0]
|
p = result.posts[0]
|
||||||
p.topic.id.should == topic.id
|
p.topic.id.should == topic.id
|
||||||
p.id.should == reply.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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ describe SearchController do
|
||||||
response.should be_success
|
response.should be_success
|
||||||
data = JSON.parse(response.body)
|
data = JSON.parse(response.body)
|
||||||
data['posts'][0]['id'].should == my_post.id
|
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
|
data['topics'][0]['id'].should == my_post.topic_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user