twitter/typeahead.js — pull request #812 by lukekarrys (2014-04-03 01:22:22+00:00)
Title: Implement character triggers (@-mentions)

This is basically #624 but adapted to work on the lastest master.

#### Syntax

```js
$('.at-mentions').typeahead({
triggerRegex: /@\w*/g,
triggerCharacter: '@'
}, dataset);
```

#### Playground
- Added an input and textarea for @-mentions
- Added a textarea for name mentions, to show whitespace examples

#### Tests
There is also a new test file `input_view_trigger_spec.js`. It's largely based on `input_view_spec.js` but any tests that triggers don't affect were removed and any other tests were updated for the specific trigger use cases.

All tests pass, and I think the code coverage is pretty high, but I wasn't sure how to find that number specifically.

The only thing I'm not satisfied with as far as tests go is `typeahead.js#_updateHint`. I couldn't find that particular method tested anywhere else, so I wasn't sure exactly how to test it. I'm open to suggestions for that.

#### Per Dataset

I played around with using `queryTokenizer` to parse triggered items from the query, but ultimately decided that the code needed to be a part of `input.js` since there could be multiple queries in one input and which one is used is based on the cursor position.

This means that `triggerRegex` and `triggerCharacter` are top level properties. The other open issue about this was #339 and it asked for a different trigger character per dataset. This PR doesn't do that, but I believe `queryTokenizer` could get you pretty far if you wanted to parse the query differently for different datasets.

#### Other Notes
- Blur events will no longer reset the input to the last query since a query might only be a part of the input value
- Hints work if the query is at the very end of the input value. But if there is non-query text after the query, no hint will be displayed.
- left/right keys run `input.js#_checkInputValue` since a change in cursor position could change the query