diff --git a/.gitignore b/.gitignore
index 300c65d7..92a9877a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ node_modules
bower_components
.*.swp
.DS_Store
+.idea/
diff --git a/angucomplete-alt.js b/angucomplete-alt.js
index f9fdf83d..e98f6f05 100644
--- a/angucomplete-alt.js
+++ b/angucomplete-alt.js
@@ -45,23 +45,23 @@
// Set the default template for this directive
$templateCache.put(TEMPLATE_URL,
- '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '
{{ result.title }}
' +
- '
' +
- '
{{result.description}}
' +
- '
' +
- '
' +
- '
'
+ '' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
{{ result.title }}
' +
+ '
' +
+ '
{{result.description}}
' +
+ '
' +
+ '
' +
+ '
'
);
function link(scope, elem, attrs, ctrl) {
@@ -80,8 +80,140 @@
var unbindInitialValue;
var displaySearching;
var displayNoResults;
+ function extractValue(obj, key) {
+ var keys, result;
+ if (key) {
+ keys= key.split('.');
+ result = obj;
+ for (var i = 0; i < keys.length; i++) {
+ result = result[keys[i]];
+ }
+ }
+ else {
+ result = obj;
+ }
+ return result;
+ }
+ function extractTitle(data) {
+ // split title fields and run extractValue for each and join with ' '
+ return scope.titleField.split(',')
+ .map(function(field) {
+ return extractValue(data, field);
+ })
+ .join(' ');
+ }
+ function findMatchString(target, str) {
+ var result, matches, re;
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
+ // Escape user input to be treated as a literal string within a regular expression
+ re = new RegExp(str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
+ if (!target) { return; }
+ if (!target.match || !target.replace) { target = target.toString(); }
+ matches = target.match(re);
+ if (matches) {
+ result = target.replace(re,
+ ''+ matches[0] +'');
+ }
+ else {
+ result = target;
+ }
+ return $sce.trustAsHtml(result);
+ }
+ function checkExactMatch(result, obj, str){
+ if (!str) { return false; }
+ for(var key in obj){
+ if(obj[key].toLowerCase() === str.toLowerCase()){
+ scope.selectResult(result);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function processResults(responseData, str) {
+ var i, description, image, text, formattedText, formattedDesc;
+
+ if (responseData && responseData.length > 0) {
+ scope.results = [];
+
+ for (i = 0; i < responseData.length; i++) {
+ if (scope.titleField && scope.titleField !== '') {
+ text = formattedText = extractTitle(responseData[i]);
+ }
+
+ description = '';
+ if (scope.descriptionField) {
+ description = formattedDesc = extractValue(responseData[i], scope.descriptionField);
+ }
+
+ image = '';
+ if (scope.imageField) {
+ image = extractValue(responseData[i], scope.imageField);
+ }
+
+ if (scope.matchClass) {
+ formattedText = findMatchString(text, str);
+ formattedDesc = findMatchString(description, str);
+ }
+ scope.results[scope.results.length] = {
+ title: formattedText,
+ description: formattedDesc,
+ image: image,
+ originalObject: responseData[i]
+ };
+ }
+
+ } else {
+ scope.results = [];
+ }
+
+ if (scope.autoMatch && scope.results.length === 1 &&
+ checkExactMatch(scope.results[0],
+ {title: text, desc: description || ''}, scope.searchStr)) {
+ scope.showDropdown = false;
+ } else if (scope.results.length === 0 && !displayNoResults) {
+ scope.showDropdown = false;
+ } else {
+ scope.showDropdown = true;
+ }
+ }
+
+ function showAll() {
+ if (scope.localData) {
+ scope.searching = false;
+ processResults(scope.localData, '');
+ }
+ else if (scope.remoteApiHandler) {
+ scope.searching = true;
+ getRemoteResultsWithCustomHandler('');
+ }
+ else {
+ scope.searching = true;
+ getRemoteResults('');
+ }
+ }
+
+ elem.on('focusin',function(event){
+ if(scope.showDrop){
+ showAll();
+ //scope.inputChangeHandler('');
+ //showSelected();
+ if(scope.selectOnfocus){
+ $timeout(function(){
+ $(elem).find('input').select();
+ },0);
+ }
+ }
+ });
+ // #194 dropdown list not consistent in collapsing (bug).
+ function clickoutHandlerForDropdown(event) {
+ mousedownOn = null;
+ scope.hideResults(event);
+ document.body.removeEventListener('click', clickoutHandlerForDropdown);
+ }
elem.on('mousedown', function(event) {
+
if (event.target.id) {
mousedownOn = event.target.id;
if (mousedownOn === scope.id + '_dropdown') {
@@ -91,8 +223,80 @@
else {
mousedownOn = event.target.className;
}
+
+
});
+ function handleRequired(valid) {
+ scope.notEmpty = valid;
+ validState = scope.searchStr;
+ if (scope.fieldRequired && ctrl && scope.inputName) {
+ ctrl[scope.inputName].$setValidity(requiredClassName, valid);
+ }
+ }
+
+
+ function callOrAssign(value) {
+
+ scope.selectedResult = value;
+
+
+ if (typeof scope.selectedObject === 'function') {
+ scope.selectedObject(value, scope.selectedObjectData);
+ }
+ else {
+ scope.selectedObject = value;
+ }
+
+ if (value) {
+ handleRequired(true);
+ }
+ else {
+ handleRequired(false);
+ }
+ }
+
+ function clearResults() {
+ scope.showDropdown = false;
+ scope.results = [];
+ if (dd) {
+ dd.scrollTop = 0;
+ }
+ }
+
+
+
+ function setInputString(str) {
+ callOrAssign({originalObject: str});
+
+ if (scope.clearSelected) {
+ scope.searchStr = null;
+ }
+ clearResults();
+ }
+
+
+
+
+
+ function handleInputChange(newval, initial) {
+ if (newval) {
+ if (typeof newval === 'object') {
+ scope.searchStr = extractTitle(newval);
+ callOrAssign({originalObject: newval});
+ } else if (typeof newval === 'string' && newval.length > 0) {
+ scope.searchStr = newval;
+ } else {
+ if (console && console.error) {
+ console.error('Tried to set ' + (!!initial ? 'initial' : '') + ' value of angucomplete to', newval, 'which is an invalid value');
+ }
+ }
+
+ handleRequired(true);
+ }
+ }
+
+
scope.currentIndex = scope.focusFirst ? 0 : null;
scope.searching = false;
unbindInitialValue = scope.$watch('initialValue', function(newval) {
@@ -133,50 +337,13 @@
}
});
- function handleInputChange(newval, initial) {
- if (newval) {
- if (typeof newval === 'object') {
- scope.searchStr = extractTitle(newval);
- callOrAssign({originalObject: newval});
- } else if (typeof newval === 'string' && newval.length > 0) {
- scope.searchStr = newval;
- } else {
- if (console && console.error) {
- console.error('Tried to set ' + (!!initial ? 'initial' : '') + ' value of angucomplete to', newval, 'which is an invalid value');
- }
- }
-
- handleRequired(true);
- }
- }
- // #194 dropdown list not consistent in collapsing (bug).
- function clickoutHandlerForDropdown(event) {
- mousedownOn = null;
- scope.hideResults(event);
- document.body.removeEventListener('click', clickoutHandlerForDropdown);
- }
// for IE8 quirkiness about event.which
function ie8EventNormalizer(event) {
return event.which ? event.which : event.keyCode;
}
- function callOrAssign(value) {
- if (typeof scope.selectedObject === 'function') {
- scope.selectedObject(value, scope.selectedObjectData);
- }
- else {
- scope.selectedObject = value;
- }
-
- if (value) {
- handleRequired(true);
- }
- else {
- handleRequired(false);
- }
- }
function callFunctionOrIdentity(fn) {
return function(data) {
@@ -184,62 +351,115 @@
};
}
- function setInputString(str) {
- callOrAssign({originalObject: str});
- if (scope.clearSelected) {
- scope.searchStr = null;
+
+
+
+ function initResults() {
+ scope.showDropdown = displaySearching;
+ scope.currentIndex = scope.focusFirst ? 0 : -1;
+ scope.results = [];
+ }
+
+ function cancelHttpRequest() {
+ if (httpCanceller) {
+ httpCanceller.resolve();
}
- clearResults();
}
+ function httpSuccessCallbackGen(str) {
+ return function(responseData, status, headers, config) {
+ // normalize return obejct from promise
+ if (!status && !headers && !config && responseData.data) {
+ responseData = responseData.data;
+ }
+ scope.searching = false;
+ processResults(
+ extractValue(responseFormatter(responseData), scope.remoteUrlDataField),
+ str);
+ };
+ }
+ function httpErrorCallback(errorRes, status, headers, config) {
+ scope.searching = httpCallInProgress;
- function extractTitle(data) {
- // split title fields and run extractValue for each and join with ' '
- return scope.titleField.split(',')
- .map(function(field) {
- return extractValue(data, field);
- })
- .join(' ');
+ // normalize return obejct from promise
+ if (!status && !headers && !config) {
+ status = errorRes.status;
+ }
+
+ // cancelled/aborted
+ if (status === 0 || status === -1) { return; }
+ if (scope.remoteUrlErrorCallback) {
+ scope.remoteUrlErrorCallback(errorRes, status, headers, config);
+ }
+ else {
+ if (console && console.error) {
+ console.error('http error');
+ }
+ }
}
- function extractValue(obj, key) {
- var keys, result;
- if (key) {
- keys= key.split('.');
- result = obj;
- for (var i = 0; i < keys.length; i++) {
- result = result[keys[i]];
+ function getLocalResults(str) {
+ var i, match, s, value,
+ searchFields = scope.searchFields.split(','),
+ matches = [];
+ if (typeof scope.parseInput() !== 'undefined') {
+ str = scope.parseInput()(str);
+ }
+ for (i = 0; i < scope.localData.length; i++) {
+ match = false;
+
+ for (s = 0; s < searchFields.length; s++) {
+ value = extractValue(scope.localData[i], searchFields[s]) || '';
+ match = match || (value.toString().toLowerCase().indexOf(str.toString().toLowerCase()) >= 0);
+ }
+
+ if (match) {
+ matches[matches.length] = scope.localData[i];
}
}
- else {
- result = obj;
- }
- return result;
+ return matches;
}
-
- function findMatchString(target, str) {
- var result, matches, re;
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
- // Escape user input to be treated as a literal string within a regular expression
- re = new RegExp(str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
- if (!target) { return; }
- if (!target.match || !target.replace) { target = target.toString(); }
- matches = target.match(re);
- if (matches) {
- result = target.replace(re,
- ''+ matches[0] +'');
+ function getRemoteResults(str) {
+ var params = {},
+ url = scope.remoteUrl + encodeURIComponent(str);
+ if (scope.remoteUrlRequestFormatter) {
+ params = {params: scope.remoteUrlRequestFormatter(str)};
+ url = scope.remoteUrl;
}
- else {
- result = target;
+ if (!!scope.remoteUrlRequestWithCredentials) {
+ params.withCredentials = true;
}
- return $sce.trustAsHtml(result);
+ cancelHttpRequest();
+ httpCanceller = $q.defer();
+ params.timeout = httpCanceller.promise;
+ httpCallInProgress = true;
+ $http.get(url, params)
+ .success(httpSuccessCallbackGen(str))
+ .error(httpErrorCallback)
+ .finally(function(){httpCallInProgress=false;});
}
- function handleRequired(valid) {
- scope.notEmpty = valid;
- validState = scope.searchStr;
- if (scope.fieldRequired && ctrl && scope.inputName) {
- ctrl[scope.inputName].$setValidity(requiredClassName, valid);
+ function searchTimerComplete(str) {
+ // Begin the search
+ if (!str || str.length < minlength) {
+ return;
+ }
+ if (scope.localData) {
+ scope.$apply(function() {
+ var matches;
+ if (typeof scope.localSearch() !== 'undefined') {
+ matches = scope.localSearch()(str, scope.localData);
+ } else {
+ matches = getLocalResults(str);
+ }
+ scope.searching = false;
+ processResults(matches, str);
+ });
+ }
+ else if (scope.remoteApiHandler) {
+ getRemoteResultsWithCustomHandler(str);
+ } else {
+ getRemoteResults(str);
}
}
@@ -296,9 +516,11 @@
}
}
+
+
function handleOverrideSuggestions(event) {
if (scope.overrideSuggestions &&
- !(scope.selectedObject && scope.selectedObject.originalObject === scope.searchStr)) {
+ !(scope.selectedObject && scope.selectedObject.originalObject === scope.searchStr)) {
if (event) {
event.preventDefault();
}
@@ -330,7 +552,7 @@
function dropdownRowTop() {
return dropdownRow().getBoundingClientRect().top -
(dd.getBoundingClientRect().top +
- parseInt(getComputedStyle(dd).paddingTop, 10));
+ parseInt(getComputedStyle(dd).paddingTop, 10));
}
function dropdownScrollTopTo(offset) {
@@ -427,221 +649,45 @@
}
}
- function httpSuccessCallbackGen(str) {
- return function(responseData, status, headers, config) {
- // normalize return obejct from promise
- if (!status && !headers && !config && responseData.data) {
- responseData = responseData.data;
- }
- scope.searching = false;
- processResults(
- extractValue(responseFormatter(responseData), scope.remoteUrlDataField),
- str);
- };
- }
- function httpErrorCallback(errorRes, status, headers, config) {
- scope.searching = httpCallInProgress;
- // normalize return obejct from promise
- if (!status && !headers && !config) {
- status = errorRes.status;
- }
- // cancelled/aborted
- if (status === 0 || status === -1) { return; }
- if (scope.remoteUrlErrorCallback) {
- scope.remoteUrlErrorCallback(errorRes, status, headers, config);
- }
- else {
- if (console && console.error) {
- console.error('http error');
- }
- }
- }
- function cancelHttpRequest() {
- if (httpCanceller) {
- httpCanceller.resolve();
- }
- }
- function getRemoteResults(str) {
- var params = {},
- url = scope.remoteUrl + encodeURIComponent(str);
- if (scope.remoteUrlRequestFormatter) {
- params = {params: scope.remoteUrlRequestFormatter(str)};
- url = scope.remoteUrl;
- }
- if (!!scope.remoteUrlRequestWithCredentials) {
- params.withCredentials = true;
- }
- cancelHttpRequest();
- httpCanceller = $q.defer();
- params.timeout = httpCanceller.promise;
- httpCallInProgress = true;
- $http.get(url, params)
- .then(httpSuccessCallbackGen(str))
- .catch(httpErrorCallback)
- .finally(function(){httpCallInProgress=false;});
- }
- function getRemoteResultsWithCustomHandler(str) {
- cancelHttpRequest();
- httpCanceller = $q.defer();
- scope.remoteApiHandler(str, httpCanceller.promise)
- .then(httpSuccessCallbackGen(str))
- .catch(httpErrorCallback);
- /* IE8 compatible
- scope.remoteApiHandler(str, httpCanceller.promise)
- ['then'](httpSuccessCallbackGen(str))
- ['catch'](httpErrorCallback);
- */
- }
- function clearResults() {
- scope.showDropdown = false;
- scope.results = [];
- if (dd) {
- dd.scrollTop = 0;
- }
- }
- function initResults() {
- scope.showDropdown = displaySearching;
- scope.currentIndex = scope.focusFirst ? 0 : -1;
- scope.results = [];
- }
- function getLocalResults(str) {
- var i, match, s, value,
- searchFields = scope.searchFields.split(','),
- matches = [];
- if (typeof scope.parseInput() !== 'undefined') {
- str = scope.parseInput()(str);
- }
- for (i = 0; i < scope.localData.length; i++) {
- match = false;
+ //TODO: selected object to show on focus not completed yet
- for (s = 0; s < searchFields.length; s++) {
- value = extractValue(scope.localData[i], searchFields[s]) || '';
- match = match || (value.toString().toLowerCase().indexOf(str.toString().toLowerCase()) >= 0);
- }
+ function showSelected(){
+ var se = scope.selectedResult.originalObject;
- if (match) {
- matches[matches.length] = scope.localData[i];
- }
- }
- return matches;
- }
- function checkExactMatch(result, obj, str){
- if (!str) { return false; }
- for(var key in obj){
- if(obj[key].toLowerCase() === str.toLowerCase()){
- scope.selectResult(result);
- return true;
+ for(var i = scope.localData.length-1 ; i >= 0;i--){
+ var item = scope.localData[i];
+ if(item[scope.searchFields] === scope.selectedResult.originalObject[scope.searchFields]){
+ scope.selectedObjectToShow = item;
}
- }
- return false;
- }
- function searchTimerComplete(str) {
- // Begin the search
- if (!str || str.length < minlength) {
- return;
- }
- if (scope.localData) {
- scope.$apply(function() {
- var matches;
- if (typeof scope.localSearch() !== 'undefined') {
- matches = scope.localSearch()(str, scope.localData);
- } else {
- matches = getLocalResults(str);
- }
- scope.searching = false;
- processResults(matches, str);
- });
- }
- else if (scope.remoteApiHandler) {
- getRemoteResultsWithCustomHandler(str);
- } else {
- getRemoteResults(str);
}
- }
-
- function processResults(responseData, str) {
- var i, description, image, text, formattedText, formattedDesc;
- if (responseData && responseData.length > 0) {
- scope.results = [];
-
- for (i = 0; i < responseData.length; i++) {
- if (scope.titleField && scope.titleField !== '') {
- text = formattedText = extractTitle(responseData[i]);
- }
-
- description = '';
- if (scope.descriptionField) {
- description = formattedDesc = extractValue(responseData[i], scope.descriptionField);
- }
-
- image = '';
- if (scope.imageField) {
- image = extractValue(responseData[i], scope.imageField);
- }
-
- if (scope.matchClass) {
- formattedText = findMatchString(text, str);
- formattedDesc = findMatchString(description, str);
- }
-
- scope.results[scope.results.length] = {
- title: formattedText,
- description: formattedDesc,
- image: image,
- originalObject: responseData[i]
- };
- }
-
- } else {
- scope.results = [];
- }
- if (scope.autoMatch && scope.results.length === 1 &&
- checkExactMatch(scope.results[0],
- {title: text, desc: description || ''}, scope.searchStr)) {
- scope.showDropdown = false;
- } else if (scope.results.length === 0 && !displayNoResults) {
- scope.showDropdown = false;
- } else {
- scope.showDropdown = true;
- }
}
- function showAll() {
- if (scope.localData) {
- scope.searching = false;
- processResults(scope.localData, '');
- }
- else if (scope.remoteApiHandler) {
- scope.searching = true;
- getRemoteResultsWithCustomHandler('');
- }
- else {
- scope.searching = true;
- getRemoteResults('');
- }
- }
scope.onFocusHandler = function() {
+
+
if (scope.focusIn) {
+
scope.focusIn();
}
if (minlength === 0 && (!scope.searchStr || scope.searchStr.length === 0)) {
+
scope.currentIndex = scope.focusFirst ? 0 : scope.currentIndex;
scope.showDropdown = true;
showAll();
@@ -650,8 +696,8 @@
scope.hideResults = function() {
if (mousedownOn &&
- (mousedownOn === scope.id + '_dropdown' ||
- mousedownOn.indexOf('angucomplete') >= 0)) {
+ (mousedownOn === scope.id + '_dropdown' ||
+ mousedownOn.indexOf('angucomplete') >= 0)) {
mousedownOn = null;
}
else {
@@ -705,6 +751,9 @@
};
scope.inputChangeHandler = function(str) {
+
+
+
if (str.length < minlength) {
cancelHttpRequest();
clearResults();
@@ -784,6 +833,7 @@
restrict: 'EA',
require: '^?form',
scope: {
+
selectedObject: '=',
selectedObjectData: '=',
disableInput: '=',
@@ -821,7 +871,10 @@
fieldTabindex: '@',
inputName: '@',
focusFirst: '@',
- parseInput: '&'
+ parseInput: '&',
+ showDrop : "@",
+ selectOnfocus : "="
+
},
templateUrl: function(element, attrs) {
return attrs.templateUrl || TEMPLATE_URL;
diff --git a/bower.json b/bower.json
index 49e6eaf8..f5c91268 100644
--- a/bower.json
+++ b/bower.json
@@ -1,9 +1,9 @@
{
- "name": "angucomplete-alt",
- "version": "3.0.0",
- "homepage": "http://ghiden.github.io/angucomplete-alt/",
+ "name": "angucomplete-mr",
+ "version": "3.1.0",
+ "homepage": "https://github.com/moryrasb/angucomplete-alt",
"authors": [
- "Hidenari Nozaki "
+ "Hidenari Nozaki ","Morteza Rezaee "
],
"description": "Autocomplete directive for AngularJS",
"keywords": [
@@ -13,8 +13,8 @@
],
"license": "MIT",
"main": [
- "./angucomplete-alt.js",
- "./angucomplete-alt.css"
+ "./angucomplete-alt.js",
+ "./angucomplete-alt.css"
],
"ignore": [
"example",
@@ -25,7 +25,8 @@
"tests"
],
"dependencies": {
- "angular": ">=1.6.0"
+ "angular": ">=1.6.0",
+ "angucomplete-alt": "angucomplete-mr#^3.0.0"
},
"devDependencies": {
"angular-mocks": ">=1.6.0",
diff --git a/dist/angucomplete-alt.min.js b/dist/angucomplete-alt.min.js
index d83180b8..a21f66c9 100644
--- a/dist/angucomplete-alt.min.js
+++ b/dist/angucomplete-alt.min.js
@@ -1,2 +1,2 @@
/*! Copyright (c) 2014 Hidenari Nozaki and contributors | Licensed under the MIT license */
-!function(a,b){"use strict";"undefined"!=typeof module&&module.exports?module.exports=b(require("angular")):"function"==typeof define&&define.amd?define(["angular"],b):b(a.angular)}(window,function(a){"use strict";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,c){a&&("object"==typeof a?(b.searchStr=C(a),z({originalObject:a})):"string"==typeof a&&a.length>0?b.searchStr=a:console&&console.error&&console.error("Tried to set "+(c?"initial":"")+" value of angucomplete to",a,"which is an invalid value"),F(!0))}function x(a){na=null,b.hideResults(a),document.body.removeEventListener("click",x)}function y(a){return a.which?a.which:a.keyCode}function z(a){"function"==typeof b.selectedObject?b.selectedObject(a,b.selectedObjectData):b.selectedObject=a,F(a?!0:!1)}function A(a){return function(c){return b[a]?b[a](c):c}}function B(a){z({originalObject:a}),b.clearSelected&&(b.searchStr=null),U()}function C(a){return b.titleField.split(",").map(function(b){return D(a,b)}).join(" ")}function D(a,b){var c,d;if(b){c=b.split("."),d=a;for(var e=0;e'+f[0]+""):a,d.trustAsHtml(e)}function F(a){b.notEmpty=a,ia=b.searchStr,b.fieldRequired&&h&&b.inputName&&h[b.inputName].$setValidity(ha,a)}function G(a){var c=y(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>=fa&&(V(),b.searching=!0,Y(b.searchStr));else if(c===m)U(),b.$apply(function(){ea.val(b.searchStr)});else{if(0===fa&&!b.searchStr)return;b.searchStr&&""!==b.searchStr?b.searchStr.length>=fa&&(V(),ga&&e.cancel(ga),b.searching=!0,ga=e(function(){Y(b.searchStr)},b.pause)):b.showDropdown=!1,ia&&ia!==b.searchStr&&!b.clearSelected&&b.$apply(function(){z()})}}function H(a){!b.overrideSuggestions||b.selectedObject&&b.selectedObject.originalObject===b.searchStr||(a&&a.preventDefault(),e.cancel(ga),R(),B(b.searchStr))}function I(a){var b=getComputedStyle(a);return a.offsetHeight+parseInt(b.marginTop,10)+parseInt(b.marginBottom,10)}function J(){return la.getBoundingClientRect().top+parseInt(getComputedStyle(la).maxHeight,10)}function K(){return f[0].querySelectorAll(".angucomplete-row")[b.currentIndex]}function L(){return K().getBoundingClientRect().top-(la.getBoundingClientRect().top+parseInt(getComputedStyle(la).paddingTop,10))}function M(a){la.scrollTop=la.scrollTop+a}function N(){var a=b.results[b.currentIndex];b.matchClass?ea.val(C(a.originalObject)):ea.val(a.title)}function O(a){var c=y(a),d=null,e=null;c===n&&b.results?(b.currentIndex>=0&&b.currentIndex=1?(b.$apply(function(){b.currentIndex--,N()}),ma&&(e=L(),e<0&&M(e-1))):0===b.currentIndex&&b.$apply(function(){b.currentIndex=-1,ea.val(b.searchStr)})):c===o?b.results&&b.results.length>0&&b.showDropdown?b.currentIndex===-1&&b.overrideSuggestions?H():(b.currentIndex===-1&&(b.currentIndex=0),b.selectResult(b.results[b.currentIndex]),b.$digest()):b.searchStr&&b.searchStr.length>0&&H():c===m&&a.preventDefault()}function P(a){return function(c,d,e,f){d||e||f||!c.data||(c=c.data),b.searching=!1,Z(D(aa(c),b.remoteUrlDataField),a)}}function Q(a,c,d,e){b.searching=ka,c||d||e||(c=a.status),0!==c&&c!==-1&&(b.remoteUrlErrorCallback?b.remoteUrlErrorCallback(a,c,d,e):console&&console.error&&console.error("http error"))}function R(){ja&&ja.resolve()}function S(d){var e={},f=b.remoteUrl+encodeURIComponent(d);b.remoteUrlRequestFormatter&&(e={params:b.remoteUrlRequestFormatter(d)},f=b.remoteUrl),b.remoteUrlRequestWithCredentials&&(e.withCredentials=!0),R(),ja=a.defer(),e.timeout=ja.promise,ka=!0,c.get(f,e).then(P(d)).catch(Q).finally(function(){ka=!1})}function T(c){R(),ja=a.defer(),b.remoteApiHandler(c,ja.promise).then(P(c)).catch(Q)}function U(){b.showDropdown=!1,b.results=[],la&&(la.scrollTop=0)}function V(){b.showDropdown=ca,b.currentIndex=b.focusFirst?0:-1,b.results=[]}function W(a){var c,d,e,f,g=b.searchFields.split(","),h=[];for("undefined"!=typeof b.parseInput()&&(a=b.parseInput()(a)),c=0;c=0;d&&(h[h.length]=b.localData[c])}return h}function X(a,c,d){if(!d)return!1;for(var e in c)if(c[e].toLowerCase()===d.toLowerCase())return b.selectResult(a),!0;return!1}function Y(a){!a||a.length0)for(b.results=[],d=0;d=0)?na=null:(_=e(function(){U(),b.$apply(function(){b.searchStr&&b.searchStr.length>0&&ea.val(b.searchStr)})},s),R(),b.focusOut&&b.focusOut(),b.overrideSuggestions&&b.searchStr&&b.searchStr.length>0&&b.currentIndex===-1&&H())},b.resetHideResults=function(){_&&e.cancel(_)},b.hoverRow=function(a){b.currentIndex=a},b.selectResult=function(a){b.matchClass&&(a.title=C(a.originalObject),a.description=D(a.originalObject,b.descriptionField)),b.clearSelected?b.searchStr=null:b.searchStr=a.title,z(a),U()},b.inputChangeHandler=function(a){return a.length {{ result.title }}
{{result.description}}
'),{restrict:"EA",require:"^?form",scope:{selectedObject:"=",selectedObjectData:"=",disableInput:"=",initialValue:"=",localData:"=",localSearch:"&",remoteUrlRequestFormatter:"=",remoteUrlRequestWithCredentials:"@",remoteUrlResponseFormatter:"=",remoteUrlErrorCallback:"=",remoteApiHandler:"=",id:"@",type:"@",placeholder:"@",textSearching:"@",textNoResults:"@",remoteUrl:"@",remoteUrlDataField:"@",titleField:"@",descriptionField:"@",imageField:"@",inputClass:"@",pause:"@",searchFields:"@",minlength:"@",matchClass:"@",clearSelected:"@",overrideSuggestions:"@",fieldRequired:"=",fieldRequiredClass:"@",inputChanged:"=",autoMatch:"@",focusOut:"&",focusIn:"&",fieldTabindex:"@",inputName:"@",focusFirst:"@",parseInput:"&"},templateUrl:function(a,b){return b.templateUrl||w},compile:function(a){var b=g.startSymbol(),c=g.endSymbol();if("{{"!==b||"}}"!==c){var d=a.html().replace(/\{\{/g,b).replace(/\}\}/g,c);a.html(d)}return h}}}])});
\ No newline at end of file
+!function(a,b){"use strict";"undefined"!=typeof module&&module.exports?module.exports=b(require("angular")):"function"==typeof define&&define.amd?define(["angular"],b):b(a.angular)}(window,function(a){"use strict";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,c){a&&("object"==typeof a?(b.searchStr=C(a),z({originalObject:a})):"string"==typeof a&&a.length>0?b.searchStr=a:console&&console.error&&console.error("Tried to set "+(c?"initial":"")+" value of angucomplete to",a,"which is an invalid value"),F(!0))}function x(a){ma=null,b.hideResults(a),document.body.removeEventListener("click",x)}function y(a){return a.which?a.which:a.keyCode}function z(a){"function"==typeof b.selectedObject?b.selectedObject(a,b.selectedObjectData):b.selectedObject=a,F(a?!0:!1)}function A(a){return function(c){return b[a]?b[a](c):c}}function B(a){z({originalObject:a}),b.clearSelected&&(b.searchStr=null),U()}function C(a){return b.titleField.split(",").map(function(b){return D(a,b)}).join(" ")}function D(a,b){var c,d;if(b){c=b.split("."),d=a;for(var e=0;e'+f[0]+""):a,d.trustAsHtml(e)):void 0}function F(a){b.notEmpty=a,ia=b.searchStr,b.fieldRequired&&h&&b.inputName&&h[b.inputName].$setValidity(ha,a)}function G(a){var c=y(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>=fa&&(V(),b.searching=!0,Y(b.searchStr));else if(c===m)U(),b.$apply(function(){ea.val(b.searchStr)});else{if(0===fa&&!b.searchStr)return;b.searchStr&&""!==b.searchStr?b.searchStr.length>=fa&&(V(),ga&&e.cancel(ga),b.searching=!0,ga=e(function(){Y(b.searchStr)},b.pause)):b.showDropdown=!1,ia&&ia!==b.searchStr&&!b.clearSelected&&b.$apply(function(){z()})}}function H(a){!b.overrideSuggestions||b.selectedObject&&b.selectedObject.originalObject===b.searchStr||(a&&a.preventDefault(),e.cancel(ga),R(),B(b.searchStr))}function I(a){var b=getComputedStyle(a);return a.offsetHeight+parseInt(b.marginTop,10)+parseInt(b.marginBottom,10)}function J(){return ka.getBoundingClientRect().top+parseInt(getComputedStyle(ka).maxHeight,10)}function K(){return f[0].querySelectorAll(".angucomplete-row")[b.currentIndex]}function L(){return K().getBoundingClientRect().top-(ka.getBoundingClientRect().top+parseInt(getComputedStyle(ka).paddingTop,10))}function M(a){ka.scrollTop=ka.scrollTop+a}function N(){var a=b.results[b.currentIndex];b.matchClass?ea.val(C(a.originalObject)):ea.val(a.title)}function O(a){var c=y(a),d=null,e=null;c===n&&b.results?(b.currentIndex>=0&&b.currentIndex=1?(b.$apply(function(){b.currentIndex--,N()}),la&&(e=L(),0>e&&M(e-1))):0===b.currentIndex&&b.$apply(function(){b.currentIndex=-1,ea.val(b.searchStr)})):c===o?b.results&&b.results.length>0&&b.showDropdown?-1===b.currentIndex&&b.overrideSuggestions?H():(-1===b.currentIndex&&(b.currentIndex=0),b.selectResult(b.results[b.currentIndex]),b.$digest()):b.searchStr&&b.searchStr.length>0&&H():c===m&&a.preventDefault()}function P(a){return function(c,d,e,f){d||e||f||!c.data||(c=c.data),b.searching=!1,Z(D(aa(c),b.remoteUrlDataField),a)}}function Q(a,c,d,e){b.searching=!1,0!==c&&-1!==c&&(c||d||e||(c=a.status),b.remoteUrlErrorCallback?b.remoteUrlErrorCallback(a,c,d,e):console&&console.error&&console.error("http error"))}function R(){ja&&ja.resolve()}function S(d){var e={},f=b.remoteUrl+encodeURIComponent(d);b.remoteUrlRequestFormatter&&(e={params:b.remoteUrlRequestFormatter(d)},f=b.remoteUrl),b.remoteUrlRequestWithCredentials&&(e.withCredentials=!0),R(),ja=a.defer(),e.timeout=ja.promise,c.get(f,e).success(P(d)).error(Q)}function T(c){R(),ja=a.defer(),b.remoteApiHandler(c,ja.promise).then(P(c))["catch"](Q)}function U(){b.showDropdown=!1,b.results=[],ka&&(ka.scrollTop=0)}function V(){b.showDropdown=ca,b.currentIndex=b.focusFirst?0:-1,b.results=[]}function W(a){var c,d,e,f,g=b.searchFields.split(","),h=[];for("undefined"!=typeof b.parseInput()&&(a=b.parseInput()(a)),c=0;c=0;d&&(h[h.length]=b.localData[c])}return h}function X(a,c,d){if(!d)return!1;for(var e in c)if(c[e].toLowerCase()===d.toLowerCase())return b.selectResult(a),!0;return!1}function Y(a){!a||a.length0)for(b.results=[],d=0;d=0)?ma=null:(_=e(function(){U(),b.$apply(function(){b.searchStr&&b.searchStr.length>0&&ea.val(b.searchStr)})},s),R(),b.focusOut&&b.focusOut(),b.overrideSuggestions&&b.searchStr&&b.searchStr.length>0&&-1===b.currentIndex&&H())},b.resetHideResults=function(){_&&e.cancel(_)},b.hoverRow=function(a){b.currentIndex=a},b.selectResult=function(a){b.matchClass&&(a.title=C(a.originalObject),a.description=D(a.originalObject,b.descriptionField)),b.clearSelected?b.searchStr=null:b.searchStr=a.title,z(a),U()},b.inputChangeHandler=function(a){return a.length {{ result.title }}
{{result.description}}
'),{restrict:"EA",require:"^?form",scope:{selectedObject:"=",selectedObjectData:"=",disableInput:"=",initialValue:"=",localData:"=",localSearch:"&",remoteUrlRequestFormatter:"=",remoteUrlRequestWithCredentials:"@",remoteUrlResponseFormatter:"=",remoteUrlErrorCallback:"=",remoteApiHandler:"=",id:"@",type:"@",placeholder:"@",textSearching:"@",textNoResults:"@",remoteUrl:"@",remoteUrlDataField:"@",titleField:"@",descriptionField:"@",imageField:"@",inputClass:"@",pause:"@",searchFields:"@",minlength:"@",matchClass:"@",clearSelected:"@",overrideSuggestions:"@",fieldRequired:"=",fieldRequiredClass:"@",inputChanged:"=",autoMatch:"@",focusOut:"&",focusIn:"&",fieldTabindex:"@",inputName:"@",focusFirst:"@",parseInput:"&"},templateUrl:function(a,b){return b.templateUrl||w},compile:function(a){var b=g.startSymbol(),c=g.endSymbol();if("{{"!==b||"}}"!==c){var d=a.html().replace(/\{\{/g,b).replace(/\}\}/g,c);a.html(d)}return h}}}])});