mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 16:52:45 +08:00
correct the category chooser to properly convert any html in category descriptions to text
This commit is contained in:
parent
1ac7c28680
commit
1106eb9902
|
@ -63,7 +63,13 @@ Discourse.Category = Discourse.Model.extend({
|
|||
removeGroup: function(group){
|
||||
this.get("groups").removeObject(group);
|
||||
this.get("availableGroups").addObject(group);
|
||||
}
|
||||
},
|
||||
|
||||
// note, this is used in a data attribute, data attributes get downcased
|
||||
// to avoid confusion later on using this naming here.
|
||||
description_text: function(){
|
||||
return $("<div>" + this.get("description") + "</div>").text();
|
||||
}.property("description")
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
Discourse.CategoryChooserView = Discourse.ComboboxView.extend({
|
||||
classNames: ['combobox category-combobox'],
|
||||
overrideWidths: true,
|
||||
dataAttributes: ['name', 'color', 'text_color', 'description', 'topic_count'],
|
||||
dataAttributes: ['name', 'color', 'text_color', 'description_text', 'topic_count'],
|
||||
valueBinding: Ember.Binding.oneWay('source'),
|
||||
|
||||
init: function() {
|
||||
|
@ -23,15 +23,24 @@ Discourse.CategoryChooserView = Discourse.ComboboxView.extend({
|
|||
|
||||
template: function(text, templateData) {
|
||||
if (!templateData.color) return text;
|
||||
|
||||
var result = "<span class='badge-category' style='background-color: #" + templateData.color + '; color: #' +
|
||||
templateData.text_color + ";'>" + templateData.name + "</span>";
|
||||
|
||||
result += " <span class='topic-count'>× " + templateData.topic_count + "</span>";
|
||||
if (templateData.description && templateData.description !== 'null') {
|
||||
result += '<div class="category-desc">' + templateData.description.substr(0,200) + (templateData.description.length > 200 ? '…' : '') + '</div>';
|
||||
|
||||
var description = templateData.description_text;
|
||||
// TODO wtf how can this be null?
|
||||
if (description && description !== 'null') {
|
||||
|
||||
result += '<div class="category-desc">' +
|
||||
description.substr(0,200) +
|
||||
(description.length > 200 ? '…' : '') +
|
||||
'</div>';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Discourse.View.registerHelper('categoryChooser', Discourse.CategoryChooserView);
|
||||
Discourse.View.registerHelper('categoryChooser', Discourse.CategoryChooserView);
|
||||
|
|
Loading…
Reference in New Issue
Block a user