From 90549fbb079667dd6bbea52f5eaa517504cf2491 Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Wed, 11 Sep 2013 00:35:04 +0100 Subject: [PATCH] Allow UPPERCASE in tag names Fixes #642 Fairly self-explanatory --- core/client/views/editor-tag-widget.js | 41 ++++++++++---------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/core/client/views/editor-tag-widget.js b/core/client/views/editor-tag-widget.js index 430493e020..0fe20d8155 100644 --- a/core/client/views/editor-tag-widget.js +++ b/core/client/views/editor-tag-widget.js @@ -58,48 +58,37 @@ return this; }, - showSuggestions: function ($target, searchTerm) { + showSuggestions: function ($target, _searchTerm) { this.$suggestions.show(); - var results = this.findMatchingTags(searchTerm), + var searchTerm = _searchTerm.toLowerCase(), + matchingTags = this.findMatchingTags(searchTerm), styles = { left: $target.position().left }, maxSuggestions = 5, // Limit the suggestions number - results_length = results.length, - i, - suggest; + regexTerm = searchTerm.replace(/(\s+)/g, "(<[^>]+>)*$1(<[^>]+>)*"), + regexPattern = new RegExp("(" + regexTerm + ")", "i"); this.$suggestions.css(styles); this.$suggestions.html(""); - if (results_length < maxSuggestions) { - maxSuggestions = results_length; - } - for (i = 0; i < maxSuggestions; i += 1) { - this.$suggestions.append("
  • " + results[i].name + "
  • "); - } + matchingTags = _.first(matchingTags, maxSuggestions); + _.each(matchingTags, function (matchingTag) { + var highlightedName, + suggestionHTML; - suggest = $('ul.suggestions li a:contains("' + searchTerm + '")'); - - 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, "$1"); + highlightedName = matchingTag.name.replace(regexPattern, "$1"); /*jslint regexp: true */ // - would like to remove this - src_str = src_str.replace(/([^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/, "$1$2$4"); + highlightedName = highlightedName.replace(/([^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/, "$1$2$4"); - $(this).html(src_str); - }); + suggestionHTML = "
  • " + highlightedName + "
  • "; + this.$suggestions.append(suggestionHTML); + }, this); }, handleKeyup: function (e) { var $target = $(e.currentTarget), - searchTerm = $.trim($target.val()).toLowerCase(), + searchTerm = $.trim($target.val()), tag, $selectedSuggestion;