diff options
author | Byron Jones <glob@mozilla.com> | 2015-06-08 05:32:04 +0200 |
---|---|---|
committer | Byron Jones <glob@mozilla.com> | 2015-06-08 05:32:04 +0200 |
commit | 9eaa85e9ec0d2c7d562d7e29e7ff027b18485982 (patch) | |
tree | 2f82097fe0aa679901ab76e37c72c2be91fecdf1 /js | |
parent | 6c5fcca1d4fcef47bcbb7a3bf9fd2261ebeb9414 (diff) | |
download | bugzilla-9eaa85e9ec0d2c7d562d7e29e7ff027b18485982.tar.gz bugzilla-9eaa85e9ec0d2c7d562d7e29e7ff027b18485982.tar.xz |
Bug 1171826: sort keywords by "start with" then "substring"
Diffstat (limited to 'js')
-rw-r--r-- | js/field.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/js/field.js b/js/field.js index d8ede471b..04633baaa 100644 --- a/js/field.js +++ b/js/field.js @@ -792,7 +792,24 @@ $(function() { .each(function() { var that = $(this); that.devbridgeAutocomplete({ - lookup: BUGZILLA.autocomplete_values[that.data('values')], + lookup: function(query, done) { + var values = BUGZILLA.autocomplete_values[that.data('values')]; + query = query.toLowerCase(); + var matchStart = + $.grep(values, function(value) { + return value.toLowerCase().substr(0, query.length) === query; + }); + var matchSub = + $.grep(values, function(value) { + return value.toLowerCase().indexOf(query) !== -1 && + $.inArray(value, matchStart) === -1; + }); + var suggestions = + $.map($.merge(matchStart, matchSub), function(suggestion) { + return { value: suggestion }; + }); + done({ suggestions: suggestions }); + }, tabDisabled: true, delimiter: /,\s*/, minChars: 0, |