Razique Mahroua
2019-11-28 1759c24ad2d2b35ec5c756e3dd3a60185fe944b7
commit | author | age
1759c2 1 /**
RM 2  * angular-strap
3  * @version v2.0.3 - 2014-05-30
4  * @link http://mgcrea.github.io/angular-strap
5  * @author Olivier Louvignes (olivier@mg-crea.com)
6  * @license MIT License, http://www.opensource.org/licenses/MIT
7  */
8 "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",placement:"bottom-left",template:"typeahead/typeahead.tpl.html",trigger:"focus",container:!1,keyboard:!0,html:!1,delay:0,minLength:1,filter:"filter",limit:6};this.$get=["$window","$rootScope","$tooltip",function(t,n,a){function i(t,n,i){var o={},r=angular.extend({},e,i);o=a(t,r);var l=i.scope,c=o.$scope;c.$resetMatches=function(){c.$matches=[],c.$activeIndex=0},c.$resetMatches(),c.$activate=function(e){c.$$postDigest(function(){o.activate(e)})},c.$select=function(e){c.$$postDigest(function(){o.select(e)})},c.$isVisible=function(){return o.$isVisible()},o.update=function(e){c.$matches=e,c.$activeIndex>=e.length&&(c.$activeIndex=0)},o.activate=function(e){c.$activeIndex=e},o.select=function(e){var t=c.$matches[e].value;n.$setViewValue(t),n.$render(),c.$resetMatches(),l&&l.$digest(),c.$emit("$typeahead.select",t,e)},o.$isVisible=function(){return r.minLength&&n?c.$matches.length&&angular.isString(n.$viewValue)&&n.$viewValue.length>=r.minLength:!!c.$matches.length},o.$getIndex=function(e){var t=c.$matches.length,n=t;if(t){for(n=t;n--&&c.$matches[n].value!==e;);if(!(0>n))return n}},o.$onMouseDown=function(e){e.preventDefault(),e.stopPropagation()},o.$onKeyDown=function(e){/(38|40|13)/.test(e.keyCode)&&(e.preventDefault(),e.stopPropagation(),13===e.keyCode&&c.$matches.length?o.select(c.$activeIndex):38===e.keyCode&&c.$activeIndex>0?c.$activeIndex--:40===e.keyCode&&c.$activeIndex<c.$matches.length-1?c.$activeIndex++:angular.isUndefined(c.$activeIndex)&&(c.$activeIndex=0),c.$digest())};var s=o.show;o.show=function(){s(),setTimeout(function(){o.$element.on("mousedown",o.$onMouseDown),r.keyboard&&t.on("keydown",o.$onKeyDown)})};var u=o.hide;return o.hide=function(){o.$element.off("mousedown",o.$onMouseDown),r.keyboard&&t.off("keydown",o.$onKeyDown),u()},o}angular.element(t.document.body);return i.defaults=e,i}]}).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"],function(e){angular.isDefined(n[e])&&(l[e]=n[e])});var c=l.filter||o.filter,s=l.limit||o.limit,u=n.ngOptions;c&&(u+=" | "+c+":$viewValue"),s&&(u+=" | limitTo:"+s);var $=i(u),d=a(t,r,l);e.$watch(n.ngModel,function(t){e.$modelValue=t,$.valuesFn(e,r).then(function(e){e.length>s&&(e=e.slice(0,s)),(1!==e.length||e[0].value!==t)&&(d.update(e),r.$render())})}),r.$render=function(){if(r.$isEmpty(r.$viewValue))return t.val("");var e=d.$getIndex(r.$modelValue),n=angular.isDefined(e)?d.$scope.$matches[e].label:r.$viewValue;n=angular.isObject(n)?n.label:n,t.val(n.replace(/<(?:.|\n)*?>/gm,"").trim())},e.$on("$destroy",function(){d.destroy(),l=null,d=null})}}}]);