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

View file

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