I want to add 'setInputDataId' function at same level as the existing function '_select' is, in plugin js http://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js file without actually modifying the file itself. So I would like to know how can I add new function, I would appreciate the help.
Existing Code in Plugin:
_select: function select(datum) {
this.input.setQuery(datum.value);
this.input.setInputValue(datum.value, true);
this._setLanguageDirection();
this.eventBus.trigger("selected", datum.raw, datum.datasetName);
this.dropdown.close();
_.defer(_.bind(this.dropdown.empty, this.dropdown));
},
New code I want:
_select: function select(datum) {
this.input.setQuery(datum.value);
this.input.setInputValue(datum.value, true);
this.input.setInputDataId(datum.raw);
this._setLanguageDirection();
this.eventBus.trigger("selected", datum.raw, datum.datasetName);
this.dropdown.close();
_.defer(_.bind(this.dropdown.empty, this.dropdown));
},
And also as 'setInputDataId' function is not originally in plugin, I want to add this function too.
the function body is:
setInputDataId: function setInputDataId(raw) {
this.$input.attr('data-id',raw.id);
},
Please goto http://twitter.github.io/typeahead.js/examples/ In chrome's console tab do this:
console.dir($.fn.typeahead)
Now expand node function then '' then second Closure there you can see Typeahead. now click on Typeahead the prototype there you can see _select method. How can I modify this function.
Hierarchy:
function
<function scope>
Closure (second)
Typeahead
prototype
_select