From 49978d02c2e0d7a9dcbc3608a2ecd907435c53f3 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 9 Mar 2015 16:09:26 -0400 Subject: [PATCH] FIX: `category-group` didn't work with subdirectories --- .../components/category-group.js.es6 | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/components/category-group.js.es6 b/app/assets/javascripts/discourse/components/category-group.js.es6 index 14caa32bfe5..13906ed312d 100644 --- a/app/assets/javascripts/discourse/components/category-group.js.es6 +++ b/app/assets/javascripts/discourse/components/category-group.js.es6 @@ -2,31 +2,32 @@ import { categoryBadgeHTML } from 'discourse/helpers/category-link'; export default Ember.Component.extend({ - _initializeAutocomplete: function(){ - var self = this; - var template = this.container.lookup('template:category-group-autocomplete.raw'); + _initializeAutocomplete: function() { + const self = this, + template = this.container.lookup('template:category-group-autocomplete.raw'), + regexp = new RegExp("href=['\"]" + Discourse.getURL('/c/') + "([^'\"]+)"); this.$('input').autocomplete({ items: this.get('categories'), single: false, allowAny: false, - dataSource: function(term){ + dataSource(term){ return Discourse.Category.list().filter(function(category){ - var regex = new RegExp(term, "i"); + const regex = new RegExp(term, "i"); return category.get("name").match(regex) && !_.contains(self.get('blacklist') || [], category) && !_.contains(self.get('categories'), category) ; }); }, - onChangeItems: function(items) { - var categories = _.map(items, function(link) { - var slug = link.match(/href=['"]\/c\/([^'"]+)/)[1]; + onChangeItems(items) { + const categories = _.map(items, function(link) { + const slug = link.match(regexp)[1]; return Discourse.Category.findSingleBySlug(slug); }); self.set("categories", categories); }, - template: template, - transformComplete: function(category) { + template, + transformComplete(category) { return categoryBadgeHTML(category, {allowUncategorized: true}); } });