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

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

minor fix