").addClass("value"+(i.toggleSelected?" toggle":"")).append(''+s+"").append('×').insertBefore(l.find("li.input-container"));o.find("span.fdl-remove").click(function(){var e=$(this).parent(),a=e.index();if(!e.hasClass("disabled")&&(t._toJSON()||t._toCSV())){var s=t._inputValue();s.splice(a,1),i._values.splice(a,1),t._inputValue(s)}e.remove()}),i.toggleSelected&&o.click(function(){var e=$(this),a=t._inputValue(),s=e.index();if(e.hasClass("disabled")){var r=e.data("_value");a.splice(s,0,r),i._values.splice(s,0,t._getText(r)),e.removeClass("disabled")}else{var r=a.splice(s,1);e.data("_value",r[0]),i._values.splice(s,1),e.addClass("disabled")}t._inputValue(a)})}else s&&s!==n.val()&&n.val(s);return t._inputValue(r,s),a=t._keyword(),t},t._inputValue=function(e,i){var a=t._toJSON(),s=t._toCSV();return r._isDefined(e)?(r._isObject(e)&&(a&&!r._isEmpty(e)?e=JSON.stringify(e):s&&(e=e.join(","))),""===e&&t._options("_values",[]),t.val(e),t.trigger("change:flexdatalist",[e,i,t._options()]).trigger("change"),e):(e=t.val(),e?a?e=JSON.parse(e):s&&(e=e.split(",")):(a||s)&&(e=[]),e)},t._getText=function(e){var i=e,a=t._options();return r._isObject(e)&&(i=e[a.searchIn[0]],i=r._isDefined(e,a.textProperty)?e[a.textProperty]:t._replacePlaceholders(e,a.textProperty,i)),$("").html(i).text()},t._getValue=function(e){var i=e,a=t._options();if(r._isObject(e))if(i=e[a.searchIn[0]],"*"===a.valueProperty)i=e;else if(r._isDefined(e,a.valueProperty))i=e[a.valueProperty];else if(t._toJSON()){var i={},s=a.valueProperty,n=a.textProperty;if(n){var l=n;"string"==typeof n&&(l=t._parsePlaceholders(n)),r._isObject(l)&&$.each(l,function(e,t){s.push(t)})}else r._isDefined(e,n)&&s.push(n);$.each(s,function(t,a){r._isDefined(e,a)&&(i[a]=e[a])})}if(a.multiple&&(t._toJSON()||t._toCSV())){var o=t._inputValue();!r._isEmpty(i)&&r._isObject(o)&&(o.push(i),i=o)}return i},t._replacePlaceholders=function(e,i,a){if(r._isObject(e)&&"string"==typeof i){var s=t._parsePlaceholders(i);if(!r._isEmpty(e)&&s)return $.each(s,function(t,a){r._isDefined(e,a)&&(i=i.replace(t,e[a]))}),i}return a},t._parsePlaceholders=function(e){var t=e.match(/\{.+?\}/g);if(t){var i={};return t.map(function(e){i[e]=e.slice(1,-1)}),i}return!1},t._normalizeString=function(e){if("string"==typeof e){var i=t._options("normalizeString");return"function"==typeof i&&(e=i(e)),e.toUpperCase()}return e},t._keyword=function(){return n.val().replace(/^\s+/,"")},t._toJSON=function(){var e=t._options("valueProperty");return r._isObject(e)||"*"===e},t._toCSV=function(){return!t._toJSON()&&t._options("multiple")},t._position=function(){var e=n;t._options("multiple")&&(e=l),$("ul.flexdatalist-results").css({width:e.outerWidth()+"px",top:e.offset().top+e.outerHeight()+"px",left:e.offset().left+"px","z-index":e.css("z-index")+1})},t._datalist(),t._init(),t._initValue(),t._chained(),a=t._keyword()},this._destroy=function(e){e||(e=s),e.each(function(){var e=$(this).data("flexdatalist");$(this).removeClass("flexdatalist-set").off().attr("type","text").val(e&&e.originalValue?e.originalValue:"").data("flexdatalist",null).next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})},this._reset=function(){this._destroy()},"string"==typeof e)if("function"==typeof this["_"+e]){if(!this["_"+e]())return this}else{if(!t){var n=s.data("flexdatalist");return n[e]}if(t){var n=s.data("flexdatalist");return n[e]=t,s.data("flexdatalist",n),this}}return this._keyNum=function(e){return e.which||e.keyCode},a.data("flexdatalist")||$(document).mouseup(function(e){var t=$(".flexdatalist-results"),i=t.data("target");i&&i.is(":focus")||t.is(e.target)||0!==t.has(e.target).length||t.remove()}).keydown(function(e){var t=$(".flexdatalist-results"),i=t.find("li"),a=i.filter(".active"),s=a.index(),n=i.length,l=r._keyNum(e);if(0!==n)if(13===l)e.preventDefault(),a.click();else if(40===l||38===l){e.preventDefault(),40===l?a=n>s&&a.nextAll(".item").first().length>0?a.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===l&&(a=s>0&&a.prevAll(".item").first().length>0?a.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active"));var o=(0===a.prev().length?a:a.prev()).position().top;t.animate({scrollTop:o+t.scrollTop()},100)}}).data("flexdatalist",!0),this._isEmpty=function(e){return r._isDefined(e)?null===e?!0:e===!0?!1:0===this._length(e)?!0:""===$.trim(e):!0},this._isObject=function(e){return e&&"object"==typeof e},this._csvToArray=function(e,t){return 0===e.length?t:"string"==typeof e?e.split(","):e},this._length=function(e){return this._isObject(e)?Object.keys(e).length:"number"==typeof e.length?e.length:0},this._isDefined=function(e,t){var i="undefined"!=typeof e;return i&&"undefined"!=typeof t?"undefined"!=typeof e[t]:i},this.each(i)},$(function(){$("input.flexdatalist").flexdatalist()});