<NME> jquery.flexdatalist.min.js
<BEF> !function(e){e.fn.flexdatalist=function(){var t=e(document),a=this;return t.data("flexdatalist")||e(document).mouseup(function(t){var a=e(".flexdatalist-results");a.is(t.target)||0!==a.has(t.target).length||a.remove()}).keydown(function(t){var r=e(".flexdatalist-results"),i=r.find("li"),n=i.filter(".active"),l=n.index(),s=i.length,o=t.keyCode||t.which;0!==s&&(13===o?(t.preventDefault(),n.click()):(40===o||38===o)&&(t.preventDefault(),40===o?n=s>l&&n.nextAll(".item").first().length>0?n.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===o&&(n=l>0&&n.prevAll(".item").first().length>0?n.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active")),a._scrollTo(r,n)))}).data("flexdatalist",!0),this._scrollTo=function(e,t){var a=(0===t.prev().length?t:t.prev()).position().top;e.animate({scrollTop:a+e.scrollTop()},100)},this.each(function(){var t=e(this),a={},r=t.attr("name");if(!t.hasClass("flexdatalist-set")){var i=e.extend({url:null,data:[],file:null,cache:!0,searchContain:!1,minLength:2,mergeRemoteData:!1,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"]},i,t.data());if(i.searchIn="string"==typeof i.searchIn?i.searchIn.split(","):i.searchIn,i.visibleProperties=0===i.visibleProperties.length?i.searchIn:i.visibleProperties,i.multiple=t.attr("multiple"),i.multiple){var n=e("<ul>").addClass("flexdatalist-multiple").css({"background-color":t.css("background-color"),"border-color":t.css("border-left-color"),"border-width":t.css("border-left-width"),"border-style":t.css("border-left-style"),"border-radius":t.css("border-top-left-radius")}).insertAfter(t);$_this=t.clone(!0).attr("name",null),t.remove(),t=$_this;e('<li class="input-container">').addClass("flexdatalist-multiple-value").append(t).appendTo(n)}t.init=function(){t.datalist(),t.on("input keyup",function(e){var a=t.keyword();t._ignoreKey(e)||(a.length>=i.minLength?t.search():t.removeResults(),i.multiple||(i.selectionRequired?t.hiddenInput().length>0&&!t.selected()&&t.value(""):t.value(a)))}).on("input keydown",function(e){188===t._keyNum(e)&&!i.selectionRequired&&i.multiple&&(e.preventDefault(),t.value(t.keyword()))}).blur(function(){i.selectionRequired&&!t.selected()&&t.value("")}).attr("autocomplete","off").addClass("flexdatalist-set").trigger("init:flexdatalist",[i]),window.onresize=function(){t.position()}},t._setValue=function(){var a=t.attr("value");if(""!==a)if("*"===i.valueProperty||"object"==typeof i.valueProperty){var a=t._parseValue(a);"object"==typeof a&&Object.keys(a).length>0?i.multiple?e.each(a,function(e,a){t.value(a)}):t.value(a):t.val("")}else t.value(a)},t._parseValue=function(e){if("string"==typeof e)try{return JSON.parse(e)}catch(t){return e}return e},t._keyNum=function(e){return e.which||e.keyCode},t._ignoreKey=function(e){var a=t._keyNum(e);return 0===a||13===a||38===a||40===a},t.search=function(){t._data(function(a){var r=[],n=t.keyword();i.mergeRemoteData&&(a=e["extends"](i.data,a));for(var l=i.groupBy,s=0;s<a.length;s++){var o=t.matches(a[s],n);if(o)if(l){if("undefined"!=typeof o[l]){var u=o[l];"undefined"==typeof r[u]&&(r[u]=[]),r[u].push(o)}}else r.push(o)}t.results(r)})},t.matches=function(e,a){for(var r=!1,n=0;n<i.searchIn.length;n++){var l=i.searchIn[n];if("undefined"!=typeof e[l]){var s=e[l];t.find(s,a)&&(e[l+"_highlight"]=t.highlight(s,a),r=!0)}}return r?e:null},t.highlight=function(e,t){return e.replace(new RegExp(t,i.searchContain?"ig":"i"),'<span class="highlight">$&</span>')},t.find=function(e,a){return e=t.normalizeString(e),a=t.normalizeString(a),i.searchContain?e.indexOf(a)>=0:0===e.indexOf(a)},t._data=function(a){if(i.data.length>0)return void a(i.data);if(i.url||i.file){var r=t.keyword(),n=i.url?i.url:i.file,l=r.substring(0,i.minLength),s=t.cache(l);return s?void a(s):void(t.hasClass("flexdatalist-loading")||(t.addClass("flexdatalist-loading"),e.ajax({url:n,data:{keyword:l,contain:i.searchContain},type:"post",dataType:"json",success:function(e){t.removeClass("flexdatalist-loading");var r=e.results?e.results:e;"string"==typeof r&&0===r.indexOf("[{")&&(r=JSON.parse(r)),"object"==typeof r&&(a(r),i.url?t.cache(l,r):i.file&&(i.data=e))}})))}},t.datalist=function(){var a=t.attr("list");return a&&(t.attr("list",null),e("#"+a).find("option").each(function(){var t=e(this).val();i.data.push({label:t,value:t})})),t},t.cache=function(e,r){if(i.cache){if(e=t.normalizeString(e),"undefined"==typeof r)return"undefined"!=typeof a[e]&&(r=a[e]),r;a[e]=r}return null},t.results=function(a){if(t.removeResults(),0!==a.length||0!==Object.keys(a).length){var r=t.getContainer();t.selected()&&t.selected(!1).value(""),i.groupBy?Object.keys(a).forEach(function(n){var l=a[n],s=i.groupBy,o=t.getHighlight(l[0],s,n);e("<li>").addClass("group").append(e("<span>").addClass("group-name").html(o)).append(e("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(r);t.items(l,r)}):t.items(a,r);var n=r.find("li:not(.group)");n.on("click",function(){var a=e(this).data("item");a&&(t.selected(!0).removeResults().value(a),t.trigger("select:flexdatalist",[a,i]))}).hover(function(){n.removeClass("active"),e(this).addClass("active")},function(){e(this).removeClass("active")}),i.focusFirstResult&&n.filter(":first").addClass("active"),t.position()}},t.getContainer=function(){var a=t;i.multiple&&(a=n);var r=e("ul.flexdatalist-results");return 0===r.length&&(r=e("<ul>").addClass("flexdatalist-results").appendTo("body").css({"border-color":a.css("border-left-color"),"border-width":"1px","border-bottom-left-radius":a.css("border-bottom-left-radius"),"border-bottom-right-radius":a.css("border-bottom-right-radius")})),r},t.removeResults=function(){return e("ul.flexdatalist-results").remove(),t},t.items=function(e,a){for(var r=0;r<e.length;r++)t.item(e[r]).appendTo(a)},t.item=function(a){for(var r=e("<li>").data("item",a).addClass("item"),n=0;n<i.visibleProperties.length;n++){var l=i.visibleProperties[n];if(!(i.groupBy&&i.groupBy===l||"undefined"==typeof a[l])){var s={};if("thumb"===l)s=e("<img>").addClass("item-"+l).attr("src",a[l]);else{var o=t.getHighlight(a,l);s=e("<span>").addClass("item-"+l).html(o+" ")}s.appendTo(r)}}return r},t.hiddenInput=function(){var a=t.parents("form:eq(0)"),i=a.find('input[type="hidden"][name="'+r+'"]');return i.length>0?i:(t.attr("name",null),e('<input type="hidden">').attr({name:r}).insertAfter(t))},t.selected=function(e){var a="flexdatalist-selected";return"undefined"==typeof e?t.hasClass(a):(e?t.addClass(a):t.removeClass(a),t)},t.value=function(a){if("undefined"==typeof a)return t.data("value");var l=t._text(a),s=t._value(a);if(i.multiple){if(""===a)return t;t.val("");var o=e("<li>").addClass("value").append('<span class="text">'+l+"</span>").append('<span class="remove">&times;</span>').insertBefore(n.find("li.input-container")),u="object"==typeof i.valueProperty||"*"===i.valueProperty;if(u)s=t._inputValue(s);else{var d=e('<input type="hidden">').attr({name:r+"[]"}).appendTo(o);s=t._inputValue(s,d)}o.find("span.remove").click(function(){var a=e(this).parent();if(u){var r=t._inputValue();r=r.splice(a.index()+1,1),r=JSON.stringify(r),t._inputValue(r)}a.remove()})}else l=l.trim(),l.length>0&&t.val(l),s=t._inputValue(s);return t.trigger("change:flexdatalist",[s,l,i]),t},t._text=function(e){var a=e;return"object"==typeof e&&(a=e[i.searchIn[0]],a="undefined"!=typeof e[i.textProperty]?e[i.textProperty]:t._replacePlaceholders(e,i.textProperty,a)),a},t._value=function(a){var r=a;if("object"==typeof a){if(r=a[i.searchIn[0]],"*"===i.valueProperty)r=a;else if("undefined"!=typeof a[i.valueProperty])r=a[i.valueProperty];else if(i.valueProperty&&"object"==typeof i.valueProperty){var r={},n=i.valueProperty,l=i.textProperty;if(l){var s=l;"string"==typeof l&&(s=t._parsePlaceholders(l)),s&&"object"==typeof s&&e.each(s,function(e,t){n.push(t)})}else"undefined"!=typeof a[l]&&n.push(l);e.each(n,function(e,t){"undefined"!=typeof a[t]&&(r[t]=a[t])})}else r=t._replacePlaceholders(a,i.valueProperty,r);if("object"==typeof r&&i.multiple){var o=t._inputValue();o.push(r),r=o}}return r},t._inputValue=function(e,a){var r="object"==typeof i.valueProperty||"*"===i.valueProperty;return"undefined"==typeof e?(e=t.data("value"),r&&(e?JSON.parse(t.data("value")):[]),t.data("value")?JSON.parse(t.data("value")):[]):("object"==typeof e&&(e=JSON.stringify(e)),a||(a=t.hiddenInput()),a.val(e),t.data("value",e),e)},t._replacePlaceholders=function(a,r,i){if("object"==typeof a&&"string"==typeof r){var n=t._parsePlaceholders(r);if(n)return e.each(n,function(e,t){"undefined"!=typeof a[t]&&(r=r.replace(e,a[t]))}),r}return i},t._parsePlaceholders=function(e){var t=e.match(/\{.+?\}/g);if(t){var a={};return t.map(function(e){a[e]=e.slice(1,-1)}),a}return!1},t.normalizeString=function(e){return e.toUpperCase()},t.keyword=function(){return this.val().replace(/^\s+/,"")},t.getHighlight=function(e,t,a){return"undefined"!=typeof e[t+"_highlight"]?e[t+"_highlight"]:"undefined"!==e[t]?e[t]:a},t.position=function(){var a=t;i.multiple&&(a=n),e("ul.flexdatalist-results").css({width:a.outerWidth()+"px",top:a.offset().top+a.outerHeight()+"px",left:a.offset().left+"px","z-index":a.css("z-index")+1})},t.init(),t._setValue()}})},e(".flexdatalist").flexdatalist()}(jQuery);

<MSG> Merge branch 'master' of https://github.com/sergiodlopes/jquery-flexdatalist

Conflicts:
	README.md
	jquery.flexdatalist.css
	jquery.flexdatalist.js
	jquery.flexdatalist.min.js

<DFF> @@ -1,1 +1,5 @@
-!function(e){e.fn.flexdatalist=function(){var t=e(document),a=this;return t.data("flexdatalist")||e(document).mouseup(function(t){var a=e(".flexdatalist-results");a.is(t.target)||0!==a.has(t.target).length||a.remove()}).keydown(function(t){var r=e(".flexdatalist-results"),i=r.find("li"),n=i.filter(".active"),l=n.index(),s=i.length,o=t.keyCode||t.which;0!==s&&(13===o?(t.preventDefault(),n.click()):(40===o||38===o)&&(t.preventDefault(),40===o?n=s>l&&n.nextAll(".item").first().length>0?n.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===o&&(n=l>0&&n.prevAll(".item").first().length>0?n.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active")),a._scrollTo(r,n)))}).data("flexdatalist",!0),this._scrollTo=function(e,t){var a=(0===t.prev().length?t:t.prev()).position().top;e.animate({scrollTop:a+e.scrollTop()},100)},this.each(function(){var t=e(this),a={},r=t.attr("name");if(!t.hasClass("flexdatalist-set")){var i=e.extend({url:null,data:[],file:null,cache:!0,searchContain:!1,minLength:2,mergeRemoteData:!1,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"]},i,t.data());if(i.searchIn="string"==typeof i.searchIn?i.searchIn.split(","):i.searchIn,i.visibleProperties=0===i.visibleProperties.length?i.searchIn:i.visibleProperties,i.multiple=t.attr("multiple"),i.multiple){var n=e("<ul>").addClass("flexdatalist-multiple").css({"background-color":t.css("background-color"),"border-color":t.css("border-left-color"),"border-width":t.css("border-left-width"),"border-style":t.css("border-left-style"),"border-radius":t.css("border-top-left-radius")}).insertAfter(t);$_this=t.clone(!0).attr("name",null),t.remove(),t=$_this;e('<li class="input-container">').addClass("flexdatalist-multiple-value").append(t).appendTo(n)}t.init=function(){t.datalist(),t.on("input keyup",function(e){var a=t.keyword();t._ignoreKey(e)||(a.length>=i.minLength?t.search():t.removeResults(),i.multiple||(i.selectionRequired?t.hiddenInput().length>0&&!t.selected()&&t.value(""):t.value(a)))}).on("input keydown",function(e){188===t._keyNum(e)&&!i.selectionRequired&&i.multiple&&(e.preventDefault(),t.value(t.keyword()))}).blur(function(){i.selectionRequired&&!t.selected()&&t.value("")}).attr("autocomplete","off").addClass("flexdatalist-set").trigger("init:flexdatalist",[i]),window.onresize=function(){t.position()}},t._setValue=function(){var a=t.attr("value");if(""!==a)if("*"===i.valueProperty||"object"==typeof i.valueProperty){var a=t._parseValue(a);"object"==typeof a&&Object.keys(a).length>0?i.multiple?e.each(a,function(e,a){t.value(a)}):t.value(a):t.val("")}else t.value(a)},t._parseValue=function(e){if("string"==typeof e)try{return JSON.parse(e)}catch(t){return e}return e},t._keyNum=function(e){return e.which||e.keyCode},t._ignoreKey=function(e){var a=t._keyNum(e);return 0===a||13===a||38===a||40===a},t.search=function(){t._data(function(a){var r=[],n=t.keyword();i.mergeRemoteData&&(a=e["extends"](i.data,a));for(var l=i.groupBy,s=0;s<a.length;s++){var o=t.matches(a[s],n);if(o)if(l){if("undefined"!=typeof o[l]){var u=o[l];"undefined"==typeof r[u]&&(r[u]=[]),r[u].push(o)}}else r.push(o)}t.results(r)})},t.matches=function(e,a){for(var r=!1,n=0;n<i.searchIn.length;n++){var l=i.searchIn[n];if("undefined"!=typeof e[l]){var s=e[l];t.find(s,a)&&(e[l+"_highlight"]=t.highlight(s,a),r=!0)}}return r?e:null},t.highlight=function(e,t){return e.replace(new RegExp(t,i.searchContain?"ig":"i"),'<span class="highlight">$&</span>')},t.find=function(e,a){return e=t.normalizeString(e),a=t.normalizeString(a),i.searchContain?e.indexOf(a)>=0:0===e.indexOf(a)},t._data=function(a){if(i.data.length>0)return void a(i.data);if(i.url||i.file){var r=t.keyword(),n=i.url?i.url:i.file,l=r.substring(0,i.minLength),s=t.cache(l);return s?void a(s):void(t.hasClass("flexdatalist-loading")||(t.addClass("flexdatalist-loading"),e.ajax({url:n,data:{keyword:l,contain:i.searchContain},type:"post",dataType:"json",success:function(e){t.removeClass("flexdatalist-loading");var r=e.results?e.results:e;"string"==typeof r&&0===r.indexOf("[{")&&(r=JSON.parse(r)),"object"==typeof r&&(a(r),i.url?t.cache(l,r):i.file&&(i.data=e))}})))}},t.datalist=function(){var a=t.attr("list");return a&&(t.attr("list",null),e("#"+a).find("option").each(function(){var t=e(this).val();i.data.push({label:t,value:t})})),t},t.cache=function(e,r){if(i.cache){if(e=t.normalizeString(e),"undefined"==typeof r)return"undefined"!=typeof a[e]&&(r=a[e]),r;a[e]=r}return null},t.results=function(a){if(t.removeResults(),0!==a.length||0!==Object.keys(a).length){var r=t.getContainer();t.selected()&&t.selected(!1).value(""),i.groupBy?Object.keys(a).forEach(function(n){var l=a[n],s=i.groupBy,o=t.getHighlight(l[0],s,n);e("<li>").addClass("group").append(e("<span>").addClass("group-name").html(o)).append(e("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(r);t.items(l,r)}):t.items(a,r);var n=r.find("li:not(.group)");n.on("click",function(){var a=e(this).data("item");a&&(t.selected(!0).removeResults().value(a),t.trigger("select:flexdatalist",[a,i]))}).hover(function(){n.removeClass("active"),e(this).addClass("active")},function(){e(this).removeClass("active")}),i.focusFirstResult&&n.filter(":first").addClass("active"),t.position()}},t.getContainer=function(){var a=t;i.multiple&&(a=n);var r=e("ul.flexdatalist-results");return 0===r.length&&(r=e("<ul>").addClass("flexdatalist-results").appendTo("body").css({"border-color":a.css("border-left-color"),"border-width":"1px","border-bottom-left-radius":a.css("border-bottom-left-radius"),"border-bottom-right-radius":a.css("border-bottom-right-radius")})),r},t.removeResults=function(){return e("ul.flexdatalist-results").remove(),t},t.items=function(e,a){for(var r=0;r<e.length;r++)t.item(e[r]).appendTo(a)},t.item=function(a){for(var r=e("<li>").data("item",a).addClass("item"),n=0;n<i.visibleProperties.length;n++){var l=i.visibleProperties[n];if(!(i.groupBy&&i.groupBy===l||"undefined"==typeof a[l])){var s={};if("thumb"===l)s=e("<img>").addClass("item-"+l).attr("src",a[l]);else{var o=t.getHighlight(a,l);s=e("<span>").addClass("item-"+l).html(o+" ")}s.appendTo(r)}}return r},t.hiddenInput=function(){var a=t.parents("form:eq(0)"),i=a.find('input[type="hidden"][name="'+r+'"]');return i.length>0?i:(t.attr("name",null),e('<input type="hidden">').attr({name:r}).insertAfter(t))},t.selected=function(e){var a="flexdatalist-selected";return"undefined"==typeof e?t.hasClass(a):(e?t.addClass(a):t.removeClass(a),t)},t.value=function(a){if("undefined"==typeof a)return t.data("value");var l=t._text(a),s=t._value(a);if(i.multiple){if(""===a)return t;t.val("");var o=e("<li>").addClass("value").append('<span class="text">'+l+"</span>").append('<span class="remove">&times;</span>').insertBefore(n.find("li.input-container")),u="object"==typeof i.valueProperty||"*"===i.valueProperty;if(u)s=t._inputValue(s);else{var d=e('<input type="hidden">').attr({name:r+"[]"}).appendTo(o);s=t._inputValue(s,d)}o.find("span.remove").click(function(){var a=e(this).parent();if(u){var r=t._inputValue();r=r.splice(a.index()+1,1),r=JSON.stringify(r),t._inputValue(r)}a.remove()})}else l=l.trim(),l.length>0&&t.val(l),s=t._inputValue(s);return t.trigger("change:flexdatalist",[s,l,i]),t},t._text=function(e){var a=e;return"object"==typeof e&&(a=e[i.searchIn[0]],a="undefined"!=typeof e[i.textProperty]?e[i.textProperty]:t._replacePlaceholders(e,i.textProperty,a)),a},t._value=function(a){var r=a;if("object"==typeof a){if(r=a[i.searchIn[0]],"*"===i.valueProperty)r=a;else if("undefined"!=typeof a[i.valueProperty])r=a[i.valueProperty];else if(i.valueProperty&&"object"==typeof i.valueProperty){var r={},n=i.valueProperty,l=i.textProperty;if(l){var s=l;"string"==typeof l&&(s=t._parsePlaceholders(l)),s&&"object"==typeof s&&e.each(s,function(e,t){n.push(t)})}else"undefined"!=typeof a[l]&&n.push(l);e.each(n,function(e,t){"undefined"!=typeof a[t]&&(r[t]=a[t])})}else r=t._replacePlaceholders(a,i.valueProperty,r);if("object"==typeof r&&i.multiple){var o=t._inputValue();o.push(r),r=o}}return r},t._inputValue=function(e,a){var r="object"==typeof i.valueProperty||"*"===i.valueProperty;return"undefined"==typeof e?(e=t.data("value"),r&&(e?JSON.parse(t.data("value")):[]),t.data("value")?JSON.parse(t.data("value")):[]):("object"==typeof e&&(e=JSON.stringify(e)),a||(a=t.hiddenInput()),a.val(e),t.data("value",e),e)},t._replacePlaceholders=function(a,r,i){if("object"==typeof a&&"string"==typeof r){var n=t._parsePlaceholders(r);if(n)return e.each(n,function(e,t){"undefined"!=typeof a[t]&&(r=r.replace(e,a[t]))}),r}return i},t._parsePlaceholders=function(e){var t=e.match(/\{.+?\}/g);if(t){var a={};return t.map(function(e){a[e]=e.slice(1,-1)}),a}return!1},t.normalizeString=function(e){return e.toUpperCase()},t.keyword=function(){return this.val().replace(/^\s+/,"")},t.getHighlight=function(e,t,a){return"undefined"!=typeof e[t+"_highlight"]?e[t+"_highlight"]:"undefined"!==e[t]?e[t]:a},t.position=function(){var a=t;i.multiple&&(a=n),e("ul.flexdatalist-results").css({width:a.outerWidth()+"px",top:a.offset().top+a.outerHeight()+"px",left:a.offset().left+"px","z-index":a.css("z-index")+1})},t.init(),t._setValue()}})},e(".flexdatalist").flexdatalist()}(jQuery);
\ No newline at end of file
+<<<<<<< HEAD
+!function(e){e.fn.flexdatalist=function(){var t=e(document),a=this;return t.data("flexdatalist")||e(document).mouseup(function(t){var a=e(".flexdatalist-results");a.is(t.target)||0!==a.has(t.target).length||a.remove()}).keydown(function(t){var r=e(".flexdatalist-results"),i=r.find("li"),n=i.filter(".active"),l=n.index(),s=i.length,o=t.keyCode||t.which;0!==s&&(13===o?(t.preventDefault(),n.click()):(40===o||38===o)&&(t.preventDefault(),40===o?n=s>l&&n.nextAll(".item").first().length>0?n.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===o&&(n=l>0&&n.prevAll(".item").first().length>0?n.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active")),a._scrollTo(r,n)))}).data("flexdatalist",!0),this._scrollTo=function(e,t){var a=(0===t.prev().length?t:t.prev()).position().top;e.animate({scrollTop:a+e.scrollTop()},100)},this.each(function(){var t=e(this),a={},r=t.attr("name");if(!t.hasClass("flexdatalist-set")){var i=e.extend({url:null,data:[],file:null,cache:!0,searchContain:!1,minLength:2,mergeRemoteData:!1,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"]},i,t.data());if(i.searchIn="string"==typeof i.searchIn?i.searchIn.split(","):i.searchIn,i.visibleProperties=0===i.visibleProperties.length?i.searchIn:i.visibleProperties,i.multiple=t.attr("multiple"),i.multiple){var n=e("<ul>").addClass("flexdatalist-multiple").css({"background-color":t.css("background-color"),"border-color":t.css("border-left-color"),"border-width":t.css("border-left-width"),"border-style":t.css("border-left-style"),"border-radius":t.css("border-top-left-radius")}).insertAfter(t);$_this=t.clone(!0).attr("name",null),t.remove(),t=$_this;e('<li class="input-container">').addClass("flexdatalist-multiple-value").append(t).appendTo(n)}t.init=function(){t.datalist(),t.on("input keyup",function(e){var a=t.keyword();t._ignoreKey(e)||(a.length>=i.minLength?t.search():t.removeResults(),i.multiple||(i.selectionRequired?t.hiddenInput().length>0&&!t.selected()&&t.value(""):t.value(a)))}).on("input keydown",function(e){188===t._keyNum(e)&&!i.selectionRequired&&i.multiple&&(e.preventDefault(),t.value(t.keyword()))}).blur(function(){i.selectionRequired&&!t.selected()&&t.value("")}).attr("autocomplete","off").addClass("flexdatalist-set").trigger("init:flexdatalist",[i]),window.onresize=function(){t.position()}},t._setValue=function(){var a=t.attr("value");if(""!==a)if("*"===i.valueProperty||"object"==typeof i.valueProperty){var a=t._parseValue(a);"object"==typeof a&&Object.keys(a).length>0?i.multiple?e.each(a,function(e,a){t.value(a)}):t.value(a):t.val("")}else t.value(a)},t._parseValue=function(e){if("string"==typeof e)try{return JSON.parse(e)}catch(t){return e}return e},t._keyNum=function(e){return e.which||e.keyCode},t._ignoreKey=function(e){var a=t._keyNum(e);return 0===a||13===a||38===a||40===a},t.search=function(){t._data(function(a){var r=[],n=t.keyword();i.mergeRemoteData&&(a=e["extends"](i.data,a));for(var l=i.groupBy,s=0;s<a.length;s++){var o=t.matches(a[s],n);if(o)if(l){if("undefined"!=typeof o[l]){var u=o[l];"undefined"==typeof r[u]&&(r[u]=[]),r[u].push(o)}}else r.push(o)}t.results(r)})},t.matches=function(e,a){for(var r=!1,n=0;n<i.searchIn.length;n++){var l=i.searchIn[n];if("undefined"!=typeof e[l]){var s=e[l];t.find(s,a)&&(e[l+"_highlight"]=t.highlight(s,a),r=!0)}}return r?e:null},t.highlight=function(e,t){return e.replace(new RegExp(t,i.searchContain?"ig":"i"),'<span class="highlight">$&</span>')},t.find=function(e,a){return e=t.normalizeString(e),a=t.normalizeString(a),i.searchContain?e.indexOf(a)>=0:0===e.indexOf(a)},t._data=function(a){if(i.data.length>0)return void a(i.data);if(i.url||i.file){var r=t.keyword(),n=i.url?i.url:i.file,l=r.substring(0,i.minLength),s=t.cache(l);return s?void a(s):void(t.hasClass("flexdatalist-loading")||(t.addClass("flexdatalist-loading"),e.ajax({url:n,data:{keyword:l,contain:i.searchContain},type:"post",dataType:"json",success:function(e){t.removeClass("flexdatalist-loading");var r=e.results?e.results:e;"string"==typeof r&&0===r.indexOf("[{")&&(r=JSON.parse(r)),"object"==typeof r&&(a(r),i.url?t.cache(l,r):i.file&&(i.data=e))}})))}},t.datalist=function(){var a=t.attr("list");return a&&(t.attr("list",null),e("#"+a).find("option").each(function(){var t=e(this).val();i.data.push({label:t,value:t})})),t},t.cache=function(e,r){if(i.cache){if(e=t.normalizeString(e),"undefined"==typeof r)return"undefined"!=typeof a[e]&&(r=a[e]),r;a[e]=r}return null},t.results=function(a){if(t.removeResults(),0!==a.length||0!==Object.keys(a).length){var r=t.getContainer();t.selected()&&t.selected(!1).value(""),i.groupBy?Object.keys(a).forEach(function(n){var l=a[n],s=i.groupBy,o=t.getHighlight(l[0],s,n);e("<li>").addClass("group").append(e("<span>").addClass("group-name").html(o)).append(e("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(r);t.items(l,r)}):t.items(a,r);var n=r.find("li:not(.group)");n.on("click",function(){var a=e(this).data("item");a&&(t.selected(!0).removeResults().value(a),t.trigger("select:flexdatalist",[a,i]))}).hover(function(){n.removeClass("active"),e(this).addClass("active")},function(){e(this).removeClass("active")}),i.focusFirstResult&&n.filter(":first").addClass("active"),t.position()}},t.getContainer=function(){var a=t;i.multiple&&(a=n);var r=e("ul.flexdatalist-results");return 0===r.length&&(r=e("<ul>").addClass("flexdatalist-results").appendTo("body").css({"border-color":a.css("border-left-color"),"border-width":"1px","border-bottom-left-radius":a.css("border-bottom-left-radius"),"border-bottom-right-radius":a.css("border-bottom-right-radius")})),r},t.removeResults=function(){return e("ul.flexdatalist-results").remove(),t},t.items=function(e,a){for(var r=0;r<e.length;r++)t.item(e[r]).appendTo(a)},t.item=function(a){for(var r=e("<li>").data("item",a).addClass("item"),n=0;n<i.visibleProperties.length;n++){var l=i.visibleProperties[n];if(!(i.groupBy&&i.groupBy===l||"undefined"==typeof a[l])){var s={};if("thumb"===l)s=e("<img>").addClass("item-"+l).attr("src",a[l]);else{var o=t.getHighlight(a,l);s=e("<span>").addClass("item-"+l).html(o+" ")}s.appendTo(r)}}return r},t.hiddenInput=function(){var a=t.parents("form:eq(0)"),i=a.find('input[type="hidden"][name="'+r+'"]');return i.length>0?i:(t.attr("name",null),e('<input type="hidden">').attr({name:r}).insertAfter(t))},t.selected=function(e){var a="flexdatalist-selected";return"undefined"==typeof e?t.hasClass(a):(e?t.addClass(a):t.removeClass(a),t)},t.value=function(a){if("undefined"==typeof a)return t.data("value");var l=t._text(a),s=t._value(a);if(i.multiple){if(""===a)return t;t.val("");var o=e("<li>").addClass("value").append('<span class="text">'+l+"</span>").append('<span class="remove">&times;</span>').insertBefore(n.find("li.input-container")),u="object"==typeof i.valueProperty||"*"===i.valueProperty;if(u)s=t._inputValue(s);else{var d=e('<input type="hidden">').attr({name:r+"[]"}).appendTo(o);s=t._inputValue(s,d)}o.find("span.remove").click(function(){var a=e(this).parent();if(u){var r=t._inputValue();r=r.splice(a.index()+1,1),r=JSON.stringify(r),t._inputValue(r)}a.remove()})}else l=l.trim(),l.length>0&&t.val(l),s=t._inputValue(s);return t.trigger("change:flexdatalist",[s,l,i]),t},t._text=function(e){var a=e;return"object"==typeof e&&(a=e[i.searchIn[0]],a="undefined"!=typeof e[i.textProperty]?e[i.textProperty]:t._replacePlaceholders(e,i.textProperty,a)),a},t._value=function(a){var r=a;if("object"==typeof a){if(r=a[i.searchIn[0]],"*"===i.valueProperty)r=a;else if("undefined"!=typeof a[i.valueProperty])r=a[i.valueProperty];else if(i.valueProperty&&"object"==typeof i.valueProperty){var r={},n=i.valueProperty,l=i.textProperty;if(l){var s=l;"string"==typeof l&&(s=t._parsePlaceholders(l)),s&&"object"==typeof s&&e.each(s,function(e,t){n.push(t)})}else"undefined"!=typeof a[l]&&n.push(l);e.each(n,function(e,t){"undefined"!=typeof a[t]&&(r[t]=a[t])})}else r=t._replacePlaceholders(a,i.valueProperty,r);if("object"==typeof r&&i.multiple){var o=t._inputValue();o.push(r),r=o}}return r},t._inputValue=function(e,a){var r="object"==typeof i.valueProperty||"*"===i.valueProperty;return"undefined"==typeof e?(e=t.data("value"),r&&(e?JSON.parse(t.data("value")):[]),t.data("value")?JSON.parse(t.data("value")):[]):("object"==typeof e&&(e=JSON.stringify(e)),a||(a=t.hiddenInput()),a.val(e),t.data("value",e),e)},t._replacePlaceholders=function(a,r,i){if("object"==typeof a&&"string"==typeof r){var n=t._parsePlaceholders(r);if(n)return e.each(n,function(e,t){"undefined"!=typeof a[t]&&(r=r.replace(e,a[t]))}),r}return i},t._parsePlaceholders=function(e){var t=e.match(/\{.+?\}/g);if(t){var a={};return t.map(function(e){a[e]=e.slice(1,-1)}),a}return!1},t.normalizeString=function(e){return e.toUpperCase()},t.keyword=function(){return this.val().replace(/^\s+/,"")},t.getHighlight=function(e,t,a){return"undefined"!=typeof e[t+"_highlight"]?e[t+"_highlight"]:"undefined"!==e[t]?e[t]:a},t.position=function(){var a=t;i.multiple&&(a=n),e("ul.flexdatalist-results").css({width:a.outerWidth()+"px",top:a.offset().top+a.outerHeight()+"px",left:a.offset().left+"px","z-index":a.css("z-index")+1})},t.init(),t._setValue()}})},e(".flexdatalist").flexdatalist()}(jQuery);
+=======
+!function(e){e.fn.flexdatalist=function(){var t=e(document),a=this;return t.data("flexdatalist")||e(document).mouseup(function(t){var a=e(".flexdatalist-results");a.is(t.target)||0!==a.has(t.target).length||a.remove()}).keydown(function(t){var r=e(".flexdatalist-results"),i=r.find("li"),n=i.filter(".active"),l=n.index(),s=i.length,o=t.keyCode||t.which;0!==s&&(13===o?(t.preventDefault(),n.click()):(40===o||38===o)&&(t.preventDefault(),40===o?n=s>l&&n.nextAll(".item").first().length>0?n.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===o&&(n=l>0&&n.prevAll(".item").first().length>0?n.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active")),a._scrollTo(r,n)))}).data("flexdatalist",!0),this._scrollTo=function(e,t){var a=(0===t.prev().length?t:t.prev()).position().top;e.animate({scrollTop:a+e.scrollTop()},100)},this.each(function(){var t=e(this),a={},r=t.attr("name");if(!t.hasClass("flexdatalist-set")){var i=e.extend({url:null,data:[],file:null,cache:!0,searchContain:!1,minLength:2,mergeRemoteData:!1,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"]},i,t.data());if(i.searchIn="string"==typeof i.searchIn?i.searchIn.split(","):i.searchIn,i.visibleProperties=0===i.visibleProperties.length?i.searchIn:i.visibleProperties,i.multiple=t.attr("multiple"),i.multiple){r+="[]";var n=e("<ul>").addClass("flexdatalist-multiple").css({"background-color":t.css("background-color"),"border-color":t.css("border-left-color"),"border-width":t.css("border-left-width"),"border-style":t.css("border-left-style"),"border-radius":t.css("border-top-left-radius")}).insertAfter(t);$_this=t.clone(!0).attr("name",null),t.remove(),t=$_this;e('<li class="input-container">').addClass("flexdatalist-multiple-value").append(t).appendTo(n)}t.init=function(){t.datalist(),t.on("input keyup",function(e){var a=t.keyword();t._ignoreKey(e)||(a.length>=i.minLength?t.search():t.removeResults(),i.multiple||(i.selectionRequired?t.hiddenInput().length>0&&!t.selected()&&t.value(""):t.value(a)))}).on("input keydown",function(e){188===t._keyNum(e)&&!i.selectionRequired&&i.multiple&&(e.preventDefault(),t.value(t.keyword()))}).blur(function(){i.selectionRequired&&!t.selected()&&t.value("")}).attr("autocomplete","off").addClass("flexdatalist-set").trigger("init:flexdatalist",[i]),window.onresize=function(){t.position()}},t._setValue=function(){var e=t.keyword();if(""!==e){var e=t._parseValue(e);"object"==typeof e||t.value(e)}},t._parseValue=function(e){if("string"==typeof e)try{return JSON.parse(e)}catch(t){return e}return e},t._keyNum=function(e){return e.which||e.keyCode},t._ignoreKey=function(e){var a=t._keyNum(e);return 0===a||13===a||38===a||40===a},t.search=function(){t._data(function(a){var r=[],n=t.keyword();i.mergeRemoteData&&(a=e["extends"](i.data,a));for(var l=i.groupBy,s=0;s<a.length;s++){var o=t.match(a[s],n);if(o)if(l){if("undefined"!=typeof o[l]){var u=o[l];"undefined"==typeof r[u]&&(r[u]=[]),r[u].push(o)}}else r.push(o)}t.results(r)})},t.match=function(e,a){for(var r=!1,n=0;n<i.searchIn.length;n++){var l=i.searchIn[n];if("undefined"!=typeof e[l]){var s=e[l];t.find(s,a)&&(e[l+"_highlight"]=t.highlight(s,a),r=!0)}}return r?e:null},t.highlight=function(e,t){return e.replace(new RegExp(t,i.searchContain?"ig":"i"),'<span class="highlight">$&</span>')},t.find=function(e,a){return e=t.normalizeString(e),a=t.normalizeString(a),i.searchContain?e.indexOf(a)>=0:0===e.indexOf(a)},t._data=function(a){if(i.data.length>0)return void a(i.data);if(i.url||i.file){var r=t.keyword(),n=i.url?i.url:i.file,l=r.substring(0,i.minLength),s=t.cache(l);return s?void a(s):void(t.hasClass("flexdatalist-loading")||(t.addClass("flexdatalist-loading"),e.ajax({url:n,data:{keyword:l,contain:i.searchContain},type:"post",dataType:"json",success:function(e){t.removeClass("flexdatalist-loading");var r=e.results?e.results:e;"string"==typeof r&&0===r.indexOf("[{")&&(r=JSON.parse(r)),"object"==typeof r&&(a(r),i.url?t.cache(l,r):i.file&&(i.data=e))}})))}},t.datalist=function(){var a=t.attr("list");return a&&(t.attr("list",null),e("#"+a).find("option").each(function(){var t=e(this).val();i.data.push({label:t,value:t})})),t},t.cache=function(e,r){if(i.cache){if(e=t.normalizeString(e),"undefined"==typeof r)return"undefined"!=typeof a[e]&&(r=a[e]),r;a[e]=r}return null},t.results=function(a){if(t.removeResults(),0!==a.length||0!==Object.keys(a).length){var r=t.getContainer();t.selected()&&t.selected(!1).value(""),i.groupBy?Object.keys(a).forEach(function(n){var l=a[n],s=i.groupBy,o=t.getHighlight(l[0],s,n);e("<li>").addClass("group").append(e("<span>").addClass("group-name").html(o)).append(e("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(r);t.items(l,r)}):t.items(a,r);var n=r.find("li:not(.group)");n.on("click",function(){var a=e(this).data("item");a&&(t.selected(!0).removeResults().value(a),t.trigger("select:flexdatalist",[a,i]))}).hover(function(){n.removeClass("active"),e(this).addClass("active")},function(){e(this).removeClass("active")}),i.focusFirstResult&&n.filter(":first").addClass("active"),t.position()}},t.getContainer=function(){var a=t;i.multiple&&(a=n);var r=e("ul.flexdatalist-results");return 0===r.length&&(r=e("<ul>").addClass("flexdatalist-results").appendTo("body").css({"border-color":a.css("border-left-color"),"border-width":"1px","border-bottom-left-radius":a.css("border-bottom-left-radius"),"border-bottom-right-radius":a.css("border-bottom-right-radius")})),r},t.removeResults=function(){return e("ul.flexdatalist-results").remove(),t},t.items=function(e,a){for(var r=0;r<e.length;r++)t.item(e[r]).appendTo(a)},t.item=function(a){for(var r=e("<li>").data("item",a).addClass("item"),n=0;n<i.visibleProperties.length;n++){var l=i.visibleProperties[n];if(!(i.groupBy&&i.groupBy===l||"undefined"==typeof a[l])){var s={};if("thumb"===l)s=e("<img>").addClass("item-"+l).attr("src",a[l]);else{var o=t.getHighlight(a,l);s=e("<span>").addClass("item-"+l).html(o+" ")}s.appendTo(r)}}return r},t.hiddenInput=function(){var a=e('input[type="hidden"][name="'+r+'"]');return a.length>0?a:(t.attr("name",null),e('<input type="hidden">').attr({name:r}).insertAfter(t))},t.selected=function(e){var a="flexdatalist-selected";return"undefined"==typeof e?t.hasClass(a):(e?t.addClass(a):t.removeClass(a),t)},t.value=function(a){if("undefined"==typeof a)return t.data("value");var l=t._text(a),s=t._value(a);if(i.multiple){if(""===a)return t;t.val("");var o=e("<li>").addClass("value").append('<span class="text">'+l+"</span>").append('<span class="remove">&times;</span>').insertBefore(n.find("li.input-container"));e('<input type="hidden">').attr({name:r}).appendTo(o).val(s),o.find("span.remove").click(function(){e(this).parent().remove()})}else l=l.trim(),l.length>0&&t.val(l),t.hiddenInput().val(s);return t.trigger("change:flexdatalist",[s,l,i]),t.data("value",s)},t._text=function(e){var a=e;return"object"==typeof e&&(a=e[i.searchIn[0]],a="undefined"!=typeof e[i.textProperty]?e[i.textProperty]:t._placeholders(e,i.textProperty,a)),a},t._value=function(e){var a=e;return"object"==typeof e&&(a=e[i.searchIn[0]],a="*"===i.valueProperty?JSON.stringify(e):"undefined"!=typeof e[i.valueProperty]?e[i.valueProperty]:t._placeholders(e,i.valueProperty,a)),a},t._placeholders=function(e,t,a){if("object"==typeof e&&"string"==typeof t){var r=t.match(/\{.+?\}/g);if(r)return r.map(function(a){var r=a.slice(1,-1);"undefined"!=typeof e[r]&&(t=t.replace(a,e[r]))}),t}return a},t.normalizeString=function(e){return e.toUpperCase()},t.keyword=function(){return this.val().replace(/^\s+/,"")},t.getHighlight=function(e,t,a){return"undefined"!=typeof e[t+"_highlight"]?e[t+"_highlight"]:"undefined"!==e[t]?e[t]:a},t.position=function(){var a=t;i.multiple&&(a=n),e("ul.flexdatalist-results").css({width:a.outerWidth()+"px",top:a.offset().top+a.outerHeight()+"px",left:a.offset().left+"px","z-index":a.css("z-index")+1})},t.init(),t._setValue()}})},e(".flexdatalist").flexdatalist()}(jQuery);
+>>>>>>> 0c63a0643a111bfd5285c40f2aef208324cb2215

Merge branch 'master' of https://github.com/sergiodlopes/jquery-flexdatalist