0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Allow UPPERCASE in tag names

Fixes #642

Fairly self-explanatory
This commit is contained in:
Adam Howard 2013-09-11 00:35:04 +01:00
parent 687d7ed72d
commit 90549fbb07

View file

@ -58,48 +58,37 @@
return this; return this;
}, },
showSuggestions: function ($target, searchTerm) { showSuggestions: function ($target, _searchTerm) {
this.$suggestions.show(); this.$suggestions.show();
var results = this.findMatchingTags(searchTerm), var searchTerm = _searchTerm.toLowerCase(),
matchingTags = this.findMatchingTags(searchTerm),
styles = { styles = {
left: $target.position().left left: $target.position().left
}, },
maxSuggestions = 5, // Limit the suggestions number maxSuggestions = 5, // Limit the suggestions number
results_length = results.length, regexTerm = searchTerm.replace(/(\s+)/g, "(<[^>]+>)*$1(<[^>]+>)*"),
i, regexPattern = new RegExp("(" + regexTerm + ")", "i");
suggest;
this.$suggestions.css(styles); this.$suggestions.css(styles);
this.$suggestions.html(""); this.$suggestions.html("");
if (results_length < maxSuggestions) { matchingTags = _.first(matchingTags, maxSuggestions);
maxSuggestions = results_length; _.each(matchingTags, function (matchingTag) {
} var highlightedName,
for (i = 0; i < maxSuggestions; i += 1) { suggestionHTML;
this.$suggestions.append("<li data-tag-id='" + results[i].id + "' data-tag-name='" + results[i].name + "'><a href='#'>" + results[i].name + "</a></li>");
}
suggest = $('ul.suggestions li a:contains("' + searchTerm + '")'); highlightedName = matchingTag.name.replace(regexPattern, "<mark>$1</mark>");
suggest.each(function () {
var src_str = $(this).html(),
term = searchTerm,
pattern;
term = term.replace(/(\s+)/, "(<[^>]+>)*$1(<[^>]+>)*");
pattern = new RegExp("(" + term + ")", "i");
src_str = src_str.replace(pattern, "<mark>$1</mark>");
/*jslint regexp: true */ // - would like to remove this /*jslint regexp: true */ // - would like to remove this
src_str = src_str.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/, "$1</mark>$2<mark>$4"); highlightedName = highlightedName.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/, "$1</mark>$2<mark>$4");
$(this).html(src_str); suggestionHTML = "<li data-tag-id='" + matchingTag.id + "' data-tag-name='" + matchingTag.name + "'><a href='#'>" + highlightedName + "</a></li>";
}); this.$suggestions.append(suggestionHTML);
}, this);
}, },
handleKeyup: function (e) { handleKeyup: function (e) {
var $target = $(e.currentTarget), var $target = $(e.currentTarget),
searchTerm = $.trim($target.val()).toLowerCase(), searchTerm = $.trim($target.val()),
tag, tag,
$selectedSuggestion; $selectedSuggestion;