/**
 * angular-strap
 * @version v2.2.4 - 2015-05-28
 * @link http://mgcrea.github.io/angular-strap
 * @author Olivier Louvignes <olivier@mg-crea.com> (https://github.com/mgcrea)
 * @license MIT License, http://www.opensource.org/licenses/MIT
 */
'use strict';angular.module('mgcrea.ngStrap.typeahead',['mgcrea.ngStrap.tooltip','mgcrea.ngStrap.helpers.parseOptions']).provider('$typeahead',function(){var e=this.defaults={animation:'am-fade',prefixClass:'typeahead',prefixEvent:'$typeahead',placement:'bottom-left',template:'typeahead/typeahead.tpl.html',trigger:'focus',container:!1,keyboard:!0,html:!1,delay:0,minLength:1,filter:'filter',limit:6,autoSelect:!1,comparator:'',trimValue:!0};this.$get=['$window','$rootScope','$tooltip','$timeout',function(t,n,a,i){function o(t,n,o){var r={},l=angular.extend({},e,o);r=a(t,l);var c=o.scope,u=r.$scope;u.$resetMatches=function(){u.$matches=[],u.$activeIndex=l.autoSelect?0:-1},u.$resetMatches(),u.$activate=function(e){u.$$postDigest(function(){r.activate(e)})},u.$select=function(e,t){u.$$postDigest(function(){r.select(e)})},u.$isVisible=function(){return r.$isVisible()},r.update=function(e){u.$matches=e,u.$activeIndex>=e.length&&(u.$activeIndex=l.autoSelect?0:-1),/^(bottom|bottom-left|bottom-right)$/.test(l.placement)||i(r.$applyPlacement)},r.activate=function(e){u.$activeIndex=e},r.select=function(e){if(-1!==e){var t=u.$matches[e].value;n.$setViewValue(t),n.$render(),u.$resetMatches(),c&&c.$digest(),u.$emit(l.prefixEvent+'.select',t,e,r)}},r.$isVisible=function(){return l.minLength&&n?u.$matches.length&&angular.isString(n.$viewValue)&&n.$viewValue.length>=l.minLength:!!u.$matches.length},r.$getIndex=function(e){var t=u.$matches.length,n=t;if(t){for(n=t;n--&&u.$matches[n].value!==e;);if(!(0>n))return n}},r.$onMouseDown=function(e){e.preventDefault(),e.stopPropagation()},r.$onKeyDown=function(e){/(38|40|13)/.test(e.keyCode)&&(!r.$isVisible()||13===e.keyCode&&-1===u.$activeIndex||(e.preventDefault(),e.stopPropagation()),13===e.keyCode&&u.$matches.length?r.select(u.$activeIndex):38===e.keyCode&&u.$activeIndex>0?u.$activeIndex--:40===e.keyCode&&u.$activeIndex<u.$matches.length-1?u.$activeIndex++:angular.isUndefined(u.$activeIndex)&&(u.$activeIndex=0),u.$digest())};var s=r.show;r.show=function(){s(),i(function(){r.$element&&r.$element.on('mousedown',r.$onMouseDown),l.keyboard&&t&&t.on('keydown',r.$onKeyDown)},0,!1)};var $=r.hide;return r.hide=function(){r.$element&&r.$element.off('mousedown',r.$onMouseDown),l.keyboard&&t&&t.off('keydown',r.$onKeyDown),l.autoSelect||r.activate(-1),$()},r}angular.element(t.document.body);return o.defaults=e,o}]}).directive('bsTypeahead',['$window','$parse','$q','$typeahead','$parseOptions',function(e,t,n,a,i){var o=a.defaults;return{restrict:'EAC',require:'ngModel',link:function(e,t,n,r){var l={scope:e};angular.forEach(['placement','container','delay','trigger','keyboard','html','animation','template','filter','limit','minLength','watchOptions','selectMode','autoSelect','comparator','id','prefixEvent','prefixClass'],function(e){angular.isDefined(n[e])&&(l[e]=n[e])});var c=/^(false|0|)$/i;angular.forEach(['html','container','trimValue'],function(e){angular.isDefined(n[e])&&c.test(n[e])&&(l[e]=!1)}),t.attr('autocomplete','off');var u=l.filter||o.filter,s=l.limit||o.limit,$=l.comparator||o.comparator,d=n.bsOptions;u&&(d+=' | '+u+':$viewValue'),$&&(d+=':'+$),s&&(d+=' | limitTo:'+s);var f=i(d),m=a(t,r,l);if(l.watchOptions){var p=f.$match[7].replace(/\|.+/,'').replace(/\(.*\)/g,'').trim();e.$watchCollection(p,function(t,n){f.valuesFn(e,r).then(function(e){m.update(e),r.$render()})})}e.$watch(n.ngModel,function(t,n){e.$modelValue=t,f.valuesFn(e,r).then(function(e){if(l.selectMode&&!e.length&&t.length>0)return void r.$setViewValue(r.$viewValue.substring(0,r.$viewValue.length-1));e.length>s&&(e=e.slice(0,s));var n=m.$isVisible();n&&m.update(e),(1!==e.length||e[0].value!==t)&&(!n&&m.update(e),r.$render())})}),r.$formatters.push(function(e){var t=f.displayValue(e);return t?t:e&&'object'!=typeof e?e:''}),r.$render=function(){if(r.$isEmpty(r.$viewValue))return t.val('');var e=m.$getIndex(r.$modelValue),n=angular.isDefined(e)?m.$scope.$matches[e].label:r.$viewValue;n=angular.isObject(n)?f.displayValue(n):n;var a=n?n.toString().replace(/<(?:.|\n)*?>/gm,''):'';t.val(l.trimValue===!1?a:a.trim())},e.$on('$destroy',function(){m&&m.destroy(),l=null,m=null})}}}]);
//# sourceMappingURL=../modules/typeahead.min.js.map