<NME> jquery.flexdatalist.min.js
<BEF> jQuery.fn.flexdatalist=function(e,t){"use strict";var i=function(e){e.each(function(){var e=$(this),t=e.data("flexdatalist");e.removeClass("flexdatalist-set").attr("type","text").val(t&&t.originalValue?t.originalValue:"").removeData("flexdatalist").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})};if("string"==typeof e&&"reset"!==e){var a=$(this).data("flexdatalist");if("destroy"===e)i($(this));else if("value"===e){if("undefined"==typeof t)return this[0].fvalue.get();this[0].fvalue.set(t)}else if("add"===e){if("undefined"==typeof t)return this[0].debug("Missing value to add!");this[0].fvalue.add(t)}else if("toggle"===e){if("undefined"==typeof t)return this[0].debug("Missing value to toggle!");this[0].fvalue.toggle(t)}else if("remove"===e){if("undefined"==typeof t)return this[0].debug("Missing value to remove!");this[0].fvalue.remove(t)}else if(a&&"undefined"!=typeof a[e]){if("undefined"==typeof t)return a[e];a[e]=t,$(this).data("flexdatalist",a)}return this}this&&"undefined"!=typeof this[0]&&"undefined"!=typeof this[0].fvalue&&i($(this));var r=$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,cacheLifetime:60,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],iconProperty:"thumb",searchIn:["label"],searchContain:!1,searchEqual:!1,searchByWord:!1,searchDisabled:!1,searchDelay:300,normalizeString:null,multiple:!1,maxShownResults:100,removeOnBackspace:!0,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,allowDuplicateValues:!1,requestType:"get",resultsProperty:"results",keywordParamName:"keyword",limitOfValues:0,valuesSeparator:",",debug:!0},e);return this.each(function(e){var t=$(this),i=this,a=null,l="flex"+e,n=null,s=null,o=t.data("flexdatalist");o||(t.removeData("flexdatalist"),o=$.extend({},r,t.data(),{multiple:t.is("[multiple]"),originalValue:t[0].value,_values:[]})),this.init=function(){this.set.up(),this.fvalue.set(t.attr("value")),n.on("focus",function(e){i.action.redoSearchFocus(e),i.action.showAllResults(e)}).on("focusin",function(){s&&s.addClass("focus")}).on("input keydown",function(e){9===i.keyNum(e)&&i.results.remove(),i.action.keypressValue(e),i.action.backSpaceKeyRemove(e)}).on("input keyup",function(e){i.action.keypressSearch(e),i.action.copyValue(e),i.action.backSpaceKeyRemove(e)}).on("focusout",function(){s&&s.removeClass("focus")}),window.onresize=function(){i.position()}},this.action={keypressValue:function(e){if((188===i.keyNum(e)||13===i.keyNum(e))&&!o.selectionRequired&&o.multiple){var t=n[0].value;e.preventDefault(),i.fvalue.extract(t),i.results.remove()}},keypressSearch:function(e){var t=i.keyNum(e),r=n.val(),l=r.length;clearTimeout(a),0===l&&o.minLength>0||l<o.minLength?i.results.remove():(!t||13!==t&&(37>t||t>40))&&(i.results.remove(),a=setTimeout(function(){0===o.minLength&&l>0||o.minLength>0&&l>=o.minLength?i.search.get(function(e){i.results.show(e)}):i.results.remove()},o.searchDelay))},redoSearchFocus:function(e){var t=(i.fvalue.get(),n.val());t.length>0&&this.keypressSearch(e)},copyValue:function(e){if(13!==i.keyNum(e)){var t=n.val();o.multiple||(o.selectionRequired?i.fvalue.clear():i.fvalue.set(t))}},backSpaceKeyRemove:function(e){if(o.removeOnBackspace){var t=n.val(),a=n.data("_remove");a?(a.find(".fdl-remove").click(),n.data("_remove",null)):0===t.length&&o.multiple&&8===i.keyNum(e)&&n.data("_remove",n.parents("li:eq(0)").prev())}},showAllResults:function(){var e=n.val();e=$.trim(e),""===e&&0===o.minLength&&i.data.load(function(e){i.results.show(e)})}},this.set={up:function(){n=this.alias(),o.multiple?s=this.multipleInput(n):n.insertAfter(t),n.attr("autofocus")&&n.focus(),this.chained()},alias:function(){var e=t.clone(!1).attr({list:null,name:t.attr("name")?t.attr("name")+"-flexdatalist":null,id:t.attr("id")?t.attr("id")+"-flexdatalist":null,value:""}).addClass("flexdatalist-alias").removeClass("flexdatalist");return t.addClass("flexdatalist flexdatalist-set").prop("type","hidden"),e},multipleInput:function(e){return s=$('<ul tabindex="1">').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"),"background-color":t.css("background-color")}).insertAfter(t).click(function(){$(this).find("input").focus()}),$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(e).appendTo(s),s},chained:function(){if(o.relatives&&o.chainedRelatives){var e=function(e){o.relatives.each(function(){var a=i.isEmpty($(this).val()),r=i.isEmpty(t[0].value);e||!a&&r||i.fvalue.clear(),s?a&&s?s.addClass("disabled"):s.removeClass("disabled"):n.prop("disabled",a)})};o.relatives.on("change",function(){e()}),e(!0)}}},this.fvalue={get:function(e){var i=t[0].value;return o.multiple&&!e?this.toObj(i):this.toStr(i)},set:function(e,a){if(i.isEmpty(e))a||this.clear(!0);else{var r=this;this._normalize(e,function(e){a||r.clear(!0),i.isEmpty(e)||($.isArray(e)?$.each(e,function(e,t){r.extract(t,!0)}):r.extract(e,!0),t.trigger("change:flexdatalist",[e,null,o]).trigger("change"))})}return t},add:function(e){this.set(e,!0)},toggle:function(e){return this.multiple.toggle(e),t},remove:function(e){return this.multiple.remove(e),t},_normalize:function(e,t){if(this.isJSON()||this.isCSV())try{e=this.toObj(e)}catch(a){i.debug("Invalid JSON given")}if(this.isCSV()||"string"==typeof o.valueProperty){var r=o.searchIn,l=o.searchEqual;o.searchIn=o.valueProperty.split(","),o.searchEqual=!0,i.search.get(e,function(e){e&&e.length>0&&t(e),o.searchIn=r,o.searchEqual=l})}else t(e)},extract:function(e,a){var r=this.text(e),l=this.value(e);t[0].value;if(!i.isEmpty(e)){if(!l)return i.debug("No value found");if(!r)return i.debug("No text found")}r&&o._values.push(r),o.multiple?this.multiple.add(l,r):this.single(l,r),a||t.trigger("change:flexdatalist",[l,r,o]).trigger("change")},single:function(e,i){i&&i!==n.val()&&n.val(i,!0),t[0].value=e},multiple:{add:function(e,i){var a=this,r=this.li(e,i);r.click(function(){a.toggle($(this))}).find(".fdl-remove").click(function(){a.remove($(this).parent())}),t.trigger("before:flexdatalist.add",[e,i,o]),this.push(e),n.val("",!0),this.checkLimit(),t.trigger("after:flexdatalist.add",[e,i,o])},push:function(e){var a=i.fvalue.get();e=i.fvalue.toObj(e),a.push(e),e=i.fvalue.toStr(a),t[0].value=e},toggle:function(e){if(o.toggleSelected){e=this.findLi(e),t.trigger("before:flexdatalist.toggle",[e.data("value"),o]);var a=e.index(),r=i.fvalue.get();if(e.hasClass("disabled")){var l=e.data("value");r.splice(a,0,l),e.removeClass("disabled")}else r.splice(a,1),e.addClass("disabled");r=i.fvalue.toStr(r),i.value=r,t.trigger("after:flexdatalist.toggle",[e.data("value"),o]),t.trigger("change:flexdatalist",[e.data("value"),e.data("text"),o]).trigger("change")}},remove:function(e){e=this.findLi(e);var a=i.fvalue.get(),r=e.index();t.trigger("before:flexdatalist.remove",[l,e,o]);var l=a.splice(r,1);a=i.fvalue.toStr(a),t[0].value=a,e.remove(),t.trigger("after:flexdatalist.remove",[l,e,o]).trigger("change:flexdatalist",[e.data("value"),e.data("text"),o]).trigger("change"),o._values.splice(r,1),i.fvalue.multiple.checkLimit()},removeAll:function(e){t.trigger("before:flexdatalist.remove.all",[e,o]),s.find("li:not(.input-container)").remove(),t[0].value="",o._values=[],t.trigger("after:flexdatalist.remove.all",[e,o])},li:function(e,t){var i=s.find("li.input-container");return $("<li>").addClass("value"+(o.toggleSelected?" toggle":"")).append('<span class="text">'+t+"</span>").append('<span class="fdl-remove">&times;</span>').data({text:t,value:e}).insertBefore(i)},checkLimit:function(){var e=o.limitOfValues;if(e>0){var t=s.find("li.input-container"),i=o._values.length;e==i?t.hide():t.show()}},findLi:function(e){if("object"!=typeof e){var t=e;e=null,s.find("li:not(.input-container)").each(function(){var i=$(this);return i.data("value")===t?(e=i,!1):void 0})}return e},isEmpty:function(){return this.get().length>0}},value:function(e){var t=e;return i.isObject(e)&&(t=this.isJSON()?this.toStr(e):i.isDefined(e,o.valueProperty)?e[o.valueProperty]:i.isDefined(e,o.searchIn[0])?e[o.searchIn[0]]:null),t},text:function(e){var t=e;return i.isObject(e)&&(t=e[o.searchIn[0]],t=i.isDefined(e,o.textProperty)?e[o.textProperty]:this.placeholders.replace(e,o.textProperty,t)),$("<div>").html(t).text()},placeholders:{replace:function(e,t,a){if(i.isObject(e)&&"string"==typeof t){var r=this.parse(t);if(!i.isEmpty(e)&&r)return $.each(r,function(a,r){i.isDefined(e,r)&&(t=t.replace(a,e[r]))}),t}return a},parse: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}},clear:function(e){o.multiple&&this.multiple.removeAll();var i=t[0].value;return t[0].value="",""!==i&&t.trigger("change:flexdatalist",[null,null,o]).trigger("change"),e&&n.val("",!0),o._values=[],t},toObj:function(e){return"object"!=typeof e&&(i.isEmpty(e)||!i.isDefined(e)?e=[]:this.isCSV()?(e=e.toString().split(o.valuesSeparator),e=$.map(e,function(e){return $.trim(e)})):this.isJSON()&&(e=JSON.parse(e))),e},toStr:function(e){return"string"!=typeof e&&(i.isEmpty(e)||!i.isDefined(e)?e="":this.isCSV()?e=e.join(o.valuesSeparator):this.isJSON()&&(e=JSON.stringify(e))),$.trim(e)},isJSON:function(){var e=o.valueProperty;return i.isObject(e)||"*"===e},isCSV:function(){return!this.isJSON()&&o.multiple}},this.data={load:function(e){var a=this,r=[];t.trigger("before:flexdatalist.data"),this.url(function(l){r=r.concat(l),a["static"](function(l){r=r.concat(l),a.datalist(function(a){if(r=r.concat(a),!o.allowDuplicateValues)for(var l=o._values,n=0;n<r.length;n++){var s=r[n];l&&l.indexOf(i.fvalue.text(s))>-1&&r.splice(n,1)}t.trigger("after:flexdatalist.data",[r]),e(r)})})})},"static":function(e){if("string"==typeof o.data){var t=o.data,a=i.cache.read(t);if(a)return void e(a);this.remote({url:t,success:function(a){o.data=a,e(a),i.cache.write(t,a,o.cacheLifetime)}})}else"object"!=typeof o.data&&(o.data=[]),e(o.data)},datalist:function(e){var a=t.attr("list"),r=[];i.isEmpty(a)||$("#"+a).find("option").each(function(){var e=$(this),t=e.val(),i=e.text();r.push({label:i.length>0?i:t,value:t})}),e(r)},url:function(e){var t=n.val(),a=(o.keywordParamName,i.fvalue.get()),r=this.relativesData();if(i.isEmpty(o.url))return e([]);var l={};"post"===o.requestType&&($.each(o,function(e,t){0!=e.indexOf("_")&&"data"!=e&&(l[e]=t)}),delete l.relatives);var s=i.cache.keyGen({relative:r,keyword:t.substring(0,o.minLength>0?o.minLength:1),contain:o.searchContain},o.url),u=i.cache.read(s);return u?void e(u):void this.remote({url:o.url,data:$.extend(r,o.params,{keywordParamName:t,contain:o.searchContain,selected:a,original:o.originalValue,options:l}),success:function(a){var r=n.val();r.length>=t.length&&e(a),i.cache.write(s,a,o.cacheLifetime)}})},remote:function(e){var i=this;t.hasClass("flexdatalist-loading")||(t.addClass("flexdatalist-loading"),$.ajax($.extend({type:"post",dataType:"json",complete:function(){t.removeClass("flexdatalist-loading")}},e,{success:function(t){t=i.extractRemoteData(t),e.success(t)}})))},extractRemoteData:function(e){var t=i.isDefined(e,o.resultsProperty)?e[o.resultsProperty]:e;return"string"==typeof t&&0===t.indexOf("[{")&&(t=JSON.parse(t)),t&&t.options&&(o=$.extend({},o,t.options)),i.isObject(t)?t:[]},relativesData:function(){var e=o.relatives,t={};return e&&(t.relatives={},e.each(function(){var e=$(this),i=e.attr("name").split("][").join("-").split("]").join("-").split("[").join("-").replace(/^\|+|\-+$/g,"");t.relatives[i]=e.val()})),t}},this.search={get:function(e,a){var r=this;return o.searchDisabled?void i.debug("Search is disabled!"):("function"==typeof e&&(a=e,e=void 0),void i.data.load(function(l){var s=!1;i.isDefined(e)||(e=n.val());var o=i.cache.read(e);if(o)return void a(o);if(t.trigger("before:flexdatalist.search",[e,l]),!i.isEmpty(e)){s=[];for(var u=r.split(e),f=0;f<l.length;f++){var c=r.matches(l[f],u);c&&s.push(c)}}t.trigger("after:flexdatalist.search",[e,l,s]),a(s),i.cache.write(e,s,30)}))},matches:function(e,t){var a=$.extend({},e),r=[],l=o.searchIn;if(t.length>0)for(var n=0;n<l.length;n++){var s=l[n];if(i.isDefined(e,s)&&e[s]){for(var u=e[s].toString(),f=u,c=this.split(u),d=0;d<t.length;d++){var h=t[d];this.find(h,c)&&(r.push(h),f=this.highlight(h,f))}f!==u&&(a[s+"_highlight"]=this.highlight(f))}}return 0===r.length||o.searchByWord&&r.length<t.length-1?!1:a},highlight:function(e,t){return t?t.replace(new RegExp(e,o.searchContain?"ig":"i"),"|:|$&|::|"):(e=e.split("|:|").join('<span class="highlight">'),e.split("|::|").join("</span>"))},find:function(e,t){for(var i=0;i<t.length;i++){var a=t[i];if(a=this.normalizeString(a),e=this.normalizeString(e),o.searchEqual)return a==e;if(o.searchContain?a.indexOf(e)>=0:0===a.indexOf(e))return!0}return!1},split:function(e){if("string"==typeof e&&(e=[$.trim(e)]),o.searchByWord)for(var t=0;t<e.length;t++){var i=$.trim(e[t]);if(i.indexOf(" ")>0){var a=i.split(" ");$.merge(e,a)}}return e},normalizeString:function(e){if("string"==typeof e){var t=o.normalizeString;return"function"==typeof t&&(e=t(e)),e.toUpperCase()}return e}},this.results={show:function(e){var a=this;if(this.remove(!0),e){if(0===e.length)return void this.empty(o.noResultsText);var r=this.container();o.groupBy?(e=this.group(e),Object.keys(e).forEach(function(t){var l=e[t],n=o.groupBy,s=i.results.highlight(l[0],n,t);$("<li>").addClass("group").append($("<span>").addClass("group-name").html(s)).append($("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(r);a.items(l,r)})):this.items(e,r);var l=r.find("li:not(.group)");l.on("click",function(){var e=$(this).data("item");e&&(i.fvalue.extract(e),a.remove(),t.trigger("select:flexdatalist",[e,o]))}).hover(function(){l.removeClass("active"),$(this).addClass("active")},function(){$(this).removeClass("active")}),o.focusFirstResult&&l.filter(":first").addClass("active")}},empty:function(e){if(!i.isEmpty(e)){var t=this.container(),a=n.val();e=e.split("{keyword}").join(a),$("<li>").addClass("item no-results").append(e).appendTo(t)}},items:function(e,i){var a=o.maxShownResults;t.trigger("show:flexdatalist.results",[e]);for(var r=0;r<e.length&&!(a>0&&a===r);r++)this.item(e[r]).appendTo(i);t.trigger("shown:flexdatalist.results",[e])},item:function(e){for(var t=$("<li>").data("item",e).addClass("item"),a=o.visibleProperties,r=0;r<a.length;r++){var l=a[r];if((!o.groupBy||o.groupBy!==l)&&i.isDefined(e,l)){var n={};if(l===o.iconProperty)n=$("<img>").addClass("item item-"+l).attr("src",e[l]);else{var s=i.results.highlight(e,l);n=$("<span>").addClass("item item-"+l).html(s+" ")}n.appendTo(t)}}return t},container:function(){var e=t;o.multiple&&(e=s);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",n),i.position(n)),a},group:function(e){for(var t=[],a=o.groupBy,r=0;r<e.length;r++){var l=e[r];if(i.isDefined(l,a)){var n=l[a];i.isDefined(t,n)||(t[n]=[]),t[n].push(l)}}return t},highlight:function(e,t,a){return i.isDefined(e,t+"_highlight")?e[t+"_highlight"]:i.isDefined(e,t)?e[t]:a},remove:function(e){var t="ul.flexdatalist-results";e&&(t="ul.flexdatalist-results li"),$(t).remove()}},this.cache={write:function(e,t,a){if(i.cache.isSupported()){e=this.keyGen(e);var r={value:t,timestamp:i.unixtime(),lifetime:a?a:!1};localStorage.setItem(e,JSON.stringify(r))}},read:function(e){if(i.cache.isSupported()){e=this.keyGen(e);var t=localStorage.getItem(e);if(t){var a=JSON.parse(t);if(a.lifetime){var r=i.unixtime()-a.timestamp;return a.lifetime>r?a.value:(i.cache["delete"](e),null)}return a.value}}return null},"delete":function(e){i.cache.isSupported()&&(e=this.keyGen(e),localStorage.removeItem(e))},clear:function(){if(i.cache.isSupported()){for(var e in localStorage)e.indexOf(l)>-1&&i.cache["delete"](e);localStorage.clear()}},isSupported:function(){if(o.cache)try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}return!1},keyGen:function(e,t){"object"==typeof e&&(e=JSON.stringify(e));var i,a,r=void 0===t?2166136261:t;for(i=0,a=e.length;a>i;i++)r^=e.charCodeAt(i),r+=(r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24);return l+("0000000"+(r>>>0).toString(16)).substr(-8)}},this.position=function(){var e=$("input:focus:eq(0)");0===e.length&&(e=n),o.multiple&&(e=e.parents(".flexdatalist-multiple:eq(0)")),$("ul.flexdatalist-results").css({width:e.outerWidth()+"px",top:e.offset().top+e.outerHeight()+"px",left:e.offset().left+"px"})},this.keyNum=function(e){return e.which||e.keyCode},this.isEmpty=function(e){return i.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.length=function(e){return this.isObject(e)?Object.keys(e).length:"number"==typeof e||"number"==typeof e.length?e.toString().length:0},this.isDefined=function(e,t){var i="undefined"!=typeof e;return i&&"undefined"!=typeof t?"undefined"!=typeof e[t]:i},this.unixtime=function(e){var t=new Date;return e&&(t=new Date(e)),Math.round(t.getTime()/1e3)},this.csvToArray=function(e,t){return 0===e.length?t:"string"==typeof e?e.split(o.valuesSeparator):e},this.debug=function(e,i){o.debug&&(i||(i={}),e="Flexdatalist: "+e,console.warn(e),console.log($.extend({inputName:t.attr("name"),options:o},i)),console.log("--- /flexdatalist ---"))},o.searchIn=this.csvToArray(o.searchIn),o.relatives=o.relatives&&$(o.relatives).length>0?$(o.relatives):null,o.textProperty=null===o.textProperty?o.searchIn[0]:o.textProperty,o.visibleProperties=this.csvToArray(o.visibleProperties,o.searchIn),t.data("flexdatalist",o),this.init()})},jQuery(function(e){var t=e(document);t.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"),r=a.filter(".active"),l=r.index(),n=a.length,s=t.which||t.keyCode;if(0!==n){if(27===s)return i.remove();if(13===s)t.preventDefault(),r.click();else if(40===s||38===s){t.preventDefault(),40===s?r=n>l&&r.nextAll(".item").first().length>0?r.removeClass("active").nextAll(".item").first().addClass("active"):a.removeClass("active").filter(".item:first").addClass("active"):38===s&&(r=l>0&&r.prevAll(".item").first().length>0?r.removeClass("active").prevAll(".item").first().addClass("active"):a.removeClass("active").filter(".item:last").addClass("active"));var o=(0===r.prev().length?r:r.prev()).position().top;i.animate({scrollTop:o+i.scrollTop()},100)}}}).data("flexdatalist",!0),jQuery("input.flexdatalist:not(.flexdatalist-set)").flexdatalist()}),function(e){var t=e.fn.val;e.fn.val=function(i){var a=e(this).hasClass("flexdatalist");return"undefined"==typeof i?a?this[0].fvalue.get(!0):t.call(this):a?this[0].fvalue.set(i):t.call(this,i)}}(jQuery);
//# sourceMappingURL=jquery.flexdatalist.min.js.map
<MSG> minor changes

<DFF> @@ -1,1 +1,1 @@
-jQuery.fn.flexdatalist=function(e,t){"use strict";var i=function(e){e.each(function(){var e=$(this),t=e.data("flexdatalist");e.removeClass("flexdatalist-set").attr("type","text").val(t&&t.originalValue?t.originalValue:"").removeData("flexdatalist").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})};if("string"==typeof e&&"reset"!==e){var a=$(this).data("flexdatalist");if("destroy"===e)i($(this));else if("value"===e){if("undefined"==typeof t)return this[0].fvalue.get();this[0].fvalue.set(t)}else if("add"===e){if("undefined"==typeof t)return this[0].debug("Missing value to add!");this[0].fvalue.add(t)}else if("toggle"===e){if("undefined"==typeof t)return this[0].debug("Missing value to toggle!");this[0].fvalue.toggle(t)}else if("remove"===e){if("undefined"==typeof t)return this[0].debug("Missing value to remove!");this[0].fvalue.remove(t)}else if(a&&"undefined"!=typeof a[e]){if("undefined"==typeof t)return a[e];a[e]=t,$(this).data("flexdatalist",a)}return this}this&&"undefined"!=typeof this[0]&&"undefined"!=typeof this[0].fvalue&&i($(this));var r=$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,cacheLifetime:60,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],iconProperty:"thumb",searchIn:["label"],searchContain:!1,searchEqual:!1,searchByWord:!1,searchDisabled:!1,searchDelay:300,normalizeString:null,multiple:!1,maxShownResults:100,removeOnBackspace:!0,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,allowDuplicateValues:!1,requestType:"get",resultsProperty:"results",keywordParamName:"keyword",limitOfValues:0,valuesSeparator:",",debug:!0},e);return this.each(function(e){var t=$(this),i=this,a=null,l="flex"+e,n=null,s=null,o=t.data("flexdatalist");o||(t.removeData("flexdatalist"),o=$.extend({},r,t.data(),{multiple:t.is("[multiple]"),originalValue:t[0].value,_values:[]})),this.init=function(){this.set.up(),this.fvalue.set(t.attr("value")),n.on("focus",function(e){i.action.redoSearchFocus(e),i.action.showAllResults(e)}).on("focusin",function(){s&&s.addClass("focus")}).on("input keydown",function(e){9===i.keyNum(e)&&i.results.remove(),i.action.keypressValue(e),i.action.backSpaceKeyRemove(e)}).on("input keyup",function(e){i.action.keypressSearch(e),i.action.copyValue(e),i.action.backSpaceKeyRemove(e)}).on("focusout",function(){s&&s.removeClass("focus")}),window.onresize=function(){i.position()}},this.action={keypressValue:function(e){if((188===i.keyNum(e)||13===i.keyNum(e))&&!o.selectionRequired&&o.multiple){var t=n[0].value;e.preventDefault(),i.fvalue.extract(t),i.results.remove()}},keypressSearch:function(e){var t=i.keyNum(e),r=n.val(),l=r.length;clearTimeout(a),0===l&&o.minLength>0||l<o.minLength?i.results.remove():(!t||13!==t&&(37>t||t>40))&&(i.results.remove(),a=setTimeout(function(){0===o.minLength&&l>0||o.minLength>0&&l>=o.minLength?i.search.get(function(e){i.results.show(e)}):i.results.remove()},o.searchDelay))},redoSearchFocus:function(e){var t=(i.fvalue.get(),n.val());t.length>0&&this.keypressSearch(e)},copyValue:function(e){if(13!==i.keyNum(e)){var t=n.val();o.multiple||(o.selectionRequired?i.fvalue.clear():i.fvalue.set(t))}},backSpaceKeyRemove:function(e){if(o.removeOnBackspace){var t=n.val(),a=n.data("_remove");a?(a.find(".fdl-remove").click(),n.data("_remove",null)):0===t.length&&o.multiple&&8===i.keyNum(e)&&n.data("_remove",n.parents("li:eq(0)").prev())}},showAllResults:function(){var e=n.val();e=$.trim(e),""===e&&0===o.minLength&&i.data.load(function(e){i.results.show(e)})}},this.set={up:function(){n=this.alias(),o.multiple?s=this.multipleInput(n):n.insertAfter(t),n.attr("autofocus")&&n.focus(),this.chained()},alias:function(){var e=t.clone(!1).attr({list:null,name:t.attr("name")?t.attr("name")+"-flexdatalist":null,id:t.attr("id")?t.attr("id")+"-flexdatalist":null,value:""}).addClass("flexdatalist-alias").removeClass("flexdatalist");return t.addClass("flexdatalist flexdatalist-set").prop("type","hidden"),e},multipleInput:function(e){return s=$('<ul tabindex="1">').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"),"background-color":t.css("background-color")}).insertAfter(t).click(function(){$(this).find("input").focus()}),$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(e).appendTo(s),s},chained:function(){if(o.relatives&&o.chainedRelatives){var e=function(e){o.relatives.each(function(){var a=i.isEmpty($(this).val()),r=i.isEmpty(t[0].value);e||!a&&r||i.fvalue.clear(),s?a&&s?s.addClass("disabled"):s.removeClass("disabled"):n.prop("disabled",a)})};o.relatives.on("change",function(){e()}),e(!0)}}},this.fvalue={get:function(e){var i=t[0].value;return o.multiple&&!e?this.toObj(i):this.toStr(i)},set:function(e,a){if(i.isEmpty(e))a||this.clear(!0);else{var r=this;this._normalize(e,function(e){a||r.clear(!0),i.isEmpty(e)||($.isArray(e)?$.each(e,function(e,t){r.extract(t,!0)}):r.extract(e,!0),t.trigger("change:flexdatalist",[e,null,o]).trigger("change"))})}return t},add:function(e){this.set(e,!0)},toggle:function(e){return this.multiple.toggle(e),t},remove:function(e){return this.multiple.remove(e),t},_normalize:function(e,t){if(this.isJSON()||this.isCSV())try{e=this.toObj(e)}catch(a){i.debug("Invalid JSON given")}if(this.isCSV()||"string"==typeof o.valueProperty){var r=o.searchIn,l=o.searchEqual;o.searchIn=o.valueProperty.split(","),o.searchEqual=!0,i.search.get(e,function(e){e&&e.length>0&&t(e),o.searchIn=r,o.searchEqual=l})}else t(e)},extract:function(e,a){var r=this.text(e),l=this.value(e);t[0].value;if(!i.isEmpty(e)){if(!l)return i.debug("No value found");if(!r)return i.debug("No text found")}r&&o._values.push(r),o.multiple?this.multiple.add(l,r):this.single(l,r),a||t.trigger("change:flexdatalist",[l,r,o]).trigger("change")},single:function(e,i){i&&i!==n.val()&&n.val(i,!0),t[0].value=e},multiple:{add:function(e,i){var a=this,r=this.li(e,i);r.click(function(){a.toggle($(this))}).find(".fdl-remove").click(function(){a.remove($(this).parent())}),t.trigger("before:flexdatalist.add",[e,i,o]),this.push(e),n.val("",!0),this.checkLimit(),t.trigger("after:flexdatalist.add",[e,i,o])},push:function(e){var a=i.fvalue.get();e=i.fvalue.toObj(e),a.push(e),e=i.fvalue.toStr(a),t[0].value=e},toggle:function(e){if(o.toggleSelected){e=this.findLi(e),t.trigger("before:flexdatalist.toggle",[e.data("value"),o]);var a=e.index(),r=i.fvalue.get();if(e.hasClass("disabled")){var l=e.data("value");r.splice(a,0,l),e.removeClass("disabled")}else r.splice(a,1),e.addClass("disabled");r=i.fvalue.toStr(r),i.value=r,t.trigger("after:flexdatalist.toggle",[e.data("value"),o]),t.trigger("change:flexdatalist",[e.data("value"),e.data("text"),o]).trigger("change")}},remove:function(e){e=this.findLi(e);var a=i.fvalue.get(),r=e.index();t.trigger("before:flexdatalist.remove",[l,e,o]);var l=a.splice(r,1);a=i.fvalue.toStr(a),t[0].value=a,e.remove(),t.trigger("after:flexdatalist.remove",[l,e,o]).trigger("change:flexdatalist",[e.data("value"),e.data("text"),o]).trigger("change"),o._values.splice(r,1),i.fvalue.multiple.checkLimit()},removeAll:function(e){t.trigger("before:flexdatalist.remove.all",[e,o]),s.find("li:not(.input-container)").remove(),t[0].value="",o._values=[],t.trigger("after:flexdatalist.remove.all",[e,o])},li:function(e,t){var i=s.find("li.input-container");return $("<li>").addClass("value"+(o.toggleSelected?" toggle":"")).append('<span class="text">'+t+"</span>").append('<span class="fdl-remove">&times;</span>').data({text:t,value:e}).insertBefore(i)},checkLimit:function(){var e=o.limitOfValues;if(e>0){var t=s.find("li.input-container"),i=o._values.length;e==i?t.hide():t.show()}},findLi:function(e){if("object"!=typeof e){var t=e;e=null,s.find("li:not(.input-container)").each(function(){var i=$(this);return i.data("value")===t?(e=i,!1):void 0})}return e},isEmpty:function(){return this.get().length>0}},value:function(e){var t=e;return i.isObject(e)&&(t=this.isJSON()?this.toStr(e):i.isDefined(e,o.valueProperty)?e[o.valueProperty]:i.isDefined(e,o.searchIn[0])?e[o.searchIn[0]]:null),t},text:function(e){var t=e;return i.isObject(e)&&(t=e[o.searchIn[0]],t=i.isDefined(e,o.textProperty)?e[o.textProperty]:this.placeholders.replace(e,o.textProperty,t)),$("<div>").html(t).text()},placeholders:{replace:function(e,t,a){if(i.isObject(e)&&"string"==typeof t){var r=this.parse(t);if(!i.isEmpty(e)&&r)return $.each(r,function(a,r){i.isDefined(e,r)&&(t=t.replace(a,e[r]))}),t}return a},parse: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}},clear:function(e){o.multiple&&this.multiple.removeAll();var i=t[0].value;return t[0].value="",""!==i&&t.trigger("change:flexdatalist",[null,null,o]).trigger("change"),e&&n.val("",!0),o._values=[],t},toObj:function(e){return"object"!=typeof e&&(i.isEmpty(e)||!i.isDefined(e)?e=[]:this.isCSV()?(e=e.toString().split(o.valuesSeparator),e=$.map(e,function(e){return $.trim(e)})):this.isJSON()&&(e=JSON.parse(e))),e},toStr:function(e){return"string"!=typeof e&&(i.isEmpty(e)||!i.isDefined(e)?e="":this.isCSV()?e=e.join(o.valuesSeparator):this.isJSON()&&(e=JSON.stringify(e))),$.trim(e)},isJSON:function(){var e=o.valueProperty;return i.isObject(e)||"*"===e},isCSV:function(){return!this.isJSON()&&o.multiple}},this.data={load:function(e){var a=this,r=[];t.trigger("before:flexdatalist.data"),this.url(function(l){r=r.concat(l),a["static"](function(l){r=r.concat(l),a.datalist(function(a){if(r=r.concat(a),!o.allowDuplicateValues)for(var l=o._values,n=0;n<r.length;n++){var s=r[n];l&&l.indexOf(i.fvalue.text(s))>-1&&r.splice(n,1)}t.trigger("after:flexdatalist.data",[r]),e(r)})})})},"static":function(e){if("string"==typeof o.data){var t=o.data,a=i.cache.read(t);if(a)return void e(a);this.remote({url:t,success:function(a){o.data=a,e(a),i.cache.write(t,a,o.cacheLifetime)}})}else"object"!=typeof o.data&&(o.data=[]),e(o.data)},datalist:function(e){var a=t.attr("list"),r=[];i.isEmpty(a)||$("#"+a).find("option").each(function(){var e=$(this),t=e.val(),i=e.text();r.push({label:i.length>0?i:t,value:t})}),e(r)},url:function(e){var t=n.val(),a=(o.keywordParamName,i.fvalue.get()),r=this.relativesData();if(i.isEmpty(o.url))return e([]);var l={};"post"===o.requestType&&($.each(o,function(e,t){0!=e.indexOf("_")&&"data"!=e&&(l[e]=t)}),delete l.relatives);var s=i.cache.keyGen({relative:r,keyword:t.substring(0,o.minLength>0?o.minLength:1),contain:o.searchContain},o.url),u=i.cache.read(s);return u?void e(u):void this.remote({url:o.url,data:$.extend(r,o.params,{keywordParamName:t,contain:o.searchContain,selected:a,original:o.originalValue,options:l}),success:function(a){var r=n.val();r.length>=t.length&&e(a),i.cache.write(s,a,o.cacheLifetime)}})},remote:function(e){var i=this;t.hasClass("flexdatalist-loading")||(t.addClass("flexdatalist-loading"),$.ajax($.extend({type:"post",dataType:"json",complete:function(){t.removeClass("flexdatalist-loading")}},e,{success:function(t){t=i.extractRemoteData(t),e.success(t)}})))},extractRemoteData:function(e){var t=i.isDefined(e,o.resultsProperty)?e[o.resultsProperty]:e;return"string"==typeof t&&0===t.indexOf("[{")&&(t=JSON.parse(t)),t&&t.options&&(o=$.extend({},o,t.options)),i.isObject(t)?t:[]},relativesData:function(){var e=o.relatives,t={};return e&&(t.relatives={},e.each(function(){var e=$(this),i=e.attr("name").split("][").join("-").split("]").join("-").split("[").join("-").replace(/^\|+|\-+$/g,"");t.relatives[i]=e.val()})),t}},this.search={get:function(e,a){var r=this;return o.searchDisabled?void i.debug("Search is disabled!"):("function"==typeof e&&(a=e,e=void 0),void i.data.load(function(l){var s=!1;i.isDefined(e)||(e=n.val());var o=i.cache.read(e);if(o)return void a(o);if(t.trigger("before:flexdatalist.search",[e,l]),!i.isEmpty(e)){s=[];for(var u=r.split(e),f=0;f<l.length;f++){var c=r.matches(l[f],u);c&&s.push(c)}}t.trigger("after:flexdatalist.search",[e,l,s]),a(s),i.cache.write(e,s,30)}))},matches:function(e,t){var a=$.extend({},e),r=[],l=o.searchIn;if(t.length>0)for(var n=0;n<l.length;n++){var s=l[n];if(i.isDefined(e,s)&&e[s]){for(var u=e[s].toString(),f=u,c=this.split(u),d=0;d<t.length;d++){var h=t[d];this.find(h,c)&&(r.push(h),f=this.highlight(h,f))}f!==u&&(a[s+"_highlight"]=this.highlight(f))}}return 0===r.length||o.searchByWord&&r.length<t.length-1?!1:a},highlight:function(e,t){return t?t.replace(new RegExp(e,o.searchContain?"ig":"i"),"|:|$&|::|"):(e=e.split("|:|").join('<span class="highlight">'),e.split("|::|").join("</span>"))},find:function(e,t){for(var i=0;i<t.length;i++){var a=t[i];if(a=this.normalizeString(a),e=this.normalizeString(e),o.searchEqual)return a==e;if(o.searchContain?a.indexOf(e)>=0:0===a.indexOf(e))return!0}return!1},split:function(e){if("string"==typeof e&&(e=[$.trim(e)]),o.searchByWord)for(var t=0;t<e.length;t++){var i=$.trim(e[t]);if(i.indexOf(" ")>0){var a=i.split(" ");$.merge(e,a)}}return e},normalizeString:function(e){if("string"==typeof e){var t=o.normalizeString;return"function"==typeof t&&(e=t(e)),e.toUpperCase()}return e}},this.results={show:function(e){var a=this;if(this.remove(!0),e){if(0===e.length)return void this.empty(o.noResultsText);var r=this.container();o.groupBy?(e=this.group(e),Object.keys(e).forEach(function(t){var l=e[t],n=o.groupBy,s=i.results.highlight(l[0],n,t);$("<li>").addClass("group").append($("<span>").addClass("group-name").html(s)).append($("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(r);a.items(l,r)})):this.items(e,r);var l=r.find("li:not(.group)");l.on("click",function(){var e=$(this).data("item");e&&(i.fvalue.extract(e),a.remove(),t.trigger("select:flexdatalist",[e,o]))}).hover(function(){l.removeClass("active"),$(this).addClass("active")},function(){$(this).removeClass("active")}),o.focusFirstResult&&l.filter(":first").addClass("active")}},empty:function(e){if(!i.isEmpty(e)){var t=this.container(),a=n.val();e=e.split("{keyword}").join(a),$("<li>").addClass("item no-results").append(e).appendTo(t)}},items:function(e,i){var a=o.maxShownResults;t.trigger("show:flexdatalist.results",[e]);for(var r=0;r<e.length&&!(a>0&&a===r);r++)this.item(e[r]).appendTo(i);t.trigger("shown:flexdatalist.results",[e])},item:function(e){for(var t=$("<li>").data("item",e).addClass("item"),a=o.visibleProperties,r=0;r<a.length;r++){var l=a[r];if((!o.groupBy||o.groupBy!==l)&&i.isDefined(e,l)){var n={};if(l===o.iconProperty)n=$("<img>").addClass("item item-"+l).attr("src",e[l]);else{var s=i.results.highlight(e,l);n=$("<span>").addClass("item item-"+l).html(s+" ")}n.appendTo(t)}}return t},container:function(){var e=t;o.multiple&&(e=s);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",n),i.position(n)),a},group:function(e){for(var t=[],a=o.groupBy,r=0;r<e.length;r++){var l=e[r];if(i.isDefined(l,a)){var n=l[a];i.isDefined(t,n)||(t[n]=[]),t[n].push(l)}}return t},highlight:function(e,t,a){return i.isDefined(e,t+"_highlight")?e[t+"_highlight"]:i.isDefined(e,t)?e[t]:a},remove:function(e){var t="ul.flexdatalist-results";e&&(t="ul.flexdatalist-results li"),$(t).remove()}},this.cache={write:function(e,t,a){if(i.cache.isSupported()){e=this.keyGen(e);var r={value:t,timestamp:i.unixtime(),lifetime:a?a:!1};localStorage.setItem(e,JSON.stringify(r))}},read:function(e){if(i.cache.isSupported()){e=this.keyGen(e);var t=localStorage.getItem(e);if(t){var a=JSON.parse(t);if(a.lifetime){var r=i.unixtime()-a.timestamp;return a.lifetime>r?a.value:(i.cache["delete"](e),null)}return a.value}}return null},"delete":function(e){i.cache.isSupported()&&(e=this.keyGen(e),localStorage.removeItem(e))},clear:function(){if(i.cache.isSupported()){for(var e in localStorage)e.indexOf(l)>-1&&i.cache["delete"](e);localStorage.clear()}},isSupported:function(){if(o.cache)try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}return!1},keyGen:function(e,t){"object"==typeof e&&(e=JSON.stringify(e));var i,a,r=void 0===t?2166136261:t;for(i=0,a=e.length;a>i;i++)r^=e.charCodeAt(i),r+=(r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24);return l+("0000000"+(r>>>0).toString(16)).substr(-8)}},this.position=function(){var e=$("input:focus:eq(0)");0===e.length&&(e=n),o.multiple&&(e=e.parents(".flexdatalist-multiple:eq(0)")),$("ul.flexdatalist-results").css({width:e.outerWidth()+"px",top:e.offset().top+e.outerHeight()+"px",left:e.offset().left+"px"})},this.keyNum=function(e){return e.which||e.keyCode},this.isEmpty=function(e){return i.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.length=function(e){return this.isObject(e)?Object.keys(e).length:"number"==typeof e||"number"==typeof e.length?e.toString().length:0},this.isDefined=function(e,t){var i="undefined"!=typeof e;return i&&"undefined"!=typeof t?"undefined"!=typeof e[t]:i},this.unixtime=function(e){var t=new Date;return e&&(t=new Date(e)),Math.round(t.getTime()/1e3)},this.csvToArray=function(e,t){return 0===e.length?t:"string"==typeof e?e.split(o.valuesSeparator):e},this.debug=function(e,i){o.debug&&(i||(i={}),e="Flexdatalist: "+e,console.warn(e),console.log($.extend({inputName:t.attr("name"),options:o},i)),console.log("--- /flexdatalist ---"))},o.searchIn=this.csvToArray(o.searchIn),o.relatives=o.relatives&&$(o.relatives).length>0?$(o.relatives):null,o.textProperty=null===o.textProperty?o.searchIn[0]:o.textProperty,o.visibleProperties=this.csvToArray(o.visibleProperties,o.searchIn),t.data("flexdatalist",o),this.init()})},jQuery(function(e){var t=e(document);t.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"),r=a.filter(".active"),l=r.index(),n=a.length,s=t.which||t.keyCode;if(0!==n){if(27===s)return i.remove();if(13===s)t.preventDefault(),r.click();else if(40===s||38===s){t.preventDefault(),40===s?r=n>l&&r.nextAll(".item").first().length>0?r.removeClass("active").nextAll(".item").first().addClass("active"):a.removeClass("active").filter(".item:first").addClass("active"):38===s&&(r=l>0&&r.prevAll(".item").first().length>0?r.removeClass("active").prevAll(".item").first().addClass("active"):a.removeClass("active").filter(".item:last").addClass("active"));var o=(0===r.prev().length?r:r.prev()).position().top;i.animate({scrollTop:o+i.scrollTop()},100)}}}).data("flexdatalist",!0),jQuery("input.flexdatalist:not(.flexdatalist-set)").flexdatalist()}),function(e){var t=e.fn.val;e.fn.val=function(i){var a=e(this).hasClass("flexdatalist");return"undefined"==typeof i?a?this[0].fvalue.get(!0):t.call(this):a?this[0].fvalue.set(i):t.call(this,i)}}(jQuery);
\ No newline at end of file
+jQuery.fn.flexdatalist=function(e,t){"use strict";var i=function(e){e.each(function(){var e=$(this),t=e.data("flexdatalist");e.removeClass("flexdatalist-set").attr("type","text").val(t&&t.originalValue?t.originalValue:"").removeData("flexdatalist").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})};if("string"==typeof e&&"reset"!==e){var a=$(this).data("flexdatalist");if("destroy"===e)i($(this));else if("value"===e){if("undefined"==typeof t)return this[0].fvalue.get();this[0].fvalue.set(t)}else if("add"===e){if("undefined"==typeof t)return this[0].debug("Missing value to add!");this[0].fvalue.add(t)}else if("toggle"===e){if("undefined"==typeof t)return this[0].debug("Missing value to toggle!");this[0].fvalue.toggle(t)}else if("remove"===e){if("undefined"==typeof t)return this[0].debug("Missing value to remove!");this[0].fvalue.remove(t)}else if(a&&"undefined"!=typeof a[e]){if("undefined"==typeof t)return a[e];a[e]=t,$(this).data("flexdatalist",a)}return this}this&&"undefined"!=typeof this[0]&&"undefined"!=typeof this[0].fvalue&&i($(this));var r=$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,cacheLifetime:60,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],iconProperty:"thumb",searchIn:["label"],searchContain:!1,searchEqual:!1,searchByWord:!1,searchDisabled:!1,searchDelay:300,normalizeString:null,multiple:!1,maxShownResults:100,removeOnBackspace:!0,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,allowDuplicateValues:!1,requestType:"get",resultsProperty:"results",keywordParamName:"keyword",limitOfValues:0,valuesSeparator:",",debug:!0},e);return this.each(function(e){var t=$(this),i=this,a=null,l="flex"+e,s=null,n=null,o=t.data("flexdatalist");o||(t.removeData("flexdatalist"),o=$.extend({},r,t.data(),{multiple:t.is("[multiple]"),originalValue:t[0].value,_values:[]})),this.init=function(){this.set.up(),this.fvalue.set(t.attr("value")),s.on("focus",function(e){i.action.redoSearchFocus(e),i.action.showAllResults(e)}).on("focusin",function(){n&&n.addClass("focus")}).on("input keydown",function(e){9===i.keyNum(e)&&i.results.remove(),i.action.keypressValue(e),i.action.backSpaceKeyRemove(e)}).on("input keyup",function(e){i.action.keypressSearch(e),i.action.copyValue(e),i.action.backSpaceKeyRemove(e)}).on("focusout",function(){n&&n.removeClass("focus")}),window.onresize=function(){i.position()}},this.action={keypressValue:function(e){if((188===i.keyNum(e)||13===i.keyNum(e))&&!o.selectionRequired&&o.multiple){var t=s[0].value;e.preventDefault(),i.fvalue.extract(t),i.results.remove()}},keypressSearch:function(e){var t=i.keyNum(e),r=s.val(),l=r.length;clearTimeout(a),0===l&&o.minLength>0||l<o.minLength?i.results.remove():(!t||13!==t&&(37>t||t>40))&&(i.results.remove(),a=setTimeout(function(){0===o.minLength&&l>0||o.minLength>0&&l>=o.minLength?i.search.get(function(e){i.results.show(e)}):i.results.remove()},o.searchDelay))},redoSearchFocus:function(e){var t=(i.fvalue.get(),s.val());t.length>0&&this.keypressSearch(e)},copyValue:function(e){if(13!==i.keyNum(e)){var t=s.val();o.multiple||(o.selectionRequired?i.fvalue.clear():i.fvalue.set(t))}},backSpaceKeyRemove:function(e){if(o.removeOnBackspace){var t=s.val(),a=s.data("_remove");a?(a.find(".fdl-remove").click(),s.data("_remove",null)):0===t.length&&o.multiple&&8===i.keyNum(e)&&s.data("_remove",s.parents("li:eq(0)").prev())}},showAllResults:function(){var e=s.val();e=$.trim(e),""===e&&0===o.minLength&&i.data.load(function(e){i.results.show(e)})}},this.set={up:function(){s=this.alias(),o.multiple?n=this.multipleInput(s):s.insertAfter(t),s.attr("autofocus")&&s.focus(),this.chained()},alias:function(){var e=t.clone(!1).attr({list:null,name:t.attr("name")?t.attr("name")+"-flexdatalist":null,id:t.attr("id")?t.attr("id")+"-flexdatalist":null,value:""}).addClass("flexdatalist-alias").removeClass("flexdatalist");return t.addClass("flexdatalist flexdatalist-set").prop("type","hidden"),e},multipleInput:function(e){return n=$('<ul tabindex="1">').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"),"background-color":t.css("background-color")}).insertAfter(t).click(function(){$(this).find("input").focus()}),$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(e).appendTo(n),n},chained:function(){if(o.relatives&&o.chainedRelatives){var e=function(e){o.relatives.each(function(){var a=i.isEmpty($(this).val()),r=i.isEmpty(t[0].value);e||!a&&r||i.fvalue.clear(),n?a&&n?n.addClass("disabled"):n.removeClass("disabled"):s.prop("disabled",a)})};o.relatives.on("change",function(){e()}),e(!0)}}},this.fvalue={get:function(e){var i=t[0].value;return o.multiple&&!e?this.toObj(i):this.toStr(i)},set:function(e,a){if(i.isEmpty(e))a||this.clear(!0);else{var r=this;this._normalize(e,function(e){a||r.clear(!0),i.isEmpty(e)||($.isArray(e)?$.each(e,function(e,t){r.extract(t,!0)}):r.extract(e,!0),t.trigger("change:flexdatalist",[e,null,o]).trigger("change"))})}return t},add:function(e){this.set(e,!0)},toggle:function(e){return this.multiple.toggle(e),t},remove:function(e){return this.multiple.remove(e),t},_normalize:function(e,t){if(this.isJSON()||this.isCSV())try{e=this.toObj(e)}catch(a){i.debug("Invalid JSON given")}if(this.isCSV()||"string"==typeof o.valueProperty){var r=o.searchIn,l=o.searchEqual;o.searchIn=o.valueProperty.split(","),o.searchEqual=!0,i.search.get(e,function(e){e&&e.length>0&&t(e),o.searchIn=r,o.searchEqual=l})}else t(e)},extract:function(e,a){var r=this.text(e),l=this.value(e);t[0].value;if(!i.isEmpty(e)){if(!l)return i.debug("No value found");if(!r)return i.debug("No text found")}r&&o._values.push(r),o.multiple?this.multiple.add(l,r):this.single(l,r),a||t.trigger("change:flexdatalist",[l,r,o]).trigger("change")},single:function(e,i){i&&i!==s.val()&&s.val(i,!0),t[0].value=e},multiple:{add:function(e,i){var a=this,r=this.li(e,i);r.click(function(){a.toggle($(this))}).find(".fdl-remove").click(function(){a.remove($(this).parent())}),t.trigger("before:flexdatalist.add",[e,i,o]),this.push(e),s.val("",!0),this.checkLimit(),t.trigger("after:flexdatalist.add",[e,i,o])},push:function(e){var a=i.fvalue.get();e=i.fvalue.toObj(e),a.push(e),e=i.fvalue.toStr(a),t[0].value=e},toggle:function(e){if(o.toggleSelected){e=this.findLi(e),t.trigger("before:flexdatalist.toggle",[e.data("value"),o]);var a=e.index(),r=i.fvalue.get();if(e.hasClass("disabled")){var l=e.data("value");r.splice(a,0,l),e.removeClass("disabled")}else r.splice(a,1),e.addClass("disabled");r=i.fvalue.toStr(r),i.value=r,t.trigger("after:flexdatalist.toggle",[e.data("value"),o]),t.trigger("change:flexdatalist",[e.data("value"),e.data("text"),o]).trigger("change")}},remove:function(e){e=this.findLi(e);var a=i.fvalue.get(),r=e.index();t.trigger("before:flexdatalist.remove",[l,e,o]);var l=a.splice(r,1);a=i.fvalue.toStr(a),t[0].value=a,e.remove(),t.trigger("after:flexdatalist.remove",[l,e,o]).trigger("change:flexdatalist",[e.data("value"),e.data("text"),o]).trigger("change"),o._values.splice(r,1),i.fvalue.multiple.checkLimit()},removeAll:function(e){t.trigger("before:flexdatalist.remove.all",[e,o]),n.find("li:not(.input-container)").remove(),t[0].value="",o._values=[],t.trigger("after:flexdatalist.remove.all",[e,o])},li:function(e,t){var i=n.find("li.input-container");return $("<li>").addClass("value"+(o.toggleSelected?" toggle":"")).append('<span class="text">'+t+"</span>").append('<span class="fdl-remove">&times;</span>').data({text:t,value:e}).insertBefore(i)},checkLimit:function(){var e=o.limitOfValues;if(e>0){var t=n.find("li.input-container"),i=o._values.length;e==i?t.hide():t.show()}},findLi:function(e){if("object"!=typeof e){var t=e;e=null,n.find("li:not(.input-container)").each(function(){var i=$(this);return i.data("value")===t?(e=i,!1):void 0})}return e},isEmpty:function(){return this.get().length>0}},value:function(e){var t=e;return i.isObject(e)&&(t=this.isJSON()?this.toStr(e):i.isDefined(e,o.valueProperty)?e[o.valueProperty]:i.isDefined(e,o.searchIn[0])?e[o.searchIn[0]]:null),t},text:function(e){var t=e;return i.isObject(e)&&(t=e[o.searchIn[0]],t=i.isDefined(e,o.textProperty)?e[o.textProperty]:this.placeholders.replace(e,o.textProperty,t)),$("<div>").html(t).text()},placeholders:{replace:function(e,t,a){if(i.isObject(e)&&"string"==typeof t){var r=this.parse(t);if(!i.isEmpty(e)&&r)return $.each(r,function(a,r){i.isDefined(e,r)&&(t=t.replace(a,e[r]))}),t}return a},parse: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}},clear:function(e){o.multiple&&this.multiple.removeAll();var i=t[0].value;return t[0].value="",""!==i&&t.trigger("change:flexdatalist",[null,null,o]).trigger("change"),e&&s.val("",!0),o._values=[],t},toObj:function(e){return"object"!=typeof e&&(i.isEmpty(e)||!i.isDefined(e)?e=[]:this.isCSV()?(e=e.toString().split(o.valuesSeparator),e=$.map(e,function(e){return $.trim(e)})):this.isJSON()&&(e=JSON.parse(e))),e},toStr:function(e){return"string"!=typeof e&&(i.isEmpty(e)||!i.isDefined(e)?e="":this.isCSV()?e=e.join(o.valuesSeparator):this.isJSON()&&(e=JSON.stringify(e))),$.trim(e)},isJSON:function(){var e=o.valueProperty;return i.isObject(e)||"*"===e},isCSV:function(){return!this.isJSON()&&o.multiple}},this.data={load:function(e){var a=this,r=[];t.trigger("before:flexdatalist.data"),this.url(function(l){r=r.concat(l),a["static"](function(l){r=r.concat(l),a.datalist(function(a){if(r=r.concat(a),!o.allowDuplicateValues)for(var l=o._values,s=0;s<r.length;s++){var n=r[s];l&&l.indexOf(i.fvalue.text(n))>-1&&r.splice(s,1)}t.trigger("after:flexdatalist.data",[r]),e(r)})})})},"static":function(e){if("string"==typeof o.data){var t=o.data,a=i.cache.read(t);if(a)return void e(a);this.remote({url:t,success:function(a){o.data=a,e(a),i.cache.write(t,a,o.cacheLifetime)}})}else"object"!=typeof o.data&&(o.data=[]),e(o.data)},datalist:function(e){var a=t.attr("list"),r=[];i.isEmpty(a)||$("#"+a).find("option").each(function(){var e=$(this),t=e.val(),i=e.text();r.push({label:i.length>0?i:t,value:t})}),e(r)},url:function(e){var t=s.val(),a=(o.keywordParamName,i.fvalue.get()),r=this.relativesData();if(i.isEmpty(o.url))return e([]);var l={};"post"===o.requestType&&($.each(o,function(e,t){0!=e.indexOf("_")&&"data"!=e&&(l[e]=t)}),delete l.relatives);var n=i.cache.keyGen({relative:r,keyword:t.substring(0,o.minLength>0?o.minLength:1),contain:o.searchContain},o.url),u=i.cache.read(n);return u?void e(u):void this.remote({url:o.url,data:$.extend(r,o.params,{keywordParamName:t,contain:o.searchContain,selected:a,original:o.originalValue,options:l}),success:function(a){var r=s.val();r.length>=t.length&&e(a),i.cache.write(n,a,o.cacheLifetime)}})},remote:function(e){var i=this;t.hasClass("flexdatalist-loading")||(t.addClass("flexdatalist-loading"),$.ajax($.extend({type:"post",dataType:"json",complete:function(){t.removeClass("flexdatalist-loading")}},e,{success:function(t){t=i.extractRemoteData(t),e.success(t)}})))},extractRemoteData:function(e){var t=i.isDefined(e,o.resultsProperty)?e[o.resultsProperty]:e;return"string"==typeof t&&0===t.indexOf("[{")&&(t=JSON.parse(t)),t&&t.options&&(o=$.extend({},o,t.options)),i.isObject(t)?t:[]},relativesData:function(){var e=o.relatives,t={};return e&&(t.relatives={},e.each(function(){var e=$(this),i=e.attr("name").split("][").join("-").split("]").join("-").split("[").join("-").replace(/^\|+|\-+$/g,"");t.relatives[i]=e.val()})),t}},this.search={get:function(e,a){var r=this;return o.searchDisabled?void i.debug("Search is disabled!"):("function"==typeof e&&(a=e,e=void 0),void i.data.load(function(l){var n=!1;i.isDefined(e)||(e=s.val());var o=i.cache.read(e);if(o)return void a(o);if(t.trigger("before:flexdatalist.search",[e,l]),!i.isEmpty(e)){n=[];for(var u=r.split(e),f=0;f<l.length;f++){var c=r.matches(l[f],u);c&&n.push(c)}}t.trigger("after:flexdatalist.search",[e,l,n]),a(n),i.cache.write(e,n,30)}))},matches:function(e,t){var a=$.extend({},e),r=[],l=o.searchIn;if(t.length>0)for(var s=0;s<l.length;s++){var n=l[s];if(i.isDefined(e,n)&&e[n]){for(var u=e[n].toString(),f=u,c=this.split(u),d=0;d<t.length;d++){var h=t[d];this.find(h,c)&&(r.push(h),f=this.highlight(h,f))}f!==u&&(a[n+"_highlight"]=this.highlight(f))}}return 0===r.length||o.searchByWord&&r.length<t.length-1?!1:a},highlight:function(e,t){return t?t.replace(new RegExp(e,o.searchContain?"ig":"i"),"|:|$&|::|"):(e=e.split("|:|").join('<span class="highlight">'),e.split("|::|").join("</span>"))},find:function(e,t){for(var i=0;i<t.length;i++){var a=t[i];if(a=this.normalizeString(a),e=this.normalizeString(e),o.searchEqual)return a==e;if(o.searchContain?a.indexOf(e)>=0:0===a.indexOf(e))return!0}return!1},split:function(e){if("string"==typeof e&&(e=[$.trim(e)]),o.searchByWord)for(var t=0;t<e.length;t++){var i=$.trim(e[t]);if(i.indexOf(" ")>0){var a=i.split(" ");$.merge(e,a)}}return e},normalizeString:function(e){if("string"==typeof e){var t=o.normalizeString;return"function"==typeof t&&(e=t(e)),e.toUpperCase()}return e}},this.results={show:function(e){var a=this;if(this.remove(!0),e){if(0===e.length)return void this.empty(o.noResultsText);var r=this.container();o.groupBy?(e=this.group(e),Object.keys(e).forEach(function(t){var l=e[t],s=o.groupBy,n=i.results.highlight(l[0],s,t);$("<li>").addClass("group").append($("<span>").addClass("group-name").html(n)).append($("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(r);a.items(l,r)})):this.items(e,r);var l=r.find("li:not(.group)");l.on("click",function(){var e=$(this).data("item");e&&(i.fvalue.extract(e),a.remove(),t.trigger("select:flexdatalist",[e,o]))}).hover(function(){l.removeClass("active"),$(this).addClass("active")},function(){$(this).removeClass("active")}),o.focusFirstResult&&l.filter(":first").addClass("active")}},empty:function(e){if(!i.isEmpty(e)){var t=this.container(),a=s.val();e=e.split("{keyword}").join(a),$("<li>").addClass("item no-results").append(e).appendTo(t)}},items:function(e,i){var a=o.maxShownResults;t.trigger("show:flexdatalist.results",[e]);for(var r=0;r<e.length&&!(a>0&&a===r);r++)this.item(e[r]).appendTo(i);t.trigger("shown:flexdatalist.results",[e])},item:function(e){for(var t=$("<li>").data("item",e).addClass("item"),a=o.visibleProperties,r=0;r<a.length;r++){var l=a[r];if((!o.groupBy||o.groupBy!==l)&&i.isDefined(e,l)){var s={};if(l===o.iconProperty)s=$("<img>").addClass("item item-"+l).attr("src",e[l]);else{var n=i.results.highlight(e,l);s=$("<span>").addClass("item item-"+l).html(n+" ")}s.appendTo(t)}}return t},container:function(){var e=t;o.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:s,input:t}),i.position(s)),a},group:function(e){for(var t=[],a=o.groupBy,r=0;r<e.length;r++){var l=e[r];if(i.isDefined(l,a)){var s=l[a];i.isDefined(t,s)||(t[s]=[]),t[s].push(l)}}return t},highlight:function(e,t,a){return i.isDefined(e,t+"_highlight")?e[t+"_highlight"]:i.isDefined(e,t)?e[t]:a},remove:function(e){var i="ul.flexdatalist-results";e&&(i="ul.flexdatalist-results li"),$(i).remove(),t.trigger("removed:flexdatalist.results")}},this.cache={write:function(e,t,a){if(i.cache.isSupported()){e=this.keyGen(e);var r={value:t,timestamp:i.unixtime(),lifetime:a?a:!1};localStorage.setItem(e,JSON.stringify(r))}},read:function(e){if(i.cache.isSupported()){e=this.keyGen(e);var t=localStorage.getItem(e);if(t){var a=JSON.parse(t);if(a.lifetime){var r=i.unixtime()-a.timestamp;return a.lifetime>r?a.value:(i.cache["delete"](e),null)}return a.value}}return null},"delete":function(e){i.cache.isSupported()&&(e=this.keyGen(e),localStorage.removeItem(e))},clear:function(){if(i.cache.isSupported()){for(var e in localStorage)e.indexOf(l)>-1&&i.cache["delete"](e);localStorage.clear()}},isSupported:function(){if(o.cache)try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}return!1},keyGen:function(e,t){"object"==typeof e&&(e=JSON.stringify(e));var i,a,r=void 0===t?2166136261:t;for(i=0,a=e.length;a>i;i++)r^=e.charCodeAt(i),r+=(r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24);return l+("0000000"+(r>>>0).toString(16)).substr(-8)}},this.position=function(){var e=$("input:focus:eq(0)");0===e.length&&(e=s),o.multiple&&(e=e.parents(".flexdatalist-multiple:eq(0)")),$("ul.flexdatalist-results").css({width:e.outerWidth()+"px",top:e.offset().top+e.outerHeight()+"px",left:e.offset().left+"px"})},this.keyNum=function(e){return e.which||e.keyCode},this.isEmpty=function(e){return i.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.length=function(e){return this.isObject(e)?Object.keys(e).length:"number"==typeof e||"number"==typeof e.length?e.toString().length:0},this.isDefined=function(e,t){var i="undefined"!=typeof e;return i&&"undefined"!=typeof t?"undefined"!=typeof e[t]:i},this.unixtime=function(e){var t=new Date;return e&&(t=new Date(e)),Math.round(t.getTime()/1e3)},this.csvToArray=function(e,t){return 0===e.length?t:"string"==typeof e?e.split(o.valuesSeparator):e},this.debug=function(e,i){o.debug&&(i||(i={}),e="Flexdatalist: "+e,console.warn(e),console.log($.extend({inputName:t.attr("name"),options:o},i)),console.log("--- /flexdatalist ---"))},o.searchIn=this.csvToArray(o.searchIn),o.relatives=o.relatives&&$(o.relatives).length>0?$(o.relatives):null,o.textProperty=null===o.textProperty?o.searchIn[0]:o.textProperty,o.visibleProperties=this.csvToArray(o.visibleProperties,o.searchIn),t.data("flexdatalist",o),this.init()})},jQuery(function(e){var t=e(document);t.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"),r=a.filter(".active"),l=r.index(),s=a.length,n=t.which||t.keyCode;if(0!==s){if(27===n)return void i.remove();if(13===n)t.preventDefault(),r.click();else if(40===n||38===n){t.preventDefault(),40===n?r=s>l&&r.nextAll(".item").first().length>0?r.removeClass("active").nextAll(".item").first().addClass("active"):a.removeClass("active").filter(".item:first").addClass("active"):38===n&&(r=l>0&&r.prevAll(".item").first().length>0?r.removeClass("active").prevAll(".item").first().addClass("active"):a.removeClass("active").filter(".item:last").addClass("active"));var o=(0===r.prev().length?r:r.prev()).position().top;i.animate({scrollTop:o+i.scrollTop()},100)}}}).data("flexdatalist",!0),jQuery("input.flexdatalist:not(.flexdatalist-set)").flexdatalist()}),function(e){var t=e.fn.val;e.fn.val=function(i){var a=e(this).hasClass("flexdatalist");return"undefined"==typeof i?a?this[0].fvalue.get(!0):t.call(this):a?this[0].fvalue.set(i):t.call(this,i)}}(jQuery);
\ No newline at end of file

minor changes