!function(a,b){"function"==typeof define&&define.amd?define("angular-typeahead",["angular"],function(a){return b(a)}):"object"==typeof exports?module.exports=b(require("angular"),require("typeahead.js")):b(angular)}(this,function(a){"use strict";a.module("siyfion.sfTypeahead",[]).value("$typeahead",function(a){a.typeahead.apply(a,Array.prototype.slice.call(arguments,1))}).directive("sfTypeahead",["$typeahead",function(b){return{restrict:"AC",require:"ngModel",scope:{datasets:"=",options:"=",allowCustom:"="},link:function(c,d,e,f){function g(){r=p?c.$watchCollection("datasets",h):c.$watch("datasets",h)}function h(b,c){if(!a.equals(b,c)){var d=p;i(),p!==d&&(r(),g())}}function i(){if(null==c.datasets)throw new Error("The datasets parameter is mandatory!");n=c.options||{},p=a.isArray(c.datasets),o=p?c.datasets:[c.datasets],q?(b(d,"destroy"),b(d,n,o)):(b(d,n,o),c.$watch("options",i),q=!0)}function j(b){for(var c in o){var d=o[c],e=d.displayKey||"value",f=(a.isFunction(e)?e(b):b[e])||"";return f}}function k(){return void 0===c.allowCustom||!!c.allowCustom}function l(a){c.$apply(function(){f.$setViewValue(a)})}function m(a){d.bind(a,function(){c.$emit(a,Array.prototype.slice.call(arguments,1))})}var n,o,p,q=!1,r=null;i(),g(),f.$parsers.push(function(b){return a.isObject(f.$modelValue)&&b===j(f.$modelValue)?f.$modelValue:k()||"string"!=typeof b?b:f.$modelValue}),f.$formatters.push(function(c){return a.isObject(c)&&(c=j(c)),c?b(d,"val",c):b(d,"val",""),c}),d.bind("typeahead:select",function(a,b,d){l(b),c.$emit("typeahead:select",b,d)}),d.bind("typeahead:autocomplete",function(a,b,d){l(b),c.$emit("typeahead:autocomplete",b,d)}),m("typeahead:active"),m("typeahead:idle"),m("typeahead:open"),m("typeahead:close"),m("typeahead:change"),m("typeahead:render"),m("typeahead:cursorchange"),m("typeahead:asyncrequest"),m("typeahead:asynccancel"),m("typeahead:asyncreceive")}}}])});