twitter/typeahead.js — pull request #390 by theoephraim (2013-08-09 07:33:53+00:00)
Title: Showing default suggestions on focus if minLength is 0

This addresses https://github.com/twitter/typeahead.js/issues/62 -- letting you display some suggestions when the user has an empty search query. This behaviour is triggered by setting minLength to 0 for a dataset. This behaviour is especially useful to make a combo-box type input, and for smaller datasets.

Default suggestions only work if dataset has local or prefetched data, and an error is thrown if you try to set minLength to 0 for a remote-only data source.

By default, the order of the default suggestions is the same as the order the data is added. There could in theory be some inconsistencies in this ordering due to object key ordering not always being preserved, however these issues arise when mixing numeric and string keys, which will not be the case. My first version was actually storing this default ordering separately in local storage along with the data, but it seemed unnecessary.

There is also an option to define a sort function that will be used by javascript's built in Array.sort function.
For example, to sort alphabetically:
```
$('#country-typeahead').typeahead([{
name: 'countries',
prefetch: '/api/countries.json',
minLength: 0,
defaultSort: function(a,b){ return a.value > b.value ? 1 : -1; }
}])
```
I opted to make the user add the `.value` in their function in case they want to sort by a custom property in their datums.