Buon giorno Jorge ;)
Yeah I believe that Twitter and TweetDeck have their own implementation of typeahead.
It made sense to me to write mixins that you can use to create specific typeaheads (components) like: cities typeahead, people typeahead, animals typeahead etc.
So I wrote two mixins to integrate Twitter's typeahead.js into my Flight App.
withBaseTypeahead
Base wrapper for the plugin.
- It requires typeahead.js
- defines the defaultAttrs (a copy of typeahead's options + few custom options)
- exposes a destroy method (called on before teardown using advice)
- binds the jQuery plugin to this.$input which is this.$node when the typeahead is not global (see the next mixin)
- listens for typeahead:autocompleted to add hidden input field(s) to your form with the selected value (optional)
withGlobalTypeahead
It depends on withBaseTypeahead and defines a mixin to create a shared typeahead across a bunch of forms on the same page.
We had a list of items (forms) where a user could add countries using an input field with typeahead,
plus the page had infinite scrolling so we really needed a shared (global) typeahead for this thing (performances + avoid rebindings).
Each form had a normal text input. Every time an input would get focus we would link the typeahead to that input.
- around initialize it creates this.$inputGlobalContainer and this.$input both jQuery elements (objects)
- append them to this.$node which now is the global container - usually the closest shared parent but it may as well be document.body or your page wrapper
- defines an activate method that moves (using jQuery's insertAfter) the global typeahead next to the target input field and hides the text input so that you can only see the typeahead's one - a sort of replace basically
- listens for the focusin event on your text inputs using event delegation to invoke the activate function
Defining components
Each component is basically an extra layer where we set the typeahead API endpoint, customise the typeahead settings and define the hidden inputs names that we want get on typeahead:autocompleted (an array used by withBaseTypeahead)
module.exports = defineComponent(catsNamesTypeahead, withBaseTypeahead/*, withGlobalTypeahead */);
Bottom line it should be pretty straight forward to wrap Bootstrap plugins if you read its event API docs.
Unfortunately I don't have the source code for those mixins and now I work for a different company but I hope that this helps :)