0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00

Merge pull request #4457 from jaswilli/tags

Fix post tags input.
This commit is contained in:
Matt Enlow 2014-11-15 08:37:07 -07:00
commit 360d77bebd
2 changed files with 22 additions and 13 deletions

View file

@ -47,6 +47,7 @@ var PostTagsInputController = Ember.Controller.extend({
return;
}
newTagText = newTagText.trim();
searchTerm = newTagText.toLowerCase();
// add existing tag if we have a match
@ -76,8 +77,10 @@ var PostTagsInputController = Ember.Controller.extend({
},
deleteTag: function (tag) {
this.get('tags').removeObject(tag);
this.get('tagEnteredOrder').removeObject(tag.get('name'));
if (tag) {
this.get('tags').removeObject(tag);
this.get('tagEnteredOrder').removeObject(tag.get('name'));
}
},
deleteLastTag: function () {
@ -160,7 +163,7 @@ var PostTagsInputController = Ember.Controller.extend({
matchingTags,
// Limit the suggestions number
maxSuggestions = 5,
suggestions = new Ember.A();
suggestions = Ember.A();
if (!searchTerm || Ember.isEmpty(searchTerm.trim())) {
this.set('suggestions', null);
@ -182,7 +185,8 @@ var PostTagsInputController = Ember.Controller.extend({
findMatchingTags: function (searchTerm) {
var matchingTags,
self = this,
allTags = this.store.all('tag');
allTags = this.store.all('tag'),
deDupe = {};
if (allTags.get('length') === 0) {
return [];
@ -192,12 +196,21 @@ var PostTagsInputController = Ember.Controller.extend({
matchingTags = allTags.filter(function (tag) {
var tagNameMatches,
hasAlreadyBeenAdded;
hasAlreadyBeenAdded,
tagName = tag.get('name');
tagNameMatches = tag.get('name').toLowerCase().indexOf(searchTerm) !== -1;
hasAlreadyBeenAdded = self.hasTag(tag.get('name'));
tagNameMatches = tagName.toLowerCase().indexOf(searchTerm) !== -1;
hasAlreadyBeenAdded = self.hasTag(tagName);
return tagNameMatches && !hasAlreadyBeenAdded;
if (tagNameMatches && !hasAlreadyBeenAdded) {
if (typeof deDupe[tagName] === 'undefined') {
deDupe[tagName] = 1;
} else {
deDupe[tagName] += 1;
}
}
return deDupe[tagName] === 1;
});
return matchingTags;
@ -215,7 +228,7 @@ var PostTagsInputController = Ember.Controller.extend({
tagName = Ember.Handlebars.Utils.escapeExpression(matchingTag.get('name')),
regex = new RegExp('(' + regexEscapedSearchTerm + ')', 'gi'),
highlightedName,
suggestion = new Ember.Object();
suggestion = Ember.Object.create();
highlightedName = tagName.replace(regex, '<mark>$1</mark>');
highlightedName = new Ember.Handlebars.SafeString(highlightedName);

View file

@ -50,10 +50,6 @@ var PostTagsInputView = Ember.View.extend({
focusOut: function () {
this.get('parentView').set('hasFocus', false);
// if (!Ember.isEmpty(this.get('value'))) {
// this.get('parentView.controller').send('addNewTag');
// }
},
keyDown: function (event) {