text: /*! Copyright (c) 2014 Hidenari Nozaki and contributors | Licensed under the MIT license */
  "use strict";!function(a,b){"undefined"!=typeof module&&module.exports?module.exports=b(require("angular")):"function"==typeof define&&define.amd?define(["../../angular/angular"],b):b(a.angular)}(window,function(a){a.module("angucomplete-alt",[]).directive("angucompleteAlt",["$q","$parse","$http","$sce","$timeout","$templateCache","$interpolate",function(a,b,c,d,e,f,g){function h(b,f,g,h){function w(a){la=null,b.hideResults(a),document.body.removeEventListener("click",w)}function x(a){return a.which?a.which:a.keyCode}function y(a){"function"==typeof b.selectedObject?b.selectedObject(a):b.selectedObject=a,E(a?!0:!1)}function z(a){return function(c){return b[a]?b[a](c):c}}function A(a){y({originalObject:a}),b.clearSelected&&(b.searchStr=null),T()}function B(a){return b.titleField.split(",").map(function(b){return C(a,b)}).join(" ")}function C(a,b){var c,d;if(b){c=b.split("."),d=a;for(var e=0;e<c.length;e++)d=d[c[e]]}else d=a;return d}function D(a,c){var e,f,g;return g=new RegExp(c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"i"),a?(a.match&&a.replace||(a=a.toString()),f=a.match(g),e=f?a.replace(g,'<span class="'+b.matchClass+'">'+f[0]+"</span>"):a,d.trustAsHtml(e)):void 0}function E(a){b.notEmpty=a,ha=b.searchStr,b.fieldRequired&&h&&h.$setValidity(ga,a)}function F(a){var c=x(a);if(c!==l&&c!==j)if(c===k||c===n)a.preventDefault();else if(c===i)a.preventDefault(),!b.showDropdown&&b.searchStr&&b.searchStr.length>=ea&&(U(),b.searching=!0,X(b.searchStr));else if(c===m)T(),b.$apply(function(){da.val(b.searchStr)});else{if(0===ea&&!b.searchStr)return;b.searchStr&&""!==b.searchStr?b.searchStr.length>=ea&&(U(),fa&&e.cancel(fa),b.searching=!0,fa=e(function(){X(b.searchStr)},b.pause)):b.showDropdown=!1,ha&&ha!==b.searchStr&&!b.clearSelected&&b.$apply(function(){y()})}}function G(a){!b.overrideSuggestions||b.selectedObject&&b.selectedObject.originalObject===b.searchStr||(a&&a.preventDefault(),A(b.searchStr))}function H(a){var b=getComputedStyle(a);return a.offsetHeight+parseInt(b.marginTop,10)+parseInt(b.marginBottom,10)}function I(){return ja.getBoundingClientRect().top+parseInt(getComputedStyle(ja).maxHeight,10)}function J(){return f[0].querySelectorAll(".angucomplete-row")[b.currentIndex]}function K(){return J().getBoundingClientRect().top-(ja.getBoundingClientRect().top+parseInt(getComputedStyle(ja).paddingTop,10))}function L(a){ja.scrollTop=ja.scrollTop+a}function M(){var a=b.results[b.currentIndex];b.matchClass?da.val(B(a.originalObject)):da.val(a.title)}function N(a){var c=x(a),d=null,e=null;c===n&&b.results?(b.currentIndex>=0&&b.currentIndex<b.results.length?(a.preventDefault(),b.selectResult(b.results[b.currentIndex])):(G(a),T()),b.$apply()):c===i&&b.results?(a.preventDefault(),b.currentIndex+1<b.results.length&&b.showDropdown&&(b.$apply(function(){b.currentIndex++,M()}),ka&&(d=J(),I()<d.getBoundingClientRect().bottom&&L(H(d))))):c===k&&b.results?(a.preventDefault(),b.currentIndex>=1?(b.$apply(function(){b.currentIndex--,M()}),ka&&(e=K(),0>e&&L(e-1))):0===b.currentIndex&&b.$apply(function(){b.currentIndex=-1,da.val(b.searchStr)})):c===o&&(b.results&&b.results.length>0&&b.showDropdown?-1===b.currentIndex&&b.overrideSuggestions?G():(-1===b.currentIndex&&(b.currentIndex=0),b.selectResult(b.results[b.currentIndex]),b.$digest()):b.searchStr&&b.searchStr.length>0&&G())}function O(a){return function(c,d,e,f){d||e||f||(c=c.data),b.searching=!1,Y(C(_(c),b.remoteUrlDataField),a)}}function P(a,c,d,e){c||d||e||(c=a.status),0!==c&&(b.remoteUrlErrorCallback?b.remoteUrlErrorCallback(a,c,d,e):console&&console.error&&console.error("http error"))}function Q(){ia&&ia.resolve()}function R(d){var e={},f=b.remoteUrl+encodeURIComponent(d);b.remoteUrlRequestFormatter&&(e={params:b.remoteUrlRequestFormatter(d)},f=b.remoteUrl),b.remoteUrlRequestWithCredentials&&(e.withCredentials=!0),Q(),ia=a.defer(),e.timeout=ia.promise,c.get(f,e).success(O(d)).error(P)}function S(c){Q(),ia=a.defer(),b.remoteApiHandler(c,ia.promise).then(O(c))["catch"](P)}function T(){b.showDropdown=!1,b.results=[],ja&&(ja.scrollTop=0)}function U(){b.showDropdown=ba,b.currentIndex=-1,b.results=[]}function V(a){var c,d,e,f,g=b.searchFields.split(","),h=[];for(c=0;c<b.localData.length;c++){for(d=!1,e=0;e<g.length;e++)f=C(b.localData[c],g[e])||"",d=d||f.toString().toLowerCase().indexOf(a.toString().toLowerCase())>=0;d&&(h[h.length]=b.localData[c])}b.searching=!1,Y(h,a)}function W(a,c,d){if(d)for(var e in c)if(c[e].toLowerCase()===d.toLowerCase())return void b.selectResult(a)}function X(a){!a||a.length<ea||(b.localData?b.$apply(function(){V(a)}):b.remoteApiHandler?S(a):R(a))}function Y(a,c){var d,e,f,g,h,i;if(a&&a.length>0)for(b.results=[],d=0;d<a.length;d++)b.titleField&&""!==b.titleField&&(g=h=B(a[d])),e="",b.descriptionField&&(e=i=C(a[d],b.descriptionField)),f="",b.imageField&&(f=C(a[d],b.imageField)),b.matchClass&&(h=D(g,c),i=D(e,c)),b.results[b.results.length]={title:h,description:i,image:f,originalObject:a[d]},b.autoMatch&&W(b.results[b.results.length-1],{title:g,desc:e||""},b.searchStr);else b.results=[];0!==b.results.length||ca?b.showDropdown=!0:b.showDropdown=!1}function Z(){b.localData?Y(b.localData,""):b.remoteApiHandler?S(""):R("")}var $,_,aa,ba,ca,da=f.find("input"),ea=p,fa=null,ga=t,ha=null,ia=null,ja=f[0].querySelector(".angucomplete-dropdown"),ka=!1,la=null;f.on("mousedown",function(a){a.target.id?(la=a.target.id,la===b.id+"_dropdown"&&document.body.addEventListener("click",w)):la=a.target.className}),b.currentIndex=null,b.searching=!1,aa=b.$watch("initialValue",function(a,c){a&&(aa(),"object"==typeof a?(b.searchStr=B(a),y({originalObject:a})):"string"==typeof a&&a.length>0?b.searchStr=a:console&&console.error&&console.error("Tried to set initial value of angucomplete to",a,"which is an invalid value"),E(!0))}),b.$on("angucomplete-alt:clearInput",function(a,c){c&&c!==b.id||(b.searchStr=null,y(),E(!1),T())}),b.onFocusHandler=function(){b.focusIn&&b.focusIn(),0!==ea||b.searchStr&&0!==b.searchStr.length||(b.showDropdown=!0,Z())},b.hideResults=function(a){la&&(la===b.id+"_dropdown"||la.indexOf("angucomplete")>=0)?la=null:($=e(function(){T(),b.$apply(function(){b.searchStr&&b.searchStr.length>0&&da.val(b.searchStr)})},s),Q(),b.focusOut&&b.focusOut(),b.overrideSuggestions&&b.searchStr&&b.searchStr.length>0&&-1===b.currentIndex&&G())},b.resetHideResults=function(){$&&e.cancel($)},b.hoverRow=function(a){b.currentIndex=a},b.selectResult=function(a){b.matchClass&&(a.title=B(a.originalObject),a.description=C(a.originalObject,b.descriptionField)),b.clearSelected?b.searchStr=null:b.searchStr=a.title,y(a),T()},b.inputChangeHandler=function(a){return a.length<ea?T():0===a.length&&0===ea&&(b.searching=!1,Z()),b.inputChanged&&(a=b.inputChanged(a)),a},b.fieldRequiredClass&&""!==b.fieldRequiredClass&&(ga=b.fieldRequiredClass),b.minlength&&""!==b.minlength&&(ea=parseInt(b.minlength,10)),b.pause||(b.pause=r),b.clearSelected||(b.clearSelected=!1),b.overrideSuggestions||(b.overrideSuggestions=!1),b.fieldRequired&&h&&E(b.initialValue?!0:!1),b.inputType=g.type?g.type:"text",b.textSearching=g.textSearching?g.textSearching:u,b.textNoResults=g.textNoResults?g.textNoResults:v,ba="false"===b.textSearching?!1:!0,ca="false"===b.textNoResults?!1:!0,b.maxlength=g.maxlength?g.maxlength:q,da.on("keydown",N),da.on("keyup",F),_=z("remoteUrlResponseFormatter"),b.$on("$destroy",function(){E(!0)}),e(function(){var a=getComputedStyle(ja);ka=a.maxHeight&&"auto"===a.overflowY})}var i=40,j=39,k=38,l=37,m=27,n=13,o=9,p=3,q=524288,r=500,s=200,t="autocomplete-required",u="Searching...",v="No results found",w="/angucomplete-alt/index.html";return f.put(w,'<div class="angucomplete-holder" ng-class="{\'angucomplete-dropdown-visible\': showDropdown}">  <input id="{{id}}_value" name="{{inputName}}" ng-class="{\'angucomplete-input-not-empty\': notEmpty}" ng-model="searchStr" ng-disabled="disableInput" type="{{inputType}}" placeholder="{{placeholder}}" maxlength="{{maxlength}}" ng-focus="onFocusHandler()" class="{{inputClass}}" ng-focus="resetHideResults()" ng-blur="hideResults($event)" autocapitalize="off" autocorrect="off" autocomplete="off" ng-change="inputChangeHandler(searchStr)"/>  <div id="{{id}}_dropdown" class="angucomplete-dropdown" ng-show="showDropdown">    <div class="angucomplete-searching" ng-show="searching" ng-bind="textSearching"></div>    <div class="angucomplete-searching" ng-show="!searching && (!results || results.length == 0)" ng-bind="textNoResults"></div>    <div class="angucomplete-row" ng-repeat="result in results" ng-click="selectResult(result)" ng-mouseenter="hoverRow($index)" ng-class="{\'angucomplete-selected-row\': $index == currentIndex}">      <div ng-if="imageField" class="angucomplete-image-holder">        <img ng-if="result.image && result.image != \'\'" ng-src="{{result.image}}" class="angucomplete-image"/>        <div ng-if="!result.image && result.image != \'\'" class="angucomplete-image-default"></div>      </div>      <div class="angucomplete-title" ng-if="matchClass" ng-bind-html="result.title"></div>      <div class="angucomplete-title" ng-if="!matchClass">{{ result.title }}</div>      <div ng-if="matchClass && result.description && result.description != \'\'" class="angucomplete-description" ng-bind-html="result.description"></div>      <div ng-if="!matchClass && result.description && result.description != \'\'" class="angucomplete-description">{{result.description}}</div>    </div>  </div></div>'),{restrict:"EA",require:"^?form",scope:{selectedObject:"=",disableInput:"=",initialValue:"=",localData:"=",remoteUrlRequestFormatter:"=",remoteUrlRequestWithCredentials:"@",remoteUrlResponseFormatter:"=",remoteUrlErrorCallback:"=",remoteApiHandler:"=",id:"@",type:"@",placeholder:"@",remoteUrl:"@",remoteUrlDataField:"@",titleField:"@",descriptionField:"@",imageField:"@",inputClass:"@",pause:"@",searchFields:"@",minlength:"@",matchClass:"@",clearSelected:"@",overrideSuggestions:"@",fieldRequired:"@",fieldRequiredClass:"@",inputChanged:"=",autoMatch:"@",focusOut:"&",focusIn:"&",inputName:"@"},templateUrl:function(a,b){return b.templateUrl||w},compile:function(a,b){var c=g.startSymbol(),d=g.endSymbol();if("{{"!==c||"}}"!==d){var e=a.html().replace(/\{\{/g,c).replace(/\}\}/g,d);a.html(e)}return h}}}])});