feature: use select2 instead of chosen

This commit is contained in:
nXqd
2014-05-11 04:50:03 +00:00
parent 8714391bb2
commit 0b6ebdac8a
15 changed files with 4099 additions and 1456 deletions
@@ -36,16 +36,16 @@ Discourse.CategoryChooserView = Discourse.ComboboxView.extend({
}
}.property(),
template: function(text, templateData) {
var category = Discourse.Category.findById(parseInt(templateData.id,10));
if (!category) return text;
template: function(item) {
var category = Discourse.Category.findById(parseInt(item.id,10));
if (!category) return item.text;
var result = Discourse.HTML.categoryBadge(category, {showParent: true, link: false, allowUncategorized: true});
result += " <div class='topic-count'>&times; " + category.get('topic_count') + "</div>";
result += " <span class='topic-count'>&times; " + category.get('topic_count') + "</span>";
var description = templateData.description_text;
// TODO wtf how can this be null?
var description = category.get('description');
// TODO wtf how can this be null?;
if (description && description !== 'null') {
result += '<div class="category-desc">' +
@@ -66,28 +66,15 @@ Discourse.ComboboxView = Discourse.View.extend({
var $elem = this.$(),
self = this;
$elem.chosen({ template: this.template, disable_search_threshold: 5 });
if (this.overrideWidths) {
// The Chosen plugin hard-codes the widths in style attrs. :<
var $chznContainer = $elem.chosen().next();
$chznContainer.removeAttr("style");
$chznContainer.find('.chzn-drop').removeAttr("style");
$chznContainer.find('.chzn-search input').removeAttr("style");
}
if (this.classNames && this.classNames.length > 0) {
// Apply the classes to Chosen's dropdown div too:
_.each(this.classNames,function(c) {
$elem.chosen().next().addClass(c);
});
}
$elem.select2({formatResult: this.template, minimumResultsForSearch: 5, width: 'resolve'});
$elem.chosen().change(function(e) {
$elem.on("change", function (e) {
self.set('value', $(e.target).val());
});
},
willClearRender: function() {
var chosenId = this.$().attr('id') + "_chzn";
var chosenId = "s2id_" + this.$().attr('id');
Ember.$("#" + chosenId).remove();
}
+1 -1
View File
@@ -17,7 +17,7 @@
//= require bootstrap-dropdown.js
//= require bootstrap-modal.js
//= require bootstrap-transition.js
//= require chosen.jquery.js
//= require select2.js
//= require favcount.js
//= require jquery.ba-replacetext.js
//= require jquery.ba-resize.min.js