forked from mgcrea/angular-strap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypeahead.min.js
More file actions
9 lines (9 loc) · 4.54 KB
/
typeahead.min.js
File metadata and controls
9 lines (9 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
/**
* angular-strap
* @version v2.3.8 - 2016-03-31
* @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',templateUrl:'typeahead/typeahead.tpl.html',trigger:'focus',container:!1,keyboard:!0,html:!1,delay:0,minLength:1,filter:'bsAsyncFilter',limit:6,autoSelect:!1,comparator:'',trimValue:!0};this.$get=['$window','$rootScope','$tooltip','$$rAF','$timeout',function(t,n,a,i,o){function r(t,n,r){var c={},u=angular.extend({},e,r);c=a(t,u);var s=r.scope,$=c.$scope;$.$resetMatches=function(){$.$matches=[],$.$activeIndex=u.autoSelect?0:-1},$.$resetMatches(),$.$activate=function(e){$.$$postDigest(function(){c.activate(e)})},$.$select=function(e,t){$.$$postDigest(function(){c.select(e)})},$.$isVisible=function(){return c.$isVisible()},c.update=function(e){$.$matches=e,$.$activeIndex>=e.length&&($.$activeIndex=u.autoSelect?0:-1),l($),i(c.$applyPlacement)},c.activate=function(e){$.$activeIndex=e},c.select=function(e){if(-1!==e){var t=$.$matches[e].value;n.$setViewValue(t),n.$render(),$.$resetMatches(),s&&s.$digest(),$.$emit(u.prefixEvent+'.select',t,e,c)}},c.$isVisible=function(){return u.minLength&&n?$.$matches.length&&angular.isString(n.$viewValue)&&n.$viewValue.length>=u.minLength:!!$.$matches.length},c.$getIndex=function(e){var t;for(t=$.$matches.length;t--&&!angular.equals($.$matches[t].value,e););return t},c.$onMouseDown=function(e){e.preventDefault(),e.stopPropagation()},c.$onKeyDown=function(e){/(38|40|13)/.test(e.keyCode)&&(!c.$isVisible()||13===e.keyCode&&-1===$.$activeIndex||(e.preventDefault(),e.stopPropagation()),13===e.keyCode&&$.$matches.length?c.select($.$activeIndex):38===e.keyCode&&$.$activeIndex>0?$.$activeIndex--:40===e.keyCode&&$.$activeIndex<$.$matches.length-1?$.$activeIndex++:angular.isUndefined($.$activeIndex)&&($.$activeIndex=0),$.$digest())};var f=c.show;c.show=function(){f(),o(function(){c.$element&&(c.$element.on('mousedown',c.$onMouseDown),u.keyboard&&t&&t.on('keydown',c.$onKeyDown))},0,!1)};var d=c.hide;return c.hide=function(){c.$element&&c.$element.off('mousedown',c.$onMouseDown),u.keyboard&&t&&t.off('keydown',c.$onKeyDown),u.autoSelect||c.activate(-1),d()},c}function l(e){e.$$phase||e.$root&&e.$root.$$phase||e.$digest()}return r.defaults=e,r}]}).filter('bsAsyncFilter',['$filter',function(e){return function(t,n,a){return t&&angular.isFunction(t.then)?t.then(function(t){return e('filter')(t,n,a)}):e('filter')(t,n,a)}}]).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){t.off('change');var l={scope:e};angular.forEach(['template','templateUrl','controller','controllerAs','placement','container','delay','trigger','keyboard','html','animation','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','filter'],function(e){angular.isDefined(n[e])&&c.test(n[e])&&(l[e]=!1)}),t.attr('autocomplete')||t.attr('autocomplete','off');var u=angular.isDefined(l.filter)?l.filter:o.filter,s=l.limit||o.limit,$=l.comparator||o.comparator,f=n.bsOptions;u&&(f+=' | '+u+':$viewValue',$&&(f+=':'+$)),s&&(f+=' | limitTo:'+s);var d=i(f),p=a(t,r,l);if(l.watchOptions){var h=d.$match[7].replace(/\|.+/,'').replace(/\(.*\)/g,'').trim();e.$watchCollection(h,function(t,n){d.valuesFn(e,r).then(function(e){p.update(e),r.$render()})})}e.$watch(n.ngModel,function(t,n){e.$modelValue=t,d.valuesFn(e,r).then(function(e){return l.selectMode&&!e.length&&t.length>0?void r.$setViewValue(r.$viewValue.substring(0,r.$viewValue.length-1)):(e.length>s&&(e=e.slice(0,s)),p.update(e),void r.$render())})}),r.$formatters.push(function(e){var t=d.displayValue(e);return t?t:angular.isDefined(e)&&'object'!=typeof e?e:''}),r.$render=function(){if(r.$isEmpty(r.$viewValue))return t.val('');var e=p.$getIndex(r.$modelValue),n=-1!==e?p.$scope.$matches[e].label:r.$viewValue;n=angular.isObject(n)?d.displayValue(n):n;var a=n?n.toString().replace(/<(?:.|\n)*?>/gm,''):'';t.val(l.trimValue===!1?a:a.trim())},e.$on('$destroy',function(){p&&p.destroy(),l=null,p=null})}}}]);
//# sourceMappingURL=typeahead.min.js.map