hand-detection/assets/plugin/flexdatalist/jquery.flexdatalist.min.js

1 line
14 KiB
JavaScript
Raw Normal View History

2024-05-29 03:18:12 +00:00
jQuery.fn.flexdatalist=function(e,t){"use strict";var i,a=$(document),s=$(this),r=this;if(i=function(){var t=$(this),i={},a="",s=null;t.attr("name");t.hasClass("flexdatalist-set")&&r._destroy(t),t._options=function(e,i){var a=t.data("flexdatalist");if(!r._isDefined(e))return t.data("flexdatalist");if(r._isDefined(i))a[e]=i;else{if(!r._isObject(e))return r._isDefined(a,e)?a[e]:null;a=e}return a.searchIn=r._csvToArray(a.searchIn),a.relatives=a.relatives&&$(a.relatives).length>0?$(a.relatives):null,a.textProperty=null===a.textProperty?a.searchIn[0]:a.textProperty,a.visibleProperties=r._csvToArray(a.visibleProperties,a.searchIn),t.data("flexdatalist",a),t},t._options($.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"],searchContain:!1,searchEqual:!1,searchDisabled:!1,normalizeString:null,multiple:t.attr("multiple"),maxShownResults:100,toggleSelected:!1,_values:[]},e,t.data()));var n=t.clone(!1).attr({list:null,name:null}).addClass("flexdatalist-alias").removeClass("flexdatalist");if(t._options("multiple")){var l=$("<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).click(function(){$(this).find("input").focus()});$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(n).appendTo(l)}else n.insertAfter(t);t.addClass("flexdatalist").attr("type","hidden"),t._init=function(){var e=t._options();n.on("input keydown",function(i){var a=t._keyword();188===r._keyNum(i)&&!e.selectionRequired&&e.multiple?(i.preventDefault(),t._value(a),t._removeResults()):9===r._keyNum(i)&&t._removeResults()}).on("input keyup",function(i){if(t._changed()&&13!==r._keyNum(i)){var s=t._keyword();e.multiple||e.selectionRequired||t._value(s),s.length>=e.minLength?t._search(function(e){t._showResults(e)}):t._removeResults(),!e.multiple&&(0===s.length||s.length<e.minLength)&&t._value("")}a=t._keyword()}).focus(function(){var i=t._keyword();0===e.minLength?""===i&&t._tdata(function(e){t._showResults(e)}):i.length>=e.minLength&&!t._selected()&&t._search(function(e){t._showResults(e)})}).attr("autocomplete","off"),n.attr("autofocus")&&n.focus(),window.onresize=function(){t._position()},t.addClass("flexdatalist-set")},t._changed=function(){return a!==t._keyword()},t._chained=function(){var e=t._options();if(e.relatives&&e.chainedRelatives){var a=function(i){e.relatives.each(function(){var a=r._isEmpty($(this).val()),s=r._isEmpty(t.val());n.prop("disabled",a),i||!a&&s||(t._value(""),n.val(""),e.multiple&&l.find("li .remove").click())})};e.relatives.on("change",function(){a(),i={}}),a(!0)}},t._initValue=function(){var e=t.attr("value");r._isEmpty(e)||(t._options("originalValue",t.val()),t.val(""),n.val(""),t._parseValue(e,function(e){r._isEmpty(e)||t._values(e),a=t._keyword()}))},t._parseValue=function(e,i){var a=t._options();if(t._toJSON())try{i(JSON.parse(e))}catch(s){}else if(t._toCSV()||"string"==typeof a.valueProperty){var r=e.split(",");if("string"==typeof a.valueProperty){var n=a.searchIn;a.searchIn=a.valueProperty.split(","),a.searchEqual=!0,t._search(function(e){e.length>0&&i(e),a.searchIn=n,a.searchEqual=!1},r)}else i(r)}else i(e)},t._tdata=function(e){t.hasClass("flexdatalist-loading")||(t.trigger("before:flexdatalist.data"),t._url(function(i){t._data(function(a){a=a.concat(i);for(var s=t._options("_values"),r=0;r<a.length;r++){var n=a[r];s&&s.indexOf(t._getText(n))>-1&&delete a[r]}t.trigger("after:flexdatalist.data",[a]),e(a)})}))},t._data=function(e){var i=t._options();t._keyword();"string"==typeof i.data?t._remote({url:i.data,success:function(a){var s=t._remoteData(a);i.data=s,e(s)}}):e(i.data)},t._url=function(e){var i=t._options(),a=t._keyword(),n=a;return r._isEmpty(i.url)||i.minLength>a.length?e([]):(clearTimeout(s),void(s=setTim