mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Merge pull request #2495 from halfdan/2478-tag-duplicate
Prevent adding duplicate tags with different casing
This commit is contained in:
commit
eb35771bd3
1 changed files with 19 additions and 14 deletions
|
@ -188,7 +188,8 @@
|
||||||
searchTerm = $.trim($target.val()),
|
searchTerm = $.trim($target.val()),
|
||||||
tag,
|
tag,
|
||||||
$selectedSuggestion,
|
$selectedSuggestion,
|
||||||
isComma = ",".localeCompare(String.fromCharCode(e.keyCode || e.charCode)) === 0;
|
isComma = ",".localeCompare(String.fromCharCode(e.keyCode || e.charCode)) === 0,
|
||||||
|
hasAlreadyBeenAdded;
|
||||||
|
|
||||||
// use localeCompare in case of international keyboard layout
|
// use localeCompare in case of international keyboard layout
|
||||||
if ((e.keyCode === this.keys.ENTER || isComma) && searchTerm) {
|
if ((e.keyCode === this.keys.ENTER || isComma) && searchTerm) {
|
||||||
|
@ -197,16 +198,19 @@
|
||||||
|
|
||||||
$selectedSuggestion = this.$suggestions.children(".selected");
|
$selectedSuggestion = this.$suggestions.children(".selected");
|
||||||
if (this.$suggestions.is(":visible") && $selectedSuggestion.length !== 0) {
|
if (this.$suggestions.is(":visible") && $selectedSuggestion.length !== 0) {
|
||||||
|
|
||||||
if ($('.tag:containsExact("' + _.unescape($selectedSuggestion.data('tag-name')) + '")').length === 0) {
|
|
||||||
tag = {id: $selectedSuggestion.data('tag-id'), name: _.unescape($selectedSuggestion.data('tag-name'))};
|
tag = {id: $selectedSuggestion.data('tag-id'), name: _.unescape($selectedSuggestion.data('tag-name'))};
|
||||||
|
hasAlreadyBeenAdded = this.hasTagBeenAdded(tag.name);
|
||||||
|
if (!hasAlreadyBeenAdded) {
|
||||||
this.addTag(tag);
|
this.addTag(tag);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isComma) {
|
if (isComma) {
|
||||||
|
// Remove comma from string if comma is used to submit.
|
||||||
searchTerm = searchTerm.replace(/,/g, "");
|
searchTerm = searchTerm.replace(/,/g, "");
|
||||||
} // Remove comma from string if comma is used to submit.
|
}
|
||||||
if ($('.tag:containsExact("' + searchTerm + '")').length === 0) {
|
|
||||||
|
hasAlreadyBeenAdded = this.hasTagBeenAdded(searchTerm);
|
||||||
|
if (!hasAlreadyBeenAdded) {
|
||||||
this.addTag({id: null, name: searchTerm});
|
this.addTag({id: null, name: searchTerm});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,13 +223,9 @@
|
||||||
completeCurrentTag: function () {
|
completeCurrentTag: function () {
|
||||||
var $target = this.$('.tag-input'),
|
var $target = this.$('.tag-input'),
|
||||||
tagName = $target.val(),
|
tagName = $target.val(),
|
||||||
usedTagNames,
|
|
||||||
hasAlreadyBeenAdded;
|
hasAlreadyBeenAdded;
|
||||||
|
|
||||||
usedTagNames = _.map(this.model.get('tags'), function (tag) {
|
hasAlreadyBeenAdded = this.hasTagBeenAdded(tagName);
|
||||||
return tag.name.toUpperCase();
|
|
||||||
});
|
|
||||||
hasAlreadyBeenAdded = usedTagNames.indexOf(tagName.toUpperCase()) !== -1;
|
|
||||||
|
|
||||||
if (tagName.length > 0 && !hasAlreadyBeenAdded) {
|
if (tagName.length > 0 && !hasAlreadyBeenAdded) {
|
||||||
this.addTag({id: null, name: tagName});
|
this.addTag({id: null, name: tagName});
|
||||||
|
@ -270,9 +270,8 @@
|
||||||
|
|
||||||
tagNameMatches = tag.name.toUpperCase().indexOf(searchTerm) !== -1;
|
tagNameMatches = tag.name.toUpperCase().indexOf(searchTerm) !== -1;
|
||||||
|
|
||||||
hasAlreadyBeenAdded = _.some(self.model.get('tags'), function (usedTag) {
|
hasAlreadyBeenAdded = self.hasTagBeenAdded(tag.name);
|
||||||
return tag.name.toUpperCase() === usedTag.name.toUpperCase();
|
|
||||||
});
|
|
||||||
return tagNameMatches && !hasAlreadyBeenAdded;
|
return tagNameMatches && !hasAlreadyBeenAdded;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -288,6 +287,12 @@
|
||||||
|
|
||||||
this.$('.tag-input').val('').focus();
|
this.$('.tag-input').val('').focus();
|
||||||
this.$suggestions.hide();
|
this.$suggestions.hide();
|
||||||
|
},
|
||||||
|
|
||||||
|
hasTagBeenAdded: function (tagName) {
|
||||||
|
return _.some(this.model.get('tags'), function (usedTag) {
|
||||||
|
return tagName.toUpperCase() === usedTag.name.toUpperCase();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue