<NME> jquery.flexdatalist.min.js
<BEF> jQuery.fn.flexdatalist=function(e,t){"use strict";var i,a=$(document),s=$(this),l=this;if(i=function(){var t,i,a=$(this),s={},r="",n=null;a.attr("name");a.hasClass("flexdatalist-set")&&l._destroy(a),l._options(a,$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"],searchContain:!1,searchEqual:!1,searchByWord:!1,searchDisabled:!1,searchDelay:200,normalizeString:null,multiple:a.is("[multiple]"),maxShownResults:100,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,allowDuplicateValues:!1,requestType:"get",limitOfValues:0,valuesSeparator:",",_values:[]},a.data(),"object"==typeof e?e:{})),a._options=function(e,t){return l._options(a,e,t)},t=a.clone(!1).attr({list:null,name:null,id:a.attr("id")?a.attr("id")+"-flexdatalist":null}).addClass("flexdatalist-alias").removeClass("flexdatalist"),a._options("multiple")?(i=$("<ul>").addClass("flexdatalist-multiple").css({"border-color":a.css("border-left-color"),"border-width":a.css("border-left-width"),"border-style":a.css("border-left-style"),"border-radius":a.css("border-top-left-radius"),"background-color":a.css("background-color")}).insertAfter(a).click(function(){$(this).find("input").focus()}),$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(t).appendTo(i)):t.insertAfter(a),t.attr("autofocus")&&t.focus(),a._init=function(){var e=a._options();t.on("input keydown",function(i){var s=a._keyword();188!==l._keyNum(i)&&13!==l._keyNum(i)||e.selectionRequired||!e.multiple||a._resultSelected()?9===l._keyNum(i)?a._removeResults():0===s.length&&e.multiple&&8===l._keyNum(i)&&t.data("_remove",t.parents("li:eq(0)").prev()):(i.preventDefault(),a._value(s),a._removeResults())}).on("input keyup",function(i){if(a._changed()&&13!==l._keyNum(i)){var s=a._keyword();e.multiple||(e._values=[],e.selectionRequired?a._value(""):a._value(s)),s.length>=e.minLength?(clearTimeout(n),n=setTimeout(function(){a._search(function(e){a._showResults(e)})},e.searchDelay)):a._removeResults()}var o=t.data("_remove");o&&(o.find(".fdl-remove").click(),t.data("_remove",null)),r=a._keyword()}).on("focus",function(){var t=a._keyword();0===e.minLength?""===t&&a._tdata(function(e){a._showResults(e)}):t.length>=e.minLength&&!a._selected()&&a._search(function(e){a._showResults(e)})}).on("focusin",function(){a.parent().find(".flexdatalist-multiple").addClass("focus")}).on("focusout",function(){a.parent().find(".flexdatalist-multiple").removeClass("focus")}).on("blur",function(){a._resultSelected()||!e.multiple||e.selectionRequired||a._value(a._keyword())}).attr("autocomplete","off"),window.onresize=function(){a._position()},a.addClass("flexdatalist flexdatalist-set").prop("type","hidden")},a._resultSelected=function(){return $("ul.flexdatalist-results").find("li.item.active").length>0},a._changed=function(){return r!==a._keyword()},a._chained=function(){var e=a._options();if(e.relatives&&e.chainedRelatives){var r=function(s){e.relatives.each(function(){var r=l._isEmpty($(this).val()),n=l._isEmpty(a.val());t.prop("disabled",r),s||!r&&n||(a._value(""),t.val(""),e.multiple&&i.find("li .fdl-remove").click()),i&&(r&&i?i.addClass("disabled"):i.removeClass("disabled"))})};e.relatives.on("change",function(){r(),s={}}),r(!0)}},a._initValue=function(){var e=a.attr("value");l._isEmpty(e)||(a._options("originalValue",a.val()),a._options("searchEqual",!0),a._parseValue(e,function(e){a.val("",!0),t.val(""),a._options("searchEqual",!1),l._isEmpty(e)||a._values(e,!0),r=a._keyword()}))},a._parseValue=function(e,t){var i=a._options();if(a._toJSON())try{t(JSON.parse(e))}catch(s){}else if(a._toCSV()||"string"==typeof i.valueProperty){var l=e.split(i.valuesSeparator);if("string"==typeof i.valueProperty){var r=i.searchIn;i.searchIn=i.valueProperty.split(","),i.searchEqual=!0,a._search(function(e){e.length>0&&t(e),i.searchIn=r,i.searchEqual=!1},l)}else t(l)}else t(e)},a._tdata=function(e){a.trigger("before:flexdatalist.data"),a._url(function(t){a._data(function(i){i=i.concat(t);for(var s=a._options("_values"),l=0;l<i.length;l++){var r=i[l];s&&s.indexOf(a._getText(r))>-1&&delete i[l]}a.trigger("after:flexdatalist.data",[i]),e(i)})})},a._data=function(e){var t=a._options();"string"==typeof t.data?a._remote({url:t.data,success:function(i){var s=a._getRemoteData(i);t.data=s,e(s)}}):e(t.data)},a._url=function(e){var t=a._options(),i=a._keyword(),s=a.val(),r=i;if(l._isEmpty(t.url))return e([]);t.cache&&2!==t.cache&&(r=i.substring(0,t.minLength>0?t.minLength:1));var n=a._cache(r);if(n&&t.cache)return void e(n);var o={};"post"==t.requestType&&($.each(t,function(e,t){0!=e.indexOf("_")&&(o[e]=t)}),delete o.relatives),a._remote({url:t.url,data:$.extend(a._relativesData(),t.params,{keyword:i,contain:t.searchContain,selected:s,options:o}),success:function(t){var s=a._getRemoteData(t),l=a._keyword();l.length>=i.length&&e(s),a._cache(r,s)}})},a._remote=function(e){a.hasClass("flexdatalist-loading")||(a.addClass("flexdatalist-loading"),e=$.extend({type:a._options("requestType"),dataType:"json",complete:function(){a.removeClass("flexdatalist-loading")}},e),$.ajax(e))},a._getRemoteData=function(e){var t=e.results?e.results:e;return"string"==typeof t&&0===t.indexOf("[{")&&(t=JSON.parse(t)),t.options&&l._options(a,t.options),l._isObject(t)?t:[]},a._relativesData=function(){var e=a._options("relatives"),t={};return e&&(t.relatives={},e.each(function(){var e=$(this),i=e.attr("name").split("][").join("-").split("]").join("-").split("[").join("-").replace(/^\|+|\-+$/g,"");t.relatives[i]=e.val()})),t},a._datalist=function(){var e=a._options(),t=a.attr("list");return l._isEmpty(t)||(e.data=[],$("#"+t).find("option").each(function(){var t=$(this),i=t.val(),a=t.text();e.data.push({label:a.length>0?a:i,value:i})})),a},a._cache=function(e,t){if(a._options("cache")){if(e=a._normalizeString(e),!l._isDefined(t))return l._isDefined(s,e)&&(t=s[e]),t;s[e]=t}return null},a._search=function(e,t){a._tdata(function(i){var s=[],r=a._options();if(r.searchDisabled)return e(i);l._isDefined(t)||(t=a._keyword()),a.trigger("before:flexdatalist.search",[t,i]),t=a._split(t);for(var n=0;n<i.length;n++){var o=a._matches(i[n],t);o&&s.push(o)}a.trigger("after:flexdatalist.search",[t,i,s]),e(s)})},a._matches=function(e,t){var i=$.extend({},e),s=a._options(),r=[],n=s.searchIn;if(t.length>0)for(var o=0;o<n.length;o++){var u=n[o];if(l._isDefined(e,u)&&e[u]){for(var f=e[u].toString(),d=f,c=a._split(f),p=0;p<t.length;p++){var _=t[p];a._find(_,c)&&(r.push(_),d=a._highlight(_,d))}d!==f&&(i[u+"_highlight"]=a._highlight(d))}}return 0===r.length||s.searchByWord&&r.length<t.length-1?!1:i},a._highlight=function(e,t){return t?t.replace(new RegExp(e,a._options("searchContain")?"ig":"i"),"|:|$&|::|"):(e=e.split("|:|").join('<span class="highlight">'),e.split("|::|").join("</span>"))},a._find=function(e,t){for(var i=a._options(),s=0;s<t.length;s++){var l=t[s];if(l=a._normalizeString(l),e=a._normalizeString(e),i.searchEqual)return l==e;if(i.searchContain?l.indexOf(e)>=0:0===l.indexOf(e))return!0}return!1},a._split=function(e){"string"==typeof e&&(e=[$.trim(e)]);var t=a._options();if(t.searchByWord)for(var i=0;i<e.length;i++){var s=$.trim(e[i]);if(s.indexOf(" ")>0){var l=s.split(" ");$.merge(e,l)}}return e},a._showResults=function(e){a._removeResults(!0);var t=a._options();if(0===e.length)return void a._noResults(t.noResultsText);var i=a._getResultsContainer();t.groupBy?(e=a._groupData(e),Object.keys(e).forEach(function(s){var l=e[s],r=t.groupBy,n=a._getHighlight(l[0],r,s);$("<li>").addClass("group").append($("<span>").addClass("group-name").html(n)).append($("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(i);a._items(l,i)})):a._items(e,i);var s=i.find("li:not(.group)");s.on("click",function(){var e=$(this).data("item");e&&(a._selected(!0)._removeResults()._value(e),a.trigger("select:flexdatalist",[e,t]))}).hover(function(){s.removeClass("active"),$(this).addClass("active")},function(){$(this).removeClass("active")}),t.focusFirstResult&&s.filter(":first").addClass("active")},a._noResults=function(e){if(!l._isEmpty(e)){var t=a._getResultsContainer(),i=a._keyword();e=e.split("{keyword}").join(i),$("<li>").addClass("item no-results").append(e).appendTo(t)}},a._groupData=function(e){for(var t=[],i=a._options("groupBy"),s=0;s<e.length;s++){var r=e[s];if(l._isDefined(r,i)){var n=r[i];l._isDefined(t,n)||(t[n]=[]),t[n].push(r)}}return t},a._items=function(e,t){var i=a._options("maxShownResults");a.trigger("show:flexdatalist.results",[e]);for(var s=0;s<e.length&&!(i>0&&i===s);s++)a._item(e[s]).appendTo(t);a.trigger("shown:flexdatalist.results",[e])},a._item=function(e){for(var t=$("<li>").data("item",e).addClass("item"),i=a._options(),s=i.visibleProperties,r=0;r<s.length;r++){var n=s[r];if((!i.groupBy||i.groupBy!==n)&&l._isDefined(e,n)){var o={};if("thumb"===n)o=$("<img>").addClass("item item-"+n).attr("src",e[n]);else{var u=a._getHighlight(e,n);o=$("<span>").addClass("item item-"+n).html(u+" ")}o.appendTo(t)}}return t},a._getHighlight=function(e,t,i){return l._isDefined(e,t+"_highlight")?e[t+"_highlight"]:l._isDefined(e,t)?e[t]:i},a._getResultsContainer=function(){var e=a;a._options("multiple")&&(e=i);var s=$("ul.flexdatalist-results");return 0===s.length&&(s=$("<ul>").addClass("flexdatalist-results").appendTo("body").css({"border-color":e.css("border-left-color"),"border-width":"1px","border-bottom-left-radius":e.css("border-bottom-left-radius"),"border-bottom-right-radius":e.css("border-bottom-right-radius")}).data("target",t),a._position()),s},a._removeResults=function(e){var t="ul.flexdatalist-results";return e&&(t="ul.flexdatalist-results li"),$(t).remove(),a},a._selected=function(e){var t="flexdatalist-selected";return l._isDefined(e)?(e?a.addClass(t):a.removeClass(t),a):a.hasClass(t)},a._values=function(e,t){return $.isArray(e)&&!l._isEmpty(e)?void $.each(e,function(e,i){a._value(i,t)}):void a._value(e,t)},a._value=function(e,s){var l=a._options(),n=a._getText(e),o=a._getValue(e);if(n.length>0&&!l.allowDuplicateValues&&l._values.push(n),l.multiple){if(""===e)return a;t.val("");var u=i.find("li.input-container"),f=$("<li>").addClass("value"+(l.toggleSelected?" toggle":"")).append('<span class="text">'+n+"</span>").append('<span class="fdl-remove">&times;</span>').insertBefore(u);s||u.find("input").focus(),f.find("span.fdl-remove").click(function(){var e=$(this).parent(),t=e.index();if(!e.hasClass("disabled")&&(a._toJSON()||a._toCSV())){var i=a._normalizeValue();i.splice(t,1),l._values.splice(t,1),a._normalizeValue(i),a._allowValues()}a.trigger("before:flexdatalist.remove"),e.remove(),a.trigger("after:flexdatalist.remove").trigger("change")}),l.toggleSelected&&f.click(function(){var e=$(this),t=a._normalizeValue(),i=e.index();if(e.hasClass("disabled")){var s=e.data("_value");t.splice(i,0,s),l._values.splice(i,0,a._getText(s)),e.removeClass("disabled")}else{var s=t.splice(i,1);e.data("_value",s[0]),l._values.splice(i,1),e.addClass("disabled")}a._normalizeValue(t,n)})}else n&&n!==t.val()&&t.val(n);return a._normalizeValue(o,n,s),r=a._keyword(),a},a._normalizeValue=function(e,t,i){var s=a._toJSON(),r=a._options(),n=a._toCSV();return l._isDefined(e)?(a._allowValues(),l._isObject(e)&&(s&&!l._isEmpty(e)?e=JSON.stringify(e):n&&(e=e.join(r.valuesSeparator))),e==a.val()?e:(""===e&&a._options("_values",[]),a.val(e,!0),!i&&a._changed()&&a.trigger("change:flexdatalist",[e,t,a._options()]).trigger("change"),e)):(e=a.val(),e?s?e=JSON.parse(e):n&&(e=e.split(r.valuesSeparator)):(s||n)&&(e=[]),e)},a._getText=function(e){var t=e,i=a._options();return l._isObject(e)&&(t=e[i.searchIn[0]],t=l._isDefined(e,i.textProperty)?e[i.textProperty]:a._replacePlaceholders(e,i.textProperty,t)),$("<div>").html(t).text()},a._getValue=function(e){var t=e,i=a._options();if(l._isObject(e))if(t=e[i.searchIn[0]],"*"===i.valueProperty)t=e;else if(l._isDefined(e,i.valueProperty))t=e[i.valueProperty];else if(a._toJSON()){var t={},s=i.valueProperty,r=i.textProperty;if(r){var n=r;"string"==typeof r&&(n=a._parsePlaceholders(r)),l._isObject(n)&&$.each(n,function(e,t){s.push(t)})}else l._isDefined(e,r)&&s.push(r);$.each(s,function(i,a){l._isDefined(e,a)&&(t[a]=e[a])})}if(i.multiple&&(a._toJSON()||a._toCSV())){var o=a._normalizeValue();!l._isEmpty(t)&&l._isObject(o)&&(o.push(t),t=o)}return t},a._replacePlaceholders=function(e,t,i){if(l._isObject(e)&&"string"==typeof t){var s=a._parsePlaceholders(t);if(!l._isEmpty(e)&&s)return $.each(s,function(i,a){l._isDefined(e,a)&&(t=t.replace(i,e[a]))}),t}return i},a._parsePlaceholders=function(e){var t=e.match(/\{.+?\}/g);if(t){var i={};return t.map(function(e){i[e]=e.slice(1,-1)}),i}return!1},a._allowValues=function(){var e=a._options();if(e.limitOfValues>0&&e.multiple){var t=i.find(".flexdatalist-multiple-value");e._values.length>=e.limitOfValues?t.hide():t.show()}},a._normalizeString=function(e){if("string"==typeof e){var t=a._options("normalizeString");return"function"==typeof t&&(e=t(e)),e.toUpperCase()}return e},a._keyword=function(){return t.val().replace(/^\s+/,"")},a._toJSON=function(){var e=a._options("valueProperty");return l._isObject(e)||"*"===e},a._toCSV=function(){return!a._toJSON()&&a._options("multiple")},a._position=function(){var e=$("input:focus:eq(0)");0==e.length&&(e=t),a._options("multiple")&&(e=e.parents(".flexdatalist-multiple:eq(0)")),$("ul.flexdatalist-results").css({width:e.outerWidth()+"px",top:e.offset().top+e.outerHeight()+"px",left:e.offset().left+"px"})},a._init(),a._datalist(),a._chained(),a._initValue()},this._destroy=function(e){e||(e=s),e.each(function(){var e=$(this).data("flexdatalist");$(this).removeClass("flexdatalist-set").attr("type","text").val(e&&e.originalValue?e.originalValue:"").removeData("flexdatalist").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})},this._reset=function(){this._destroy()},this._setValue=function(e){s.each(function(){var t=$(this),i=t.data("flexdatalist");if(l._isDefined(i)){if(i.originalValue=e,""==e)return t.val(e,!0),void(i.multiple&&t.next("ul.flexdatalist-multiple").find("li.value").remove());l._destroy()}})},this._keyNum=function(e){return e.which||e.keyCode},a.data("flexdatalist")||$(document).mouseup(function(e){var t=$(".flexdatalist-results"),i=t.data("target");i&&i.is(":focus")||t.is(e.target)||0!==t.has(e.target).length||t.remove()}).keydown(function(e){var t=$(".flexdatalist-results"),i=t.find("li"),a=i.filter(".active"),s=a.index(),r=i.length,n=l._keyNum(e);if(0!==r){if(27===l._keyNum(e))return t.remove();if(13===n)e.preventDefault(),a.click();else if(40===n||38===n){e.preventDefault(),40===n?a=r>s&&a.nextAll(".item").first().length>0?a.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===n&&(a=s>0&&a.prevAll(".item").first().length>0?a.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active"));var o=(0===a.prev().length?a:a.prev()).position().top;t.animate({scrollTop:o+t.scrollTop()},100)}}}).data("flexdatalist",!0),this._isEmpty=function(e){return l._isDefined(e)?null===e?!0:e===!0?!1:0===this._length(e)?!0:""===$.trim(e):!0},this._isObject=function(e){return e&&"object"==typeof e},this._csvToArray=function(e,t,i){return 0===e.length?t:(i||(i=","),"string"==typeof e?e.split(i):e)},this._length=function(e){return this._isObject(e)?Object.keys(e).length:"number"==typeof e.length?e.length:0},this._isDefined=function(e,t){var i="undefined"!=typeof e;return i&&"undefined"!=typeof t?"undefined"!=typeof e[t]:i},this._options=function(e,t,i){var a=e.data("flexdatalist");if(l._isDefined(t)){if(l._isDefined(i))a[t]=i;else{if(!l._isObject(t))return l._isDefined(a,t)?a[t]:null;a=t}a.searchIn=l._csvToArray(a.searchIn,void 0,a.valuesSeparator),a.relatives=a.relatives&&$(a.relatives).length>0?$(a.relatives):null,a.textProperty=null===a.textProperty?a.searchIn[0]:a.textProperty,a.visibleProperties=l._csvToArray(a.visibleProperties,a.searchIn,a.valuesSeparator),e.data("flexdatalist",a)}return a},"string"==typeof e)if("function"==typeof this["_"+e]){if(!this["_"+e]())return this}else{if("value"!==e)return t?(l._options(s,e,t),this):l._options(s,e);this._setValue(t)}return this.each(i)};var _defaultValFunc=jQuery.fn.val;jQuery.fn.val=function(e,t){return!t&&$(this).hasClass("flexdatalist-set")&&"undefined"!=typeof e&&$(this).flexdatalist("value",e),_defaultValFunc.apply(this,arguments)},$(function(){$("input.flexdatalist:not(.flexdatalist-set)").flexdatalist()});
//# sourceMappingURL=jquery.flexdatalist.min.js.map
<MSG> fixed unnecessary search onfocus

<DFF> @@ -1,1 +1,1 @@
-jQuery.fn.flexdatalist=function(e,t){"use strict";var i,a=$(document),s=$(this),l=this;if(i=function(){var t,i,a=$(this),s={},r="",n=null;a.attr("name");a.hasClass("flexdatalist-set")&&l._destroy(a),l._options(a,$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"],searchContain:!1,searchEqual:!1,searchByWord:!1,searchDisabled:!1,searchDelay:200,normalizeString:null,multiple:a.is("[multiple]"),maxShownResults:100,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,allowDuplicateValues:!1,requestType:"get",limitOfValues:0,valuesSeparator:",",_values:[]},a.data(),"object"==typeof e?e:{})),a._options=function(e,t){return l._options(a,e,t)},t=a.clone(!1).attr({list:null,name:null,id:a.attr("id")?a.attr("id")+"-flexdatalist":null}).addClass("flexdatalist-alias").removeClass("flexdatalist"),a._options("multiple")?(i=$("<ul>").addClass("flexdatalist-multiple").css({"border-color":a.css("border-left-color"),"border-width":a.css("border-left-width"),"border-style":a.css("border-left-style"),"border-radius":a.css("border-top-left-radius"),"background-color":a.css("background-color")}).insertAfter(a).click(function(){$(this).find("input").focus()}),$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(t).appendTo(i)):t.insertAfter(a),t.attr("autofocus")&&t.focus(),a._init=function(){var e=a._options();t.on("input keydown",function(i){var s=a._keyword();188!==l._keyNum(i)&&13!==l._keyNum(i)||e.selectionRequired||!e.multiple||a._resultSelected()?9===l._keyNum(i)?a._removeResults():0===s.length&&e.multiple&&8===l._keyNum(i)&&t.data("_remove",t.parents("li:eq(0)").prev()):(i.preventDefault(),a._value(s),a._removeResults())}).on("input keyup",function(i){if(a._changed()&&13!==l._keyNum(i)){var s=a._keyword();e.multiple||(e._values=[],e.selectionRequired?a._value(""):a._value(s)),s.length>=e.minLength?(clearTimeout(n),n=setTimeout(function(){a._search(function(e){a._showResults(e)})},e.searchDelay)):a._removeResults()}var o=t.data("_remove");o&&(o.find(".fdl-remove").click(),t.data("_remove",null)),r=a._keyword()}).on("focus",function(){var t=a._keyword();0===e.minLength?""===t&&a._tdata(function(e){a._showResults(e)}):t.length>=e.minLength&&!a._selected()&&a._search(function(e){a._showResults(e)})}).on("focusin",function(){a.parent().find(".flexdatalist-multiple").addClass("focus")}).on("focusout",function(){a.parent().find(".flexdatalist-multiple").removeClass("focus")}).on("blur",function(){a._resultSelected()||!e.multiple||e.selectionRequired||a._value(a._keyword())}).attr("autocomplete","off"),window.onresize=function(){a._position()},a.addClass("flexdatalist flexdatalist-set").prop("type","hidden")},a._resultSelected=function(){return $("ul.flexdatalist-results").find("li.item.active").length>0},a._changed=function(){return r!==a._keyword()},a._chained=function(){var e=a._options();if(e.relatives&&e.chainedRelatives){var r=function(s){e.relatives.each(function(){var r=l._isEmpty($(this).val()),n=l._isEmpty(a.val());t.prop("disabled",r),s||!r&&n||(a._value(""),t.val(""),e.multiple&&i.find("li .fdl-remove").click()),i&&(r&&i?i.addClass("disabled"):i.removeClass("disabled"))})};e.relatives.on("change",function(){r(),s={}}),r(!0)}},a._initValue=function(){var e=a.attr("value");l._isEmpty(e)||(a._options("originalValue",a.val()),a._options("searchEqual",!0),a._parseValue(e,function(e){a.val("",!0),t.val(""),a._options("searchEqual",!1),l._isEmpty(e)||a._values(e,!0),r=a._keyword()}))},a._parseValue=function(e,t){var i=a._options();if(a._toJSON())try{t(JSON.parse(e))}catch(s){}else if(a._toCSV()||"string"==typeof i.valueProperty){var l=e.split(i.valuesSeparator);if("string"==typeof i.valueProperty){var r=i.searchIn;i.searchIn=i.valueProperty.split(","),i.searchEqual=!0,a._search(function(e){e.length>0&&t(e),i.searchIn=r,i.searchEqual=!1},l)}else t(l)}else t(e)},a._tdata=function(e){a.trigger("before:flexdatalist.data"),a._url(function(t){a._data(function(i){i=i.concat(t);for(var s=a._options("_values"),l=0;l<i.length;l++){var r=i[l];s&&s.indexOf(a._getText(r))>-1&&delete i[l]}a.trigger("after:flexdatalist.data",[i]),e(i)})})},a._data=function(e){var t=a._options();"string"==typeof t.data?a._remote({url:t.data,success:function(i){var s=a._getRemoteData(i);t.data=s,e(s)}}):e(t.data)},a._url=function(e){var t=a._options(),i=a._keyword(),s=a.val(),r=i;if(l._isEmpty(t.url))return e([]);t.cache&&2!==t.cache&&(r=i.substring(0,t.minLength>0?t.minLength:1));var n=a._cache(r);if(n&&t.cache)return void e(n);var o={};"post"==t.requestType&&($.each(t,function(e,t){0!=e.indexOf("_")&&(o[e]=t)}),delete o.relatives),a._remote({url:t.url,data:$.extend(a._relativesData(),t.params,{keyword:i,contain:t.searchContain,selected:s,options:o}),success:function(t){var s=a._getRemoteData(t),l=a._keyword();l.length>=i.length&&e(s),a._cache(r,s)}})},a._remote=function(e){a.hasClass("flexdatalist-loading")||(a.addClass("flexdatalist-loading"),e=$.extend({type:a._options("requestType"),dataType:"json",complete:function(){a.removeClass("flexdatalist-loading")}},e),$.ajax(e))},a._getRemoteData=function(e){var t=e.results?e.results:e;return"string"==typeof t&&0===t.indexOf("[{")&&(t=JSON.parse(t)),t.options&&l._options(a,t.options),l._isObject(t)?t:[]},a._relativesData=function(){var e=a._options("relatives"),t={};return e&&(t.relatives={},e.each(function(){var e=$(this),i=e.attr("name").split("][").join("-").split("]").join("-").split("[").join("-").replace(/^\|+|\-+$/g,"");t.relatives[i]=e.val()})),t},a._datalist=function(){var e=a._options(),t=a.attr("list");return l._isEmpty(t)||(e.data=[],$("#"+t).find("option").each(function(){var t=$(this),i=t.val(),a=t.text();e.data.push({label:a.length>0?a:i,value:i})})),a},a._cache=function(e,t){if(a._options("cache")){if(e=a._normalizeString(e),!l._isDefined(t))return l._isDefined(s,e)&&(t=s[e]),t;s[e]=t}return null},a._search=function(e,t){a._tdata(function(i){var s=[],r=a._options();if(r.searchDisabled)return e(i);l._isDefined(t)||(t=a._keyword()),a.trigger("before:flexdatalist.search",[t,i]),t=a._split(t);for(var n=0;n<i.length;n++){var o=a._matches(i[n],t);o&&s.push(o)}a.trigger("after:flexdatalist.search",[t,i,s]),e(s)})},a._matches=function(e,t){var i=$.extend({},e),s=a._options(),r=[],n=s.searchIn;if(t.length>0)for(var o=0;o<n.length;o++){var u=n[o];if(l._isDefined(e,u)&&e[u]){for(var f=e[u].toString(),d=f,c=a._split(f),p=0;p<t.length;p++){var _=t[p];a._find(_,c)&&(r.push(_),d=a._highlight(_,d))}d!==f&&(i[u+"_highlight"]=a._highlight(d))}}return 0===r.length||s.searchByWord&&r.length<t.length-1?!1:i},a._highlight=function(e,t){return t?t.replace(new RegExp(e,a._options("searchContain")?"ig":"i"),"|:|$&|::|"):(e=e.split("|:|").join('<span class="highlight">'),e.split("|::|").join("</span>"))},a._find=function(e,t){for(var i=a._options(),s=0;s<t.length;s++){var l=t[s];if(l=a._normalizeString(l),e=a._normalizeString(e),i.searchEqual)return l==e;if(i.searchContain?l.indexOf(e)>=0:0===l.indexOf(e))return!0}return!1},a._split=function(e){"string"==typeof e&&(e=[$.trim(e)]);var t=a._options();if(t.searchByWord)for(var i=0;i<e.length;i++){var s=$.trim(e[i]);if(s.indexOf(" ")>0){var l=s.split(" ");$.merge(e,l)}}return e},a._showResults=function(e){a._removeResults(!0);var t=a._options();if(0===e.length)return void a._noResults(t.noResultsText);var i=a._getResultsContainer();t.groupBy?(e=a._groupData(e),Object.keys(e).forEach(function(s){var l=e[s],r=t.groupBy,n=a._getHighlight(l[0],r,s);$("<li>").addClass("group").append($("<span>").addClass("group-name").html(n)).append($("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(i);a._items(l,i)})):a._items(e,i);var s=i.find("li:not(.group)");s.on("click",function(){var e=$(this).data("item");e&&(a._selected(!0)._removeResults()._value(e),a.trigger("select:flexdatalist",[e,t]))}).hover(function(){s.removeClass("active"),$(this).addClass("active")},function(){$(this).removeClass("active")}),t.focusFirstResult&&s.filter(":first").addClass("active")},a._noResults=function(e){if(!l._isEmpty(e)){var t=a._getResultsContainer(),i=a._keyword();e=e.split("{keyword}").join(i),$("<li>").addClass("item no-results").append(e).appendTo(t)}},a._groupData=function(e){for(var t=[],i=a._options("groupBy"),s=0;s<e.length;s++){var r=e[s];if(l._isDefined(r,i)){var n=r[i];l._isDefined(t,n)||(t[n]=[]),t[n].push(r)}}return t},a._items=function(e,t){var i=a._options("maxShownResults");a.trigger("show:flexdatalist.results",[e]);for(var s=0;s<e.length&&!(i>0&&i===s);s++)a._item(e[s]).appendTo(t);a.trigger("shown:flexdatalist.results",[e])},a._item=function(e){for(var t=$("<li>").data("item",e).addClass("item"),i=a._options(),s=i.visibleProperties,r=0;r<s.length;r++){var n=s[r];if((!i.groupBy||i.groupBy!==n)&&l._isDefined(e,n)){var o={};if("thumb"===n)o=$("<img>").addClass("item item-"+n).attr("src",e[n]);else{var u=a._getHighlight(e,n);o=$("<span>").addClass("item item-"+n).html(u+" ")}o.appendTo(t)}}return t},a._getHighlight=function(e,t,i){return l._isDefined(e,t+"_highlight")?e[t+"_highlight"]:l._isDefined(e,t)?e[t]:i},a._getResultsContainer=function(){var e=a;a._options("multiple")&&(e=i);var s=$("ul.flexdatalist-results");return 0===s.length&&(s=$("<ul>").addClass("flexdatalist-results").appendTo("body").css({"border-color":e.css("border-left-color"),"border-width":"1px","border-bottom-left-radius":e.css("border-bottom-left-radius"),"border-bottom-right-radius":e.css("border-bottom-right-radius")}).data("target",t),a._position()),s},a._removeResults=function(e){var t="ul.flexdatalist-results";return e&&(t="ul.flexdatalist-results li"),$(t).remove(),a},a._selected=function(e){var t="flexdatalist-selected";return l._isDefined(e)?(e?a.addClass(t):a.removeClass(t),a):a.hasClass(t)},a._values=function(e,t){return $.isArray(e)&&!l._isEmpty(e)?void $.each(e,function(e,i){a._value(i,t)}):void a._value(e,t)},a._value=function(e,s){var l=a._options(),n=a._getText(e),o=a._getValue(e);if(n.length>0&&!l.allowDuplicateValues&&l._values.push(n),l.multiple){if(""===e)return a;t.val("");var u=i.find("li.input-container"),f=$("<li>").addClass("value"+(l.toggleSelected?" toggle":"")).append('<span class="text">'+n+"</span>").append('<span class="fdl-remove">&times;</span>').insertBefore(u);s||u.find("input").focus(),f.find("span.fdl-remove").click(function(){var e=$(this).parent(),t=e.index();if(!e.hasClass("disabled")&&(a._toJSON()||a._toCSV())){var i=a._normalizeValue();i.splice(t,1),l._values.splice(t,1),a._normalizeValue(i),a._allowValues()}a.trigger("before:flexdatalist.remove"),e.remove(),a.trigger("after:flexdatalist.remove").trigger("change")}),l.toggleSelected&&f.click(function(){var e=$(this),t=a._normalizeValue(),i=e.index();if(e.hasClass("disabled")){var s=e.data("_value");t.splice(i,0,s),l._values.splice(i,0,a._getText(s)),e.removeClass("disabled")}else{var s=t.splice(i,1);e.data("_value",s[0]),l._values.splice(i,1),e.addClass("disabled")}a._normalizeValue(t,n)})}else n&&n!==t.val()&&t.val(n);return a._normalizeValue(o,n,s),r=a._keyword(),a},a._normalizeValue=function(e,t,i){var s=a._toJSON(),r=a._options(),n=a._toCSV();return l._isDefined(e)?(a._allowValues(),l._isObject(e)&&(s&&!l._isEmpty(e)?e=JSON.stringify(e):n&&(e=e.join(r.valuesSeparator))),e==a.val()?e:(""===e&&a._options("_values",[]),a.val(e,!0),!i&&a._changed()&&a.trigger("change:flexdatalist",[e,t,a._options()]).trigger("change"),e)):(e=a.val(),e?s?e=JSON.parse(e):n&&(e=e.split(r.valuesSeparator)):(s||n)&&(e=[]),e)},a._getText=function(e){var t=e,i=a._options();return l._isObject(e)&&(t=e[i.searchIn[0]],t=l._isDefined(e,i.textProperty)?e[i.textProperty]:a._replacePlaceholders(e,i.textProperty,t)),$("<div>").html(t).text()},a._getValue=function(e){var t=e,i=a._options();if(l._isObject(e))if(t=e[i.searchIn[0]],"*"===i.valueProperty)t=e;else if(l._isDefined(e,i.valueProperty))t=e[i.valueProperty];else if(a._toJSON()){var t={},s=i.valueProperty,r=i.textProperty;if(r){var n=r;"string"==typeof r&&(n=a._parsePlaceholders(r)),l._isObject(n)&&$.each(n,function(e,t){s.push(t)})}else l._isDefined(e,r)&&s.push(r);$.each(s,function(i,a){l._isDefined(e,a)&&(t[a]=e[a])})}if(i.multiple&&(a._toJSON()||a._toCSV())){var o=a._normalizeValue();!l._isEmpty(t)&&l._isObject(o)&&(o.push(t),t=o)}return t},a._replacePlaceholders=function(e,t,i){if(l._isObject(e)&&"string"==typeof t){var s=a._parsePlaceholders(t);if(!l._isEmpty(e)&&s)return $.each(s,function(i,a){l._isDefined(e,a)&&(t=t.replace(i,e[a]))}),t}return i},a._parsePlaceholders=function(e){var t=e.match(/\{.+?\}/g);if(t){var i={};return t.map(function(e){i[e]=e.slice(1,-1)}),i}return!1},a._allowValues=function(){var e=a._options();if(e.limitOfValues>0&&e.multiple){var t=i.find(".flexdatalist-multiple-value");e._values.length>=e.limitOfValues?t.hide():t.show()}},a._normalizeString=function(e){if("string"==typeof e){var t=a._options("normalizeString");return"function"==typeof t&&(e=t(e)),e.toUpperCase()}return e},a._keyword=function(){return t.val().replace(/^\s+/,"")},a._toJSON=function(){var e=a._options("valueProperty");return l._isObject(e)||"*"===e},a._toCSV=function(){return!a._toJSON()&&a._options("multiple")},a._position=function(){var e=$("input:focus:eq(0)");0==e.length&&(e=t),a._options("multiple")&&(e=e.parents(".flexdatalist-multiple:eq(0)")),$("ul.flexdatalist-results").css({width:e.outerWidth()+"px",top:e.offset().top+e.outerHeight()+"px",left:e.offset().left+"px"})},a._init(),a._datalist(),a._chained(),a._initValue()},this._destroy=function(e){e||(e=s),e.each(function(){var e=$(this).data("flexdatalist");$(this).removeClass("flexdatalist-set").attr("type","text").val(e&&e.originalValue?e.originalValue:"").removeData("flexdatalist").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})},this._reset=function(){this._destroy()},this._setValue=function(e){s.each(function(){var t=$(this),i=t.data("flexdatalist");if(l._isDefined(i)){if(i.originalValue=e,""==e)return t.val(e,!0),void(i.multiple&&t.next("ul.flexdatalist-multiple").find("li.value").remove());l._destroy()}})},this._keyNum=function(e){return e.which||e.keyCode},a.data("flexdatalist")||$(document).mouseup(function(e){var t=$(".flexdatalist-results"),i=t.data("target");i&&i.is(":focus")||t.is(e.target)||0!==t.has(e.target).length||t.remove()}).keydown(function(e){var t=$(".flexdatalist-results"),i=t.find("li"),a=i.filter(".active"),s=a.index(),r=i.length,n=l._keyNum(e);if(0!==r){if(27===l._keyNum(e))return t.remove();if(13===n)e.preventDefault(),a.click();else if(40===n||38===n){e.preventDefault(),40===n?a=r>s&&a.nextAll(".item").first().length>0?a.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===n&&(a=s>0&&a.prevAll(".item").first().length>0?a.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active"));var o=(0===a.prev().length?a:a.prev()).position().top;t.animate({scrollTop:o+t.scrollTop()},100)}}}).data("flexdatalist",!0),this._isEmpty=function(e){return l._isDefined(e)?null===e?!0:e===!0?!1:0===this._length(e)?!0:""===$.trim(e):!0},this._isObject=function(e){return e&&"object"==typeof e},this._csvToArray=function(e,t,i){return 0===e.length?t:(i||(i=","),"string"==typeof e?e.split(i):e)},this._length=function(e){return this._isObject(e)?Object.keys(e).length:"number"==typeof e.length?e.length:0},this._isDefined=function(e,t){var i="undefined"!=typeof e;return i&&"undefined"!=typeof t?"undefined"!=typeof e[t]:i},this._options=function(e,t,i){var a=e.data("flexdatalist");if(l._isDefined(t)){if(l._isDefined(i))a[t]=i;else{if(!l._isObject(t))return l._isDefined(a,t)?a[t]:null;a=t}a.searchIn=l._csvToArray(a.searchIn,void 0,a.valuesSeparator),a.relatives=a.relatives&&$(a.relatives).length>0?$(a.relatives):null,a.textProperty=null===a.textProperty?a.searchIn[0]:a.textProperty,a.visibleProperties=l._csvToArray(a.visibleProperties,a.searchIn,a.valuesSeparator),e.data("flexdatalist",a)}return a},"string"==typeof e)if("function"==typeof this["_"+e]){if(!this["_"+e]())return this}else{if("value"!==e)return t?(l._options(s,e,t),this):l._options(s,e);this._setValue(t)}return this.each(i)};var _defaultValFunc=jQuery.fn.val;jQuery.fn.val=function(e,t){return!t&&$(this).hasClass("flexdatalist-set")&&"undefined"!=typeof e&&$(this).flexdatalist("value",e),_defaultValFunc.apply(this,arguments)},$(function(){$("input.flexdatalist:not(.flexdatalist-set)").flexdatalist()});
\ No newline at end of file
+jQuery.fn.flexdatalist=function(e,t){"use strict";var i,a=$(document),s=$(this),l=this;if(i=function(){var t,i,a=$(this),s={},r="",n=null;a.attr("name");a.hasClass("flexdatalist-set")&&l._destroy(a),l._options(a,$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"],searchContain:!1,searchEqual:!1,searchByWord:!1,searchDisabled:!1,searchDelay:200,normalizeString:null,multiple:a.is("[multiple]"),maxShownResults:100,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,allowDuplicateValues:!1,requestType:"get",limitOfValues:0,valuesSeparator:",",_values:[]},a.data(),"object"==typeof e?e:{})),a._options=function(e,t){return l._options(a,e,t)},t=a.clone(!1).attr({list:null,name:null,id:a.attr("id")?a.attr("id")+"-flexdatalist":null}).addClass("flexdatalist-alias").removeClass("flexdatalist"),a._options("multiple")?(i=$("<ul>").addClass("flexdatalist-multiple").css({"border-color":a.css("border-left-color"),"border-width":a.css("border-left-width"),"border-style":a.css("border-left-style"),"border-radius":a.css("border-top-left-radius"),"background-color":a.css("background-color")}).insertAfter(a).click(function(){$(this).find("input").focus()}),$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(t).appendTo(i)):t.insertAfter(a),t.attr("autofocus")&&t.focus(),a._init=function(){var e=a._options();t.on("input keydown",function(i){var s=a._keyword();188!==l._keyNum(i)&&13!==l._keyNum(i)||e.selectionRequired||!e.multiple||a._resultSelected()?9===l._keyNum(i)?a._removeResults():0===s.length&&e.multiple&&8===l._keyNum(i)&&t.data("_remove",t.parents("li:eq(0)").prev()):(i.preventDefault(),a._value(s),a._removeResults())}).on("input keyup",function(i){if(a._changed()&&13!==l._keyNum(i)){var s=a._keyword();e.multiple||(e._values=[],e.selectionRequired?a._value(""):a._value(s)),s.length>=e.minLength?(clearTimeout(n),n=setTimeout(function(){a._search(function(e){a._showResults(e)})},e.searchDelay)):a._removeResults()}var o=t.data("_remove");o&&(o.find(".fdl-remove").click(),t.data("_remove",null)),r=a._keyword()}).on("focus",function(){var t=a._keyword();0===e.minLength?""===t&&a._tdata(function(e){a._showResults(e)}):t.length>=e.minLength&&!a._selected()&&a._search(function(e){a._showResults(e)})}).on("focusin",function(){a.parent().find(".flexdatalist-multiple").addClass("focus")}).on("focusout",function(){a.parent().find(".flexdatalist-multiple").removeClass("focus")}).on("blur",function(){a._resultSelected()||!e.multiple||e.selectionRequired||a._value(a._keyword())}).attr("autocomplete","off"),window.onresize=function(){a._position()},a.addClass("flexdatalist flexdatalist-set").prop("type","hidden")},a._resultSelected=function(){return $("ul.flexdatalist-results").find("li.item.active").length>0},a._changed=function(){return r!==a._keyword()},a._chained=function(){var e=a._options();if(e.relatives&&e.chainedRelatives){var r=function(s){e.relatives.each(function(){var r=l._isEmpty($(this).val()),n=l._isEmpty(a.val());t.prop("disabled",r),s||!r&&n||(a._value(""),t.val(""),e.multiple&&i.find("li .fdl-remove").click()),i&&(r&&i?i.addClass("disabled"):i.removeClass("disabled"))})};e.relatives.on("change",function(){r(),s={}}),r(!0)}},a._initValue=function(){var e=a.attr("value");l._isEmpty(e)||(a._options("originalValue",a.val()),a._options("searchEqual",!0),a._parseValue(e,function(e){a.val("",!0),t.val(""),a._options("searchEqual",!1),l._isEmpty(e)||(a._selected(!0),a._values(e,!0)),r=a._keyword()}))},a._parseValue=function(e,t){var i=a._options();if(a._toJSON())try{t(JSON.parse(e))}catch(s){}else if(a._toCSV()||"string"==typeof i.valueProperty){var l=e.split(i.valuesSeparator);if("string"==typeof i.valueProperty){var r=i.searchIn;i.searchIn=i.valueProperty.split(","),i.searchEqual=!0,a._search(function(e){e.length>0&&t(e),i.searchIn=r,i.searchEqual=!1},l)}else t(l)}else t(e)},a._tdata=function(e){a.trigger("before:flexdatalist.data"),a._url(function(t){a._data(function(i){i=i.concat(t);for(var s=a._options("_values"),l=0;l<i.length;l++){var r=i[l];s&&s.indexOf(a._getText(r))>-1&&delete i[l]}a.trigger("after:flexdatalist.data",[i]),e(i)})})},a._data=function(e){var t=a._options();"string"==typeof t.data?a._remote({url:t.data,success:function(i){var s=a._getRemoteData(i);t.data=s,e(s)}}):e(t.data)},a._url=function(e){var t=a._options(),i=a._keyword(),s=a.val(),r=i;if(l._isEmpty(t.url))return e([]);t.cache&&2!==t.cache&&(r=i.substring(0,t.minLength>0?t.minLength:1));var n=a._cache(r);if(n&&t.cache)return void e(n);var o={};"post"==t.requestType&&($.each(t,function(e,t){0!=e.indexOf("_")&&(o[e]=t)}),delete o.relatives),a._remote({url:t.url,data:$.extend(a._relativesData(),t.params,{keyword:i,contain:t.searchContain,selected:s,options:o}),success:function(t){var s=a._getRemoteData(t),l=a._keyword();l.length>=i.length&&e(s),a._cache(r,s)}})},a._remote=function(e){a.hasClass("flexdatalist-loading")||(a.addClass("flexdatalist-loading"),e=$.extend({type:a._options("requestType"),dataType:"json",complete:function(){a.removeClass("flexdatalist-loading")}},e),$.ajax(e))},a._getRemoteData=function(e){var t=e.results?e.results:e;return"string"==typeof t&&0===t.indexOf("[{")&&(t=JSON.parse(t)),t.options&&l._options(a,t.options),l._isObject(t)?t:[]},a._relativesData=function(){var e=a._options("relatives"),t={};return e&&(t.relatives={},e.each(function(){var e=$(this),i=e.attr("name").split("][").join("-").split("]").join("-").split("[").join("-").replace(/^\|+|\-+$/g,"");t.relatives[i]=e.val()})),t},a._datalist=function(){var e=a._options(),t=a.attr("list");return l._isEmpty(t)||(e.data=[],$("#"+t).find("option").each(function(){var t=$(this),i=t.val(),a=t.text();e.data.push({label:a.length>0?a:i,value:i})})),a},a._cache=function(e,t){if(a._options("cache")){if(e=a._normalizeString(e),!l._isDefined(t))return l._isDefined(s,e)&&(t=s[e]),t;s[e]=t}return null},a._search=function(e,t){a._tdata(function(i){var s=[],r=a._options();if(r.searchDisabled)return e(i);l._isDefined(t)||(t=a._keyword()),a.trigger("before:flexdatalist.search",[t,i]),t=a._split(t);for(var n=0;n<i.length;n++){var o=a._matches(i[n],t);o&&s.push(o)}a.trigger("after:flexdatalist.search",[t,i,s]),e(s)})},a._matches=function(e,t){var i=$.extend({},e),s=a._options(),r=[],n=s.searchIn;if(t.length>0)for(var o=0;o<n.length;o++){var u=n[o];if(l._isDefined(e,u)&&e[u]){for(var f=e[u].toString(),d=f,c=a._split(f),p=0;p<t.length;p++){var _=t[p];a._find(_,c)&&(r.push(_),d=a._highlight(_,d))}d!==f&&(i[u+"_highlight"]=a._highlight(d))}}return 0===r.length||s.searchByWord&&r.length<t.length-1?!1:i},a._highlight=function(e,t){return t?t.replace(new RegExp(e,a._options("searchContain")?"ig":"i"),"|:|$&|::|"):(e=e.split("|:|").join('<span class="highlight">'),e.split("|::|").join("</span>"))},a._find=function(e,t){for(var i=a._options(),s=0;s<t.length;s++){var l=t[s];if(l=a._normalizeString(l),e=a._normalizeString(e),i.searchEqual)return l==e;if(i.searchContain?l.indexOf(e)>=0:0===l.indexOf(e))return!0}return!1},a._split=function(e){"string"==typeof e&&(e=[$.trim(e)]);var t=a._options();if(t.searchByWord)for(var i=0;i<e.length;i++){var s=$.trim(e[i]);if(s.indexOf(" ")>0){var l=s.split(" ");$.merge(e,l)}}return e},a._showResults=function(e){a._removeResults(!0);var t=a._options();if(0===e.length)return void a._noResults(t.noResultsText);var i=a._getResultsContainer();t.groupBy?(e=a._groupData(e),Object.keys(e).forEach(function(s){var l=e[s],r=t.groupBy,n=a._getHighlight(l[0],r,s);$("<li>").addClass("group").append($("<span>").addClass("group-name").html(n)).append($("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(i);a._items(l,i)})):a._items(e,i);var s=i.find("li:not(.group)");s.on("click",function(){var e=$(this).data("item");e&&(a._selected(!0)._removeResults()._value(e),a.trigger("select:flexdatalist",[e,t]))}).hover(function(){s.removeClass("active"),$(this).addClass("active")},function(){$(this).removeClass("active")}),t.focusFirstResult&&s.filter(":first").addClass("active")},a._noResults=function(e){if(!l._isEmpty(e)){var t=a._getResultsContainer(),i=a._keyword();e=e.split("{keyword}").join(i),$("<li>").addClass("item no-results").append(e).appendTo(t)}},a._groupData=function(e){for(var t=[],i=a._options("groupBy"),s=0;s<e.length;s++){var r=e[s];if(l._isDefined(r,i)){var n=r[i];l._isDefined(t,n)||(t[n]=[]),t[n].push(r)}}return t},a._items=function(e,t){var i=a._options("maxShownResults");a.trigger("show:flexdatalist.results",[e]);for(var s=0;s<e.length&&!(i>0&&i===s);s++)a._item(e[s]).appendTo(t);a.trigger("shown:flexdatalist.results",[e])},a._item=function(e){for(var t=$("<li>").data("item",e).addClass("item"),i=a._options(),s=i.visibleProperties,r=0;r<s.length;r++){var n=s[r];if((!i.groupBy||i.groupBy!==n)&&l._isDefined(e,n)){var o={};if("thumb"===n)o=$("<img>").addClass("item item-"+n).attr("src",e[n]);else{var u=a._getHighlight(e,n);o=$("<span>").addClass("item item-"+n).html(u+" ")}o.appendTo(t)}}return t},a._getHighlight=function(e,t,i){return l._isDefined(e,t+"_highlight")?e[t+"_highlight"]:l._isDefined(e,t)?e[t]:i},a._getResultsContainer=function(){var e=a;a._options("multiple")&&(e=i);var s=$("ul.flexdatalist-results");return 0===s.length&&(s=$("<ul>").addClass("flexdatalist-results").appendTo("body").css({"border-color":e.css("border-left-color"),"border-width":"1px","border-bottom-left-radius":e.css("border-bottom-left-radius"),"border-bottom-right-radius":e.css("border-bottom-right-radius")}).data("target",t),a._position()),s},a._removeResults=function(e){var t="ul.flexdatalist-results";return e&&(t="ul.flexdatalist-results li"),$(t).remove(),a},a._selected=function(e){var t="flexdatalist-selected";return l._isDefined(e)?(e?a.addClass(t):a.removeClass(t),a):a.hasClass(t)},a._values=function(e,t){return $.isArray(e)&&!l._isEmpty(e)?void $.each(e,function(e,i){a._value(i,t)}):void a._value(e,t)},a._value=function(e,s){var l=a._options(),n=a._getText(e),o=a._getValue(e);if(n.length>0&&!l.allowDuplicateValues&&l._values.push(n),l.multiple){if(""===e)return a;t.val("");var u=i.find("li.input-container"),f=$("<li>").addClass("value"+(l.toggleSelected?" toggle":"")).append('<span class="text">'+n+"</span>").append('<span class="fdl-remove">&times;</span>').insertBefore(u);s||u.find("input").focus(),f.find("span.fdl-remove").click(function(){var e=$(this).parent(),t=e.index();if(!e.hasClass("disabled")&&(a._toJSON()||a._toCSV())){var i=a._normalizeValue();i.splice(t,1),l._values.splice(t,1),a._normalizeValue(i),a._allowValues()}a.trigger("before:flexdatalist.remove"),e.remove(),a.trigger("after:flexdatalist.remove").trigger("change")}),l.toggleSelected&&f.click(function(){var e=$(this),t=a._normalizeValue(),i=e.index();if(e.hasClass("disabled")){var s=e.data("_value");t.splice(i,0,s),l._values.splice(i,0,a._getText(s)),e.removeClass("disabled")}else{var s=t.splice(i,1);e.data("_value",s[0]),l._values.splice(i,1),e.addClass("disabled")}a._normalizeValue(t,n)})}else n&&n!==t.val()&&t.val(n);return a._normalizeValue(o,n,s),r=a._keyword(),a},a._normalizeValue=function(e,t,i){var s=a._toJSON(),r=a._options(),n=a._toCSV();return l._isDefined(e)?(a._allowValues(),l._isObject(e)&&(s&&!l._isEmpty(e)?e=JSON.stringify(e):n&&(e=e.join(r.valuesSeparator))),e==a.val()?e:(""===e&&a._options("_values",[]),a.val(e,!0),!i&&a._changed()&&a.trigger("change:flexdatalist",[e,t,a._options()]).trigger("change"),e)):(e=a.val(),e?s?e=JSON.parse(e):n&&(e=e.split(r.valuesSeparator)):(s||n)&&(e=[]),e)},a._getText=function(e){var t=e,i=a._options();return l._isObject(e)&&(t=e[i.searchIn[0]],t=l._isDefined(e,i.textProperty)?e[i.textProperty]:a._replacePlaceholders(e,i.textProperty,t)),$("<div>").html(t).text()},a._getValue=function(e){var t=e,i=a._options();if(l._isObject(e))if(t=e[i.searchIn[0]],"*"===i.valueProperty)t=e;else if(l._isDefined(e,i.valueProperty))t=e[i.valueProperty];else if(a._toJSON()){var t={},s=i.valueProperty,r=i.textProperty;if(r){var n=r;"string"==typeof r&&(n=a._parsePlaceholders(r)),l._isObject(n)&&$.each(n,function(e,t){s.push(t)})}else l._isDefined(e,r)&&s.push(r);$.each(s,function(i,a){l._isDefined(e,a)&&(t[a]=e[a])})}if(i.multiple&&(a._toJSON()||a._toCSV())){var o=a._normalizeValue();!l._isEmpty(t)&&l._isObject(o)&&(o.push(t),t=o)}return t},a._replacePlaceholders=function(e,t,i){if(l._isObject(e)&&"string"==typeof t){var s=a._parsePlaceholders(t);if(!l._isEmpty(e)&&s)return $.each(s,function(i,a){l._isDefined(e,a)&&(t=t.replace(i,e[a]))}),t}return i},a._parsePlaceholders=function(e){var t=e.match(/\{.+?\}/g);if(t){var i={};return t.map(function(e){i[e]=e.slice(1,-1)}),i}return!1},a._allowValues=function(){var e=a._options();if(e.limitOfValues>0&&e.multiple){var t=i.find(".flexdatalist-multiple-value");e._values.length>=e.limitOfValues?t.hide():t.show()}},a._normalizeString=function(e){if("string"==typeof e){var t=a._options("normalizeString");return"function"==typeof t&&(e=t(e)),e.toUpperCase()}return e},a._keyword=function(){return t.val().replace(/^\s+/,"")},a._toJSON=function(){var e=a._options("valueProperty");return l._isObject(e)||"*"===e},a._toCSV=function(){return!a._toJSON()&&a._options("multiple")},a._position=function(){var e=$("input:focus:eq(0)");0==e.length&&(e=t),a._options("multiple")&&(e=e.parents(".flexdatalist-multiple:eq(0)")),$("ul.flexdatalist-results").css({width:e.outerWidth()+"px",top:e.offset().top+e.outerHeight()+"px",left:e.offset().left+"px"})},a._init(),a._datalist(),a._chained(),a._initValue()},this._destroy=function(e){e||(e=s),e.each(function(){var e=$(this).data("flexdatalist");$(this).removeClass("flexdatalist-set").attr("type","text").val(e&&e.originalValue?e.originalValue:"").removeData("flexdatalist").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})},this._reset=function(){this._destroy()},this._setValue=function(e){s.each(function(){var t=$(this),i=t.data("flexdatalist");if(l._isDefined(i)){if(i.originalValue=e,""==e)return t.val(e,!0),void(i.multiple&&t.next("ul.flexdatalist-multiple").find("li.value").remove());l._destroy()}})},this._keyNum=function(e){return e.which||e.keyCode},a.data("flexdatalist")||$(document).mouseup(function(e){var t=$(".flexdatalist-results"),i=t.data("target");i&&i.is(":focus")||t.is(e.target)||0!==t.has(e.target).length||t.remove()}).keydown(function(e){var t=$(".flexdatalist-results"),i=t.find("li"),a=i.filter(".active"),s=a.index(),r=i.length,n=l._keyNum(e);if(0!==r){if(27===l._keyNum(e))return t.remove();if(13===n)e.preventDefault(),a.click();else if(40===n||38===n){e.preventDefault(),40===n?a=r>s&&a.nextAll(".item").first().length>0?a.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===n&&(a=s>0&&a.prevAll(".item").first().length>0?a.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active"));var o=(0===a.prev().length?a:a.prev()).position().top;t.animate({scrollTop:o+t.scrollTop()},100)}}}).data("flexdatalist",!0),this._isEmpty=function(e){return l._isDefined(e)?null===e?!0:e===!0?!1:0===this._length(e)?!0:""===$.trim(e):!0},this._isObject=function(e){return e&&"object"==typeof e},this._csvToArray=function(e,t,i){return 0===e.length?t:(i||(i=","),"string"==typeof e?e.split(i):e)},this._length=function(e){return this._isObject(e)?Object.keys(e).length:"number"==typeof e.length?e.length:0},this._isDefined=function(e,t){var i="undefined"!=typeof e;return i&&"undefined"!=typeof t?"undefined"!=typeof e[t]:i},this._options=function(e,t,i){var a=e.data("flexdatalist");if(l._isDefined(t)){if(l._isDefined(i))a[t]=i;else{if(!l._isObject(t))return l._isDefined(a,t)?a[t]:null;a=t}a.searchIn=l._csvToArray(a.searchIn,void 0,a.valuesSeparator),a.relatives=a.relatives&&$(a.relatives).length>0?$(a.relatives):null,a.textProperty=null===a.textProperty?a.searchIn[0]:a.textProperty,a.visibleProperties=l._csvToArray(a.visibleProperties,a.searchIn,a.valuesSeparator),e.data("flexdatalist",a)}return a},"string"==typeof e)if("function"==typeof this["_"+e]){if(!this["_"+e]())return this}else{if("value"!==e)return t?(l._options(s,e,t),this):l._options(s,e);this._setValue(t)}return this.each(i)};var _defaultValFunc=jQuery.fn.val;jQuery.fn.val=function(e,t){return!t&&$(this).hasClass("flexdatalist-set")&&"undefined"!=typeof e&&$(this).flexdatalist("value",e),_defaultValFunc.apply(this,arguments)},$(function(){$("input.flexdatalist:not(.flexdatalist-set)").flexdatalist()});
\ No newline at end of file

fixed unnecessary search onfocus