mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
correct the category chooser to properly convert any html in category descriptions to text
This commit is contained in:
@@ -63,7 +63,13 @@ Discourse.Category = Discourse.Model.extend({
|
|||||||
removeGroup: function(group){
|
removeGroup: function(group){
|
||||||
this.get("groups").removeObject(group);
|
this.get("groups").removeObject(group);
|
||||||
this.get("availableGroups").addObject(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({
|
Discourse.CategoryChooserView = Discourse.ComboboxView.extend({
|
||||||
classNames: ['combobox category-combobox'],
|
classNames: ['combobox category-combobox'],
|
||||||
overrideWidths: true,
|
overrideWidths: true,
|
||||||
dataAttributes: ['name', 'color', 'text_color', 'description', 'topic_count'],
|
dataAttributes: ['name', 'color', 'text_color', 'description_text', 'topic_count'],
|
||||||
valueBinding: Ember.Binding.oneWay('source'),
|
valueBinding: Ember.Binding.oneWay('source'),
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
@@ -23,15 +23,24 @@ Discourse.CategoryChooserView = Discourse.ComboboxView.extend({
|
|||||||
|
|
||||||
template: function(text, templateData) {
|
template: function(text, templateData) {
|
||||||
if (!templateData.color) return text;
|
if (!templateData.color) return text;
|
||||||
|
|
||||||
var result = "<span class='badge-category' style='background-color: #" + templateData.color + '; color: #' +
|
var result = "<span class='badge-category' style='background-color: #" + templateData.color + '; color: #' +
|
||||||
templateData.text_color + ";'>" + templateData.name + "</span>";
|
templateData.text_color + ";'>" + templateData.name + "</span>";
|
||||||
|
|
||||||
result += " <span class='topic-count'>× " + templateData.topic_count + "</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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.View.registerHelper('categoryChooser', Discourse.CategoryChooserView);
|
Discourse.View.registerHelper('categoryChooser', Discourse.CategoryChooserView);
|
||||||
|
|||||||
Reference in New Issue
Block a user