From af8560d12deed610da106535703e054fd030513d Mon Sep 17 00:00:00 2001 From: Preetpal Sohal Date: Wed, 15 Jun 2016 17:01:38 -0700 Subject: [PATCH] Added presentation settings for showing category and suggestion while hovering over appropriate divs (by embedding them in title attributes). --- readme.md | 2 ++ src/jquery.autocomplete.js | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index ce064f7..a449dd3 100644 --- a/readme.md +++ b/readme.md @@ -62,6 +62,8 @@ The standard jquery.autocomplete.js file is around 13KB when minified. * `preserveInput`: if `true`, input value stays the same when navigating over suggestions. Default: `false`. * `showNoSuggestionNotice`: Default `false`. When no matching results, display a notification label. * `noSuggestionNotice`: Default `No results`. Text or htmlString or Element or jQuery object for no matching results label. +* `showCategoryOnHover`: Default `false`. Embeds category in title attribute for each autocomplete-group div. +* `showSuggestionOnHover`: Default `false`. Embeds suggestion in title attribute for each autocomplete-suggestion div. * `onInvalidateSelection`: `function () {}` called when input is altered after selection has been made. `this` is bound to input element. * `tabDisabled`: Default `false`. Set to true to leave the cursor in the input field after the user tabs to select a suggestion. diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index 6118947..4a57516 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -90,6 +90,8 @@ }, showNoSuggestionNotice: false, noSuggestionNotice: 'No results', + showCategoryOnHover: false, + showSuggestionOnHover: false, orientation: 'bottom', forceFixPosition: false }; @@ -666,7 +668,11 @@ category = currentCategory; - return '
' + category + '
'; + if (options.showCategoryOnHover) { + return '
' + category + '
'; + } else { + return '
' + category + '
'; + } }; if (options.triggerSelectOnValidInput && that.isExactMatch(value)) { @@ -680,7 +686,11 @@ html += formatGroup(suggestion, value, i); } - html += '
' + formatResult(suggestion, value, i) + '
'; + if (options.showSuggestionOnHover) { + html += '
' + formatResult(suggestion, value, i) + '
'; + } else { + html += '
' + formatResult(suggestion, value, i) + '
'; + } }); this.adjustContainerWidth();