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

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

fixes and improvements