-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathjquery.flexdatalist.min.js
2 lines (2 loc) · 24.5 KB
/
jquery.flexdatalist.min.js
1
2
jQuery.fn.flexdatalist=function(e,t){"use strict";var i=function(e,t){e.each((function(){var e=$(this),i=e.data(),a=i.flexdatalist,r=i.aliascontainer;r&&(e.removeClass("flexdatalist-set").attr({style:null,tabindex:null}).val(a&&a.originalValue&&!t?a.originalValue:"").removeData("flexdatalist").removeData("aliascontainer").off(),r.remove())}))};if("string"==typeof e&&"reset"!==e){if("object"==typeof this[0]&&void 0!==this[0].fvalue){var a=this[0];if("destroy"===e)i(this,t);else if("value"===e){if(void 0===t)return a.fvalue.get();a.fvalue.set(t)}else if("add"===e){if(void 0===t)return a.debug("Missing value to add!");a.fvalue.add(t)}else if("toggle"===e){if(void 0===t)return a.debug("Missing value to toggle!");a.fvalue.toggle(t)}else if("remove"===e){if(void 0===t)return a.debug("Missing value to remove!");a.fvalue.remove(t)}else if("disabled"===e){if(void 0===t)return a.fdisabled();a.fdisabled(t)}else if("string"==typeof e){if(void 0===t)return a.options.get(e);a.options.set(e,t)}return this}e={_option:t}}this.length>0&&void 0!==this[0].fvalue&&i(this);var r=$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,cacheLifetime:60,minLength:3,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],iconProperty:"thumb",searchIn:["label"],searchContain:!1,searchEqual:!1,searchByWord:!1,searchDisabled:!1,searchDelay:400,normalizeString:null,multiple:null,disabled:null,maxShownResults:100,removeOnBackspace:!0,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,allowDuplicateValues:!1,redoSearchOnFocus:!0,requestType:"get",requestContentType:"x-www-form-urlencoded",requestHeaders:null,resultsProperty:"results",keywordParamName:"keyword",searchContainParamName:"contain",limitOfValues:0,valuesSeparator:",",debug:!0},e);return this.each((function(e){var t=$(this),i=this,a=null,s=[],n="flex"+e,l=null,o=null;this.init=function(){var e=this.options.init();this.set.up(),l.on("focusin",(function(e){i.action.redoSearchFocus(e),i.action.showAllResults(e),o&&o.addClass("focus")})).on("input keydown",(function(e){if(9===i.keyNum(e)&&i.results.remove(),i.action.keypressValue(e,188),i.action.backSpaceKeyRemove(e),13===i.keyNum(e)&&0===$(".flexdatalist-results li").length)return!1})).on("input keyup",(function(e){var t=!1;if(i.action.keypressValue(e,13)&&(t=!0),i.action.keypressSearch(e),i.action.copyValue(e),i.action.backSpaceKeyRemove(e),i.action.showAllResults(e),i.action.clearValue(e),i.action.removeResults(e),i.action.inputWidth(e),t)return!1})).on("focusout",(function(e){o&&o.removeClass("focus"),i.action.clearText(e),i.action.clearValue(e)})),window.onresize=function(e){i.position()},this.cache.gc(),e.selectionRequired&&i.fvalue.clear(!0,!0),this.fvalue._load(e.originalValue,(function(a,r){i.fdisabled(e.disabled),t.trigger("init:flexdatalist",[e])}),!0)},this.action={keypressValue:function(e,t){var a=i.keyNum(e),r=l[0].value,s=i.options.get();if(r.length>0&&a===t&&!s.selectionRequired&&s.multiple){e.preventDefault(),e.stopPropagation();r=l[0].value;return i.fvalue.extract(r),i.results.remove(),!0}},keypressSearch:function(e){var t=i.keyNum(e),r=l.val(),s=r.length,n=i.options.get();clearTimeout(a),(!t||13!==t&&(t<37||t>40))&&(a=setTimeout((function(){(0===n.minLength&&s>0||n.minLength>0&&s>=n.minLength)&&i.data.load((function(e){i.search.get(r,e,(function(e){i.results.show(e)}))}))}),n.searchDelay))},redoSearchFocus:function(e){var t=i.fvalue.get(),a=i.options.get(),r=l.val();a.redoSearchOnFocus&&(r.length>0&&a.multiple||r.length>0&&0===t.length)&&this.keypressSearch(e)},copyValue:function(e){if(13!==i.keyNum(e)){var t=l.val(),a=i.fvalue.get(!0),r=i.options.get();r.multiple||r.selectionRequired||t.length===a.length||i.fvalue.extract(t)}},backSpaceKeyRemove:function(e){var t=i.options.get();if(t.removeOnBackspace&&t.multiple){var a=l.val(),r=l.data("_remove");8===i.keyNum(e)&&(0===a.length?r?(i.fvalue.remove(r),l.data("_remove",null)):l.data("_remove",l.parents("li:eq(0)").prev()):l.data("_remove",null))}},showAllResults:function(e){var t=l.val();""===(t=$.trim(t))&&0===i.options.get("minLength")&&i.data.load((function(e){i.results.show(e)}))},inputWidth:function(e){if(i.options.get().multiple){var a=l.val(),r=parseInt(l.css("fontSize").replace("px","")),s=t.innerWidth(),n=(a.length+1)*r;n>=40&&n<=s&&(l[0].style.width=n+"px")}},clearText:function(e){var t=i.fvalue.get(),a=i.options.get();!a.multiple&&a.selectionRequired&&0===t.length&&(l[0].value="")},clearValue:function(e){i.fvalue.get();var t=l.val(),a=i.options.get();!a.multiple&&a.selectionRequired&&t.length<=a.minLength&&i.fvalue.clear()},removeResults:function(e){var t=l.val(),a=i.options.get();a.minLength>0&&t.length<a.minLength&&i.results.remove()}},this.set={up:function(){l=this.getAlias(),i.options.get("multiple")?o=this.multipleInput(l):l.insertAfter(t),this.accessibility(l),t.attr("autofocus")&&l.trigger("focus"),t.data("aliascontainer",o||l).addClass("flexdatalist flexdatalist-set").css({position:"absolute",top:-14e3,left:-14e3}).attr("tabindex",-1);var e=t.attr("id"),a=l.attr("id");$('label[for="'+e+'"]').attr("for",a),this.chained()},getAlias:function(){var e=t.attr("id")?t.attr("id")+"-flexdatalist":n;return $('<input type="text">').attr({class:t.attr("class"),name:t.attr("name")?"flexdatalist-"+t.attr("name"):null,id:e,placeholder:t.attr("placeholder")}).addClass("flexdatalist-alias "+e).removeClass("flexdatalist").attr("autocomplete","off")},multipleInput:function(e){return o=$('<ul tabindex="1">').addClass("flexdatalist-multiple "+n).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).on("click",(function(){$(this).find("input").trigger("focus")})),$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(e).appendTo(o),o},chained:function(){var e=i.options.get();if(e.relatives&&e.chainedRelatives){var t=function(t){e.relatives.each((function(){var e=i.isEmpty($(this).val()),t=i.isEmpty(i.value);!e&&t||i.fvalue.clear(),i.fdisabled(e)}))};e.relatives.on("change",(function(){t()})),t()}},accessibility:function(e){var i={"aria-autocomplete":"list","aria-expanded":"false","aria-owns":(t.attr("id")?t.attr("id")+"-flexdatalist":n)+"-results"};e.attr(i)}},this.fvalue={get:function(e){var t=i.value;return!i.options.get().multiple&&!this.isJSON()||e?t:this.toObj(t)},set:function(e,a){return i.fdisabled()||(a||this.clear(!0),this._load(e)),t},add:function(e){return i.options.get("multiple")&&this.set(e,!0),this},toggle:function(e){return i.fdisabled()||this.multiple.toggle(e),this},remove:function(e){if(!i.fdisabled()){e=this.toObj(e),t.trigger("before:flexdatalist.remove",[e]);var a=[];if(i.isArray(e))$.each(e,(function(e,t){var r=i.fvalue.multiple.remove(t);r&&a.push(r)}));else{var r=this.multiple.remove(e);r&&a.push(r)}t.trigger("after:flexdatalist.remove",[e,a]).trigger("change:flexdatalist",[a,i.options.get()]).trigger("change")}return this},_load:function(e,t,a){var r=i.options.get().valueProperty,s=this.toStr(e),n=this.get(!0);if(t=t||$.noop,0!=s.length||0!=n.length){if(e=this.toObj(e),!i.isEmpty(e)&&!i.isEmpty(r)&&"*"!==r)return i.isObject(r)||(r=r.split(",")),void i.data.load((function(a){i.isObject(e)?i.isArray(e)||(e=[e]):e=e.split(",");for(var s=[],n=0;n<e.length;n++)for(var l=e[n],o=0;o<a.length;o++)for(var u=a[o],c=0;c<r.length;c++){var f=r[c];l=i.isDefined(l,f)?l[f]:l;i.isDefined(u,f)&&l===u[f]&&s.push(u)}s.length>0&&i.fvalue.extract(s,!0),t(e)}),e);t(e),i.fvalue.extract(e,a)}else t(e)},extract:function(e,a){var r=i.options.get(),s=[];a||t.trigger("before:flexdatalist.value",[e,r]),i.isArray(e)?$.each(e,(function(e,t){s.push(i.fvalue._extract(t))})):s=i.fvalue._extract(e),a||t.data("result_selected",e).trigger("after:flexdatalist.value",[s,r]).trigger("change:flexdatalist",[s,r]).trigger("change")},_extract:function(e){var t=this.text(e),a=this.value(e);if(i.options.get().multiple){if(!i.isEmpty(t)){if(i.isDup(t))return;s.push(t),this.multiple.add(a,t)}}else this.single(a,t);return{value:a,text:t}},single:function(e,t){t&&t!==l.val()&&(l[0].value=t),i.value=e},multiple:{add:function(e,t){var a=this;this.li(e,t).on("click",(function(){a.toggle($(this))})).find(".fdl-remove").on("click",(function(){i.fvalue.remove($(this).parent())})),this.push(e),l[0].value="",this.handleLimit()},push:function(e,t){var a=i.fvalue.get();if(a.includes(e))return!1;e=i.fvalue.toObj(e),a.push(e),e=i.fvalue.toStr(a),i.value=e},toggle:function(e){var a=i.options.get();if(a.toggleSelected){var r=this.findLi(e);if(r){var s=r.data(),n=r.hasClass("disabled")?"enable":"disable",l=[{value:s.value,text:s.text,action:n},a];t.trigger("before:flexdatalist.toggle",l),"enable"===n?r.removeClass("disabled"):r.addClass("disabled");var u=[];o.find("li.toggle:not(.disabled)").each((function(){var e=$(this);u.push(e.data("value"))})),u=i.fvalue.toStr(u),i.value=u,t.trigger("after:flexdatalist.toggle",l).trigger("change:flexdatalist",l).trigger("change")}}},remove:function(e){var t=this.findLi(e);if(t){var a=i.fvalue.get(),r=t.index(),n=t.data(),l={value:n.value,text:n.text};return a.splice(r,1),a=i.fvalue.toStr(a),i.value=a,t.remove(),i.fvalue.multiple.handleLimit(),s.splice(r,1),this.handleLimit(),l}},removeAll:function(){var e=i.fvalue.get(),a=i.options.get();t.trigger("before:flexdatalist.remove.all",[e,a]),o.find("li:not(.input-container)").remove(),i.value="",s=[],this.handleLimit(),t.trigger("after:flexdatalist.remove.all",[e,a])},li:function(e,t){var a=o.find("li.input-container"),r=i.options.get();return $("<li>").addClass("value"+(r.toggleSelected?" toggle":"")).append('<span class="text">'+t+"</span>").append('<span class="fdl-remove">×</span>').data({text:t,value:i.fvalue.toStr(e)}).insertBefore(a)},handleLimit:function(){var e=this.isAtLimit(),t=o.find("li.input-container");e?t.hide():t.show()},isAtLimit:function(){var e=i.options.get("limitOfValues");return e>0&&e==s.length},findLi:function(e){if(e instanceof jQuery)0===e.length&&(e=null);else{var t=e;e=null,o.find("li:not(.input-container)").each((function(){var i=$(this);if(i.data("value")===t)return e=i,!1}))}return e},isEmpty:function(){return this.get().length>0}},value:function(e){var t=e,a=i.options.get(),r=a.valueProperty;if(i.isObject(e))if(this.isJSON()||this.isMixed())if(delete e.name_highlight,i.isArray(r)){for(var s={},n=0;n<r.length;n++){var l=i.getPropertyValue(e,r[n]);l&&(s[r[n]]=l)}t=this.toStr(s)}else t=this.toStr(e);else t=i.isDefined(e,r)?i.getPropertyValue(e,r):i.isDefined(e,a.searchIn[0])?i.getPropertyValue(e,a.searchIn[0]):null;return t},text:function(e){var t=e,a=i.options.get();return i.isObject(e)&&(t=i.getPropertyValue(e,a.searchIn[0]),t=i.isDefined(e,a.textProperty)?i.getPropertyValue(e,a.textProperty):this.placeholders.replace(e,a.textProperty,t)),t=i.escapeHtml(t)},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,i.getPropertyValue(e,r)))})),t}return a},parse:function(e){var t=e.match(/\{.+?\}/g);if(!t)return!1;var i={};return t.map((function(e){i[e]=e.slice(1,-1)})),i}},clear:function(e,a){var r=i.value,n=i.options.get();return n.multiple&&this.multiple.removeAll(),i.value="",e&&(l[0].value=""),""===r||a||t.trigger("change:flexdatalist",[{value:"",text:""},n]).trigger("clear:flexdatalist",[{value:"",text:""},n]).trigger("change"),s=[],this},toObj:function(e){if("object"!=typeof e){var t=i.options.get();i.isEmpty(e)||!i.isDefined(e)?e=t.multiple?[]:this.isJSON()?{}:"":this.isCSV()?e=(e=e.toString().split(t.valuesSeparator)).map((function(e){return e.trim()})):!this.isMixed()&&!this.isJSON()||0!==e.indexOf("[")&&!this.isJSON(e)?"number"==typeof e&&(e=e.toString()):e=JSON.parse(e)}return e},toStr:function(e){return"string"!=typeof e&&(i.isEmpty(e)||!i.isDefined(e)?e="":"number"==typeof e?e=e.toString():this.isCSV()?e=e.join(i.options.get("valuesSeparator")):(this.isJSON()||this.isMixed())&&(e=JSON.stringify(e))),$.trim(e)},isJSON:function(e){if(void 0!==e){if(i.isObject(e))e=JSON.stringify(e);else if("string"!=typeof e)return!1;return 0===e.indexOf("{")||0===e.indexOf("[{")}var t=i.options.get().valueProperty;return i.isObject(t)||"*"===t},isMixed:function(){var e=i.options.get();return!e.selectionRequired&&("*"===e.valueProperty||i.isObject(e.valueProperty))},isCSV:function(){return!this.isJSON()&&i.options.get("multiple")}},this.data={load:function(e,i){var a=this,r=[];t.trigger("before:flexdatalist.data"),this.url((function(i){r=r.concat(i),a.static((function(i){r=r.concat(i),a.datalist((function(i){r=r.concat(i),t.trigger("after:flexdatalist.data",[r]),e(r)}))}))}),i)},static:function(e){var t=i.options.get();if("string"==typeof t.data){var a=t.data,r=i.cache.read(a,!0);if(r)return void e(r);this.remote({url:a,success:function(r){t.data=r,e(r),i.cache.write(a,r,t.cacheLifetime,!0)}})}else"object"!=typeof t.data&&(t.data=[]),e(t.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,a){var r=l.val(),s=i.options.get(),n=s.keywordParamName,o=s.searchContainParamName,u=i.fvalue.get(),c=this.relativesData();if(i.isEmpty(s.url))return e([]);var f={};"post"===s.requestType&&($.each(s,(function(e,t){0!=e.indexOf("_")&&"data"!=e&&(f[e]=t)})),delete f.relatives);var d=i.cache.keyGen({relative:c,load:a,keyword:r,contain:s.searchContain},s.url),h=i.cache.read(d,!0);if(h)e(h);else{var p="function"==typeof s.params?s.params.call(t[0],r):s.params,g=$.extend(c,p,{load:a,selected:u,original:s.originalValue,options:f});g[n]=r,g[o]=s.searchContain,this.remote({url:s.url,data:g,success:function(t){l.val().length>=r.length&&e(t),i.cache.write(d,t,s.cacheLifetime,!0)}})}},remote:function(e){var a=this,r=i.options.get();t.hasClass("flexdatalist-loading")||(t.addClass("flexdatalist-loading"),"json"===r.requestContentType&&(e.data=JSON.stringify(e.data)),$.ajax($.extend({type:r.requestType,dataType:"json",headers:r.requestHeaders,contentType:"application/"+r.requestContentType+"; charset=UTF-8",complete:function(){t.removeClass("flexdatalist-loading")}},e,{success:function(t){t=a.extractRemoteData(t),e.success(t)}})))},extractRemoteData:function(e){var t=i.options.get(),a=i.isDefined(e,t.resultsProperty)?e[t.resultsProperty]:e;return"string"==typeof a&&0===a.indexOf("[{")&&(a=JSON.parse(a)),a&&a.options&&i.options.set($.extend({},t,a.options)),i.isObject(a)?a:[]},relativesData:function(){var e=i.options.get("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,r){var s=a;if(!i.options.get().searchDisabled&&!(s=i.cache.read(e))){if(t.trigger("before:flexdatalist.search",[e,a]),!i.isEmpty(e)){s=[];for(var n=this.split(e),l=0;l<a.length;l++){var o=a[l];i.isDup(o)||(o=this.matches(o,n))&&s.push(o)}}i.cache.write(e,s,2),t.trigger("after:flexdatalist.search",[e,a,s])}r(s)},matches:function(e,t){var a=$.extend({},e),r=[],s=i.options.get(),n=s.searchIn;if(t.length>0)for(var l=0;l<n.length;l++){var o=n[l];if(i.isDefined(e,o)&&e[o]){for(var u=e[o].toString(),c=u,f=this.split(u),d=0;d<t.length;d++){var h=t[d];this.find(h,f)&&(r.push(h),c=this.highlight(h,c))}c!==u&&(a[o+"_highlight"]=this.highlight(c))}}return!(0===r.length||s.searchByWord&&r.length<t.length-1)&&a},highlight:function(e,t){return t?(e=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),t.replace(new RegExp(e,i.options.get("searchContain")?"ig":"i"),"|:|$&|::|")):(e=e.split("|:|").join('<span class="highlight">')).split("|::|").join("</span>")},find:function(e,t){for(var a=i.options.get(),r=0;r<t.length;r++){var s=t[r];if(s=this.normalizeString(s),e=this.normalizeString(e),a.searchEqual)return s==e;if(a.searchContain?s.indexOf(e)>=0:0===s.indexOf(e))return!0}return!1},split:function(e){if("string"==typeof e&&(e=[$.trim(e)]),i.options.get("searchByWord"))for(var t=0;t<e.length;t++){var a=$.trim(e[t]);if(a.indexOf(" ")>0){var r=a.split(" ");$.merge(e,r)}}return e},normalizeString:function(e){if("string"==typeof e){var t=i.options.get("normalizeString");return"function"==typeof t&&(e=t(e)),(e=e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")).toUpperCase()}return e}},this.results={show:function(e){var a=this,r=i.options.get();if(this.remove(!0),e)if(0!==e.length){var s=this.container();r.groupBy?(e=this.group(e),Object.keys(e).forEach((function(t,n){var l=e[t],o=r.groupBy,u=i.results.highlight(l[0],o,t);$("<li>").addClass("group").append($("<span>").addClass("group-name").html(u)).append($("<span>").addClass("group-item-count").text(" "+l.length)).appendTo(s);a.items(l,s)}))):this.items(e,s);var n=s.find("li:not(.group)");n.on("click",(function(e){var s=$(this).data("item");s&&(i.fvalue.extract(s),a.remove(),t.trigger("select:flexdatalist",[s,r]))})).on("hover",(function(){n.removeClass("active"),$(this).addClass("active").trigger("active:flexdatalist.results",[$(this).data("item")])}),(function(){$(this).removeClass("active")})),r.focusFirstResult&&n.filter(":first").addClass("active")}else this.empty(r.noResultsText)},empty:function(e){if(!i.isEmpty(e)){var a=this.container(),r=l.val();e=e.split("{keyword}").join(r),$("<li>").addClass("item no-results").append(e).appendTo(a),t.trigger("empty:flexdatalist.results",[e])}},items:function(e,a){var r=i.options.get("maxShownResults");t.trigger("show:flexdatalist.results",[e]);for(var s=0;s<e.length&&!(r>0&&r===s);s++)this.item(e[s],s,e.length).appendTo(a);t.trigger("shown:flexdatalist.results",[e])},item:function(e,a,r){var s=$("<li>").attr({role:"option",tabindex:"-1","aria-posinset":a+1,"aria-setsize":r}).data("item",e).addClass("item"),n=i.options.get(),l=n.visibleProperties;for(a=0;a<l.length;a++){var o=l[a];if(o.indexOf("{")>-1){var u=i.fvalue.placeholders.replace(e,o),c=i.fvalue.placeholders.parse(o);f=$("<span>").addClass("item item-"+Object.values(c).join("-")).html(u+" ")}else{if(n.groupBy&&n.groupBy===o||!i.isDefined(e,o))continue;var f={};if(o===n.iconProperty)f=$("<img>").addClass("item item-"+o).attr("src",e[o]);else{var d=i.results.highlight(e,o);f=$("<span>").addClass("item item-"+o).html(d+" ")}}f.appendTo(s)}return t.trigger("item:flexdatalist.results",[s,e]),s},container:function(){var e=t;o&&(e=o);var a=$("ul.flexdatalist-results");return 0===a.length&&(a=$("<ul>").addClass("flexdatalist-results ").appendTo("body").attr({id:l.attr("id")+"-results",role:"listbox"}).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:o||l,input:t}),i.position(l)),a},group:function(e){for(var t=[],a=i.options.get("groupBy"),r=0;r<e.length;r++){var s=e[r];if(i.isDefined(s,a)){var n=s[a];i.isDefined(t,n)||(t[n]=[]),t[n].push(s)}}return t},highlight:function(e,t,a){return i.isDefined(e,t+"_highlight")?e[t+"_highlight"]:i.isDefined(e,t)?e[t]:a},active:function(e){},remove:function(e){var i="ul.flexdatalist-results";e&&(i="ul.flexdatalist-results li"),t.trigger("remove:flexdatalist.results"),$(i).remove(),t.trigger("removed:flexdatalist.results")}},this.cache={write:function(e,t,a,r){if(i.cache.isSupported()){e=this.keyGen(e,void 0,r);var s={value:t,timestamp:i.unixtime(),lifetime:a||!1};localStorage.setItem(e,JSON.stringify(s))}},read:function(e,t){if(i.cache.isSupported()){e=this.keyGen(e,void 0,t);var a=localStorage.getItem(e);if(a){var r=JSON.parse(a);if(!this.expired(r))return r.value;localStorage.removeItem(e)}}return null},delete:function(e,t){i.cache.isSupported()&&(e=this.keyGen(e,void 0,t),localStorage.removeItem(e))},clear:function(){if(i.cache.isSupported()){for(var e in localStorage)(e.indexOf(n)>-1||e.indexOf("global")>-1)&&localStorage.removeItem(e);localStorage.clear()}},gc:function(){if(i.cache.isSupported())for(var e in localStorage)if(e.indexOf(n)>-1||e.indexOf("global")>-1){var t=localStorage.getItem(e);t=JSON.parse(t),this.expired(t)&&localStorage.removeItem(e)}},isSupported:function(){if(i.options.get("cache"))try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}return!1},expired:function(e){if(e.lifetime){var t=i.unixtime()-e.timestamp;return e.lifetime<=t}return!1},keyGen:function(e,t,i){"object"==typeof e&&(e=JSON.stringify(e));var a,r,s=void 0===t?2166136261:t;for(a=0,r=e.length;a<r;a++)s^=e.charCodeAt(a),s+=(s<<1)+(s<<4)+(s<<7)+(s<<8)+(s<<24);return(i?"global":n)+("0000000"+(s>>>0).toString(16)).substr(-8)}},this.options={init:function(){var e=$.extend({},r,t.data(),{multiple:null===r.multiple?t.is("[multiple]"):r.multiple,disabled:null===r.disabled?t.is("[disabled]"):r.disabled,originalValue:i.value});return this.set(e),e},get:function(e){var a=t.data("flexdatalist");return e?i.isDefined(a,e)?a[e]:null:a||{}},set:function(e,a){var r=this.get();return i.isDefined(r,e)&&i.isDefined(a)?r[e]=a:i.isObject(e)&&(r=this._normalize(e)),t.data("flexdatalist",r),t},_normalize:function(e){if(e.searchIn=i.csvToArray(e.searchIn),e.relatives=e.relatives&&$(e.relatives).length>0?$(e.relatives):null,e.textProperty=null===e.textProperty?e.searchIn[0]:e.textProperty,e.visibleProperties=i.csvToArray(e.visibleProperties,e.searchIn),"*"===e.valueProperty&&e.multiple&&!e.selectionRequired)throw new Error("Selection must be required for multiple, JSON fields!");return e}},this.position=function(){var e=$("ul.flexdatalist-results"),t=e.data("target");e.length>0&&e.css({width:t.outerWidth()+"px",top:t.offset().top+t.outerHeight()+"px",left:t.offset().left+"px"})},this.fdisabled=function(e){if(this.isDefined(e)){if(t.prop("disabled",e),l.prop("disabled",e),o){o.css("background-color",t.css("background-color"));var i=o.find("li .fdl-remove"),a=o.find("li.input-container");e?(o.addClass("disabled"),i.length>0&&a.hide(),i.hide()):(o.removeClass("disabled"),a.show(),i.show())}this.options.set("disabled",e)}return this.options.get("disabled")},this.isDup=function(e){return!this.options.get("allowDuplicateValues")&&(s.length>0&&s.indexOf(this.fvalue.text(e))>-1)},this.keyNum=function(e){return e.which||e.keyCode},this.isEmpty=function(e){return!i.isDefined(e)||(null===e||!0!==e&&(0===this.length(e)||""===$.trim(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=void 0!==e;return i&&void 0!==t?void 0!==this.getPropertyValue(e,t):i},this.isObject=function(e){return e&&"object"==typeof e},this.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},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(i.options.get("valuesSeparator")):e},this.getPropertyValue=function(e,t){if(e&&"string"==typeof t){for(var i=t.split(".");i.length&&(e=e[i.shift()]););return e}},this.escapeHtml=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},this.debug=function(e,a){var r=i.options.get();r.debug&&(a||(a={}),e="Flexdatalist: "+e,console.warn(e),console.log($.extend({inputName:t.attr("name"),options:r},a)),console.log("--- /flexdatalist ---"))},this.init()}))},jQuery((function(e){e(document).data("flexdatalist")||e(document).on("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()})).on("keydown",(function(t){var i=e(".flexdatalist-results"),a=i.find("li"),r=a.filter(".active"),s=r.index(),n=a.length,l=t.which||t.keyCode;if(0!==n)if(27!==l){if(13===l)t.preventDefault(),r.trigger("click");else if(40===l||38===l){t.preventDefault(),40===l?r=s<n&&r.nextAll(".item").first().length>0?r.removeClass("active").nextAll(".item").first().addClass("active"):a.removeClass("active").filter(".item:first").addClass("active"):38===l&&(r=s>0&&r.prevAll(".item").first().length>0?r.removeClass("active").prevAll(".item").first().addClass("active"):a.removeClass("active").filter(".item:last").addClass("active")),r.trigger("active:flexdatalist.results",[r.data("item")]);var o=(0===r.prev().length?r:r.prev()).position().top;i.animate({scrollTop:o+i.scrollTop()},100)}}else i.remove()})).data("flexdatalist",!0),jQuery("input.flexdatalist:not(.flexdatalist-set):not(.autodiscover-disabled)").flexdatalist()})),function(e){var t=e.fn.val;e.fn.val=function(e){var i=this.length>0&&void 0!==this[0].fvalue;return void 0===e?i?this[0].fvalue.get(!0):t.call(this):i?this[0].fvalue.set(e):t.call(this,e)}}(jQuery);
//# sourceMappingURL=jquery.flexdatalist.min.js.map