<NME> jquery.flexdatalist.min.js
<BEF> !function(e){"use strict";e.fn.flexdatalist=function(t,i){var a=e(document),s=e(this),r=this;if(this._destroy=function(){return s.removeClass("flexdatalist-set").data("flexdatalist",null).off().val("").attr("type","text").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove(),!1},this._reset=function(){this._destroy()},"string"==typeof t)if("function"==typeof this["_"+t]){if(!this["_"+t]())return}else if(i){var n=s.data("flexdatalist");return n[t]=i,void s.data("flexdatalist",n)}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"),n=s.index(),l=a.length,o=r._keyNum(t);if(0!==l)if(13===o)t.preventDefault(),s.click();else if(40===o||38===o){t.preventDefault(),40===o?s=l>n&&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=n>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 r._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="";i.attr("name");if(!i.hasClass("flexdatalist-set")){i._options=function(t,s){var n=i.data("flexdatalist");if(!r._isDefined(t))return i.data("flexdatalist");if(r._isDefined(s))n[t]=s;else{if(!r._isObject(t))return r._isDefined(n,t)?n[t]:null;n=t}return n.searchIn="string"==typeof n.searchIn?n.searchIn.split(","):n.searchIn,n.relatives=n.relatives&&e(n.relatives).length>0?e(n.relatives):null,n.textProperty=null===n.textProperty?n.searchIn[0]:n.textProperty,i.data("flexdatalist",n),a={},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},t,i.data()));var n=i.clone(!1).attr({list:null,name:null}).addClass("flexdatalist-alias").removeClass("flexdatalist");if(i._options("multiple")){var l=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);e('<li class="input-container">').addClass("flexdatalist-multiple-value").append(n).appendTo(l)}else n.insertAfter(i);i.addClass("flexdatalist").attr("type","hidden"),i._init=function(){var e=i._options();n.on("input keydown",function(t){var a=i._keyword();188===r._keyNum(t)&&!e.selectionRequired&&e.multiple&&(t.preventDefault(),i._value(a),i._removeResults())}).on("input keyup",function(t){if(i._changed()&&13!==r._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._data(function(e){i._showResults(e)}):n.trigger("keyup"))}).blur(function(){e.selectionRequired&&!i._selected()&&i._value("")}).attr("autocomplete","off"),i.addClass("flexdatalist-set"),window.onresize=function(){i._position()},n.attr("autofocus")&&n.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=r._isEmpty(e(this).val()),o=r._isEmpty(i.val());n.prop("disabled",s),a||!s&&o||(i._value(""),n.val(""),t.multiple&&l.find("li .remove").click())})};t.relatives.on("change",function(){s(),a={}}),s(!0)}},i._initValue=function(){var e=i.attr("value");r._isEmpty(e)||(i.val(""),n.val(""),i._parseValue(e,function(e){r._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 r=e.split(",");if("string"==typeof a.valueProperty){var n=a.searchIn;a.searchIn=a.valueProperty.split(","),a.searchEqual=!0,i._search(function(e,i){i.length>0&&t(i),a.searchIn=n,a.searchEqual=!1},r)}else t(r)}else t(e)},i._data=function(t){var a=i._options(),s=a.url;if(r._isObject(a.data)&&!r._isEmpty(a.data))return void t(a.data);if("string"==typeof a.data)s=a.data;else if(r._isEmpty(a.url)&&r._isEmpty(a.data))return;var n=i._keyword(),l=n.substring(0,a.minLength),o=i._cache(l);return o?void t(o):void(i.hasClass("flexdatalist-loading")||(i.addClass("flexdatalist-loading"),e.ajax({url:s,data:e.extend(i._relativesData(),a.params,{keyword:n,contain:a.searchContain,selected:i.val()}),type:"post",dataType:"json",success:function(e){i.removeClass("flexdatalist-loading");var s=e.results?e.results:e;"string"==typeof s&&0===s.indexOf("[{")&&(s=JSON.parse(s)),r._isObject(s)&&(t(s),"string"==typeof a.data?a.data=s:r._isEmpty(a.url)||r._isEmpty(s)||i._cache(l,s))}})))},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 r._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),!r._isDefined(t))return r._isDefined(a,e)&&(t=a[e]),t;a[e]=t}return null},i._search=function(e,t){i._data(function(a){var s=[],n=[];r._isDefined(t)||(t=i._keyword()),"string"==typeof t&&(t=[t]);for(var l=i._options("groupBy"),o=0;o<t.length;o++)for(var u=t[o],f=0;f<a.length;f++){var d=i._matches(a[f],u);if(d)if(n.push(d),l){if(r._isDefined(d,l)){var c=d[l];r._isDefined(s,c)||(s[c]=[]),s[c].push(d)}}else s.push(d)}e(s,n)})},i._matches=function(e,t){for(var a=!1,s=i._options("searchIn"),n=0;n<s.length;n++){var l=s[n];if(r._isDefined(e,l)){var o=e[l];i._find(t,o,e)&&(e[l+"_highlight"]=i._highlight(t,o),a=!0)}}return a?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();i._selected()&&i._selected(!1)._value(""),s.groupBy?Object.keys(t).forEach(function(r){var n=t[r],l=s.groupBy,o=i._getHighlight(n[0],l,r);e("<li>").addClass("group").append(e("<span>").addClass("group-name").html(o)).append(e("<span>").addClass("group-item-count").text(" "+n.length)).appendTo(a);i._items(n,a)}):i._items(t,a);var r=a.find("li:not(.group)");r.on("click",function(){var t=e(this).data("item");t&&(i._selected(!0)._removeResults()._value(t),i.trigger("select:flexdatalist",[t,s]))}).hover(function(){r.removeClass("active"),e(this).addClass("active")},function(){e(this).removeClass("active")}),s.focusFirstResult&&r.filter(":first").addClass("active"),i._position()},i._getResultsContainer=function(){var t=i;i._options("multiple")&&(t=l);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",n)),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(),n=0===s.visibleProperties.length?s.searchIn:s.visibleProperties,l=0;l<n.length;l++){var o=n[l];if((!s.groupBy||s.groupBy!==o)&&r._isDefined(t,o)){var u={};if("thumb"===o)u=e("<img>").addClass("item item-"+o).attr("src",t[o]);else{var f=i._getHighlight(t,o);u=e("<span>").addClass("item item-"+o).html(f+" ")}u.appendTo(a)}}return a},i._removeResults=function(){return e("ul.flexdatalist-results").remove(),i},i._selected=function(e){var t="flexdatalist-selected";return r._isDefined(e)?(e?i.addClass(t):i.removeClass(t),i):i.hasClass(t)},i._values=function(t){return e.isArray(t)&&!r._isEmpty(t)?void e.each(t,function(e,t){i._value(t)}):void i._value(t)},i._value=function(t){var a=i._getText(t),r=i._getValue(t);if(i._options("multiple")){if(""===t)return i;n.val("");var o=e("<li>").addClass("value").append('<span class="text">'+a+"</span>").append('<span class="fdl-remove">&times;</span>').insertBefore(l.find("li.input-container"));o.find("span.fdl-remove").click(function(){var t=e(this).parent();if(i._toJSON()||i._toCSV()){var a=i._inputValue();a.splice(t.index(),1),i._inputValue(a)}t.remove()})}else a&&a!==n.val()&&n.val(a);return i._inputValue(r,a),s=i._keyword(),i},i._inputValue=function(e,t){var a=i._toJSON(),s=i._toCSV();return r._isDefined(e)?(r._isObject(e)&&(a&&!r._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(e){var t=e,a=i._options();return r._isObject(e)&&(t=e[a.searchIn[0]],t=r._isDefined(e,a.textProperty)?e[a.textProperty]:i._replacePlaceholders(e,a.textProperty,t)),t},i._getValue=function(t){var a=t,s=i._options();if(r._isObject(t))if(a=t[s.searchIn[0]],"*"===s.valueProperty)a=t;else if(r._isDefined(t,s.valueProperty))a=t[s.valueProperty];else if(i._toJSON()){var a={},n=s.valueProperty,l=s.textProperty;if(l){var o=l;"string"==typeof l&&(o=i._parsePlaceholders(l)),r._isObject(o)&&e.each(o,function(e,t){n.push(t)})}else r._isDefined(t,l)&&n.push(l);e.each(n,function(e,i){r._isDefined(t,i)&&(a[i]=t[i])})}if(s.multiple&&(i._toJSON()||i._toCSV())){var u=i._inputValue();!r._isEmpty(a)&&r._isObject(u)&&(u.push(a),a=u)}return a},i._replacePlaceholders=function(t,a,s){if(r._isObject(t)&&"string"==typeof a){var n=i._parsePlaceholders(a);if(!r._isEmpty(t)&&n)return e.each(n,function(e,i){r._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 n.val().replace(/^\s+/,"")},i._toJSON=function(){var e=i._options("valueProperty");return r._isObject(e)||"*"===e},i._toCSV=function(){return!i._toJSON()&&i._options("multiple")},i._getHighlight=function(e,t,i){return r._isDefined(e,t+"_highlight")?e[t+"_highlight"]:r._isDefined(e,t)?e[t]:i},i._position=function(){var t=n;i._options("multiple")&&(t=l),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, Code cleaning and improvements in usability

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

Fixes, Code cleaning and improvements in usability