Added showing tag suggestions on click

This commit is contained in:
Marcin Kurczewski 2014-11-30 11:31:40 +01:00
parent 24ce67b4ff
commit c350c47195

View file

@ -187,7 +187,7 @@ App.Controls.TagInput = function($underlyingInput) {
addTag(impliedTagName); addTag(impliedTagName);
flashTagYellow(impliedTagName); flashTagYellow(impliedTagName);
}); });
showOrHideSuggestions(tag.suggestions); showOrHideSuggestions(tagName);
} else { } else {
flashTagGreen(tagName); flashTagGreen(tagName);
} }
@ -262,7 +262,8 @@ App.Controls.TagInput = function($underlyingInput) {
$tagLink.text(tagName); $tagLink.text(tagName);
$tagLink.click(function(e) { $tagLink.click(function(e) {
e.preventDefault(); e.preventDefault();
showOrHideTagSiblings(tagName); showOrHideSiblings(tagName);
showOrHideSuggestions(tagName);
}); });
$elem.append($tagLink); $elem.append($tagLink);
@ -276,19 +277,20 @@ App.Controls.TagInput = function($underlyingInput) {
return $elem; return $elem;
} }
function showOrHideSuggestions(suggestedTagNames) { function showOrHideSuggestions(tagName) {
if (_.size(suggestedTagNames) === 0) { var tag = getExportedTag(tagName);
return; if (tag && _.size(tag.suggestions) > 0) {
} var suggestions = filterSuggestions(tag.suggestions);
if (suggestions.length > 0) {
var suggestions = filterSuggestions(suggestedTagNames); attachTagsToSuggestionList($suggestions.find('ul'), suggestions);
if (suggestions.length > 0) { $suggestions.slideDown('fast');
attachTagsToSuggestionList($suggestions.find('ul'), suggestions); return;
$suggestions.slideDown('fast'); }
} }
$suggestions.slideUp('fast');
} }
function showOrHideTagSiblings(tagName) { function showOrHideSiblings(tagName) {
if ($siblings.data('lastTag') === tagName && $siblings.is(':visible')) { if ($siblings.data('lastTag') === tagName && $siblings.is(':visible')) {
$siblings.slideUp('fast'); $siblings.slideUp('fast');
$siblings.data('lastTag', null); $siblings.data('lastTag', null);