Skip to content

Commit

Permalink
Remove non-alphanumeric characters from dataset.name to avoid issues …
Browse files Browse the repository at this point in the history
…with class names (Issue twitter#610)

Replaced dataset.name with dataset.name.replace(/\W/g, '') in
typeahead.js
  • Loading branch information
ejdaly committed Jan 15, 2014
1 parent 331cff9 commit cf3c47e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dist/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@
return $suggestion.length > 0 ? extractSuggestion($suggestion) : null;
},
renderSuggestions: function(dataset, suggestions) {
var datasetClassName = "tt-dataset-" + dataset.name, wrapper = '<div class="tt-suggestion">%body</div>', compiledHtml, $suggestionsList, $dataset = this.$menu.find("." + datasetClassName), elBuilder, fragment, $el;
var datasetClassName = "tt-dataset-" + dataset.name.replace(/\W/g, ''), wrapper = '<div class="tt-suggestion">%body</div>', compiledHtml, $suggestionsList, $dataset = this.$menu.find("." + datasetClassName), elBuilder, fragment, $el;
if ($dataset.length === 0) {
$suggestionsList = $(html.suggestionsList).css(css.suggestionsList);
$dataset = $("<div></div>").addClass(datasetClassName).append(dataset.header).append($suggestionsList).append(dataset.footer).appendTo(this.$menu);
Expand All @@ -824,7 +824,7 @@
elBuilder = document.createElement("div");
fragment = document.createDocumentFragment();
utils.each(suggestions, function(i, suggestion) {
suggestion.dataset = dataset.name;
suggestion.dataset = dataset.name.replace(/\W/g, '');
compiledHtml = dataset.template(suggestion.datum);
elBuilder.innerHTML = wrapper.replace("%body", compiledHtml);
$el = $(elBuilder.firstChild).css(css.suggestion).data("suggestion", suggestion);
Expand All @@ -835,7 +835,7 @@
});
$dataset.show().find(".tt-suggestions").html(fragment);
} else {
this.clearSuggestions(dataset.name);
this.clearSuggestions(dataset.name.replace(/\W/g, ''));
}
this.trigger("suggestionsRendered");
},
Expand Down

0 comments on commit cf3c47e

Please sign in to comment.