From 49d73d5e16115d37c773999830ad44c97603327f Mon Sep 17 00:00:00 2001 From: Mai Abuthraa Date: Mon, 24 May 2021 14:13:06 +0300 Subject: [PATCH 1/5] DC-7463: Show categories deplaned on data, --- dist/easy-autocomplete.css | 2 +- dist/easy-autocomplete.min.css | 2 +- dist/easy-autocomplete.themes.css | 2 +- dist/easy-autocomplete.themes.min.css | 2 +- dist/jquery.easy-autocomplete.js | 34 +++++++++---------- dist/jquery.easy-autocomplete.min.js | 4 +-- dist/maps/easy-autocomplete.css.map | 2 +- dist/maps/easy-autocomplete.min.css.map | 2 +- dist/maps/easy-autocomplete.themes.css.map | 2 +- .../maps/easy-autocomplete.themes.min.css.map | 2 +- package.json | 2 +- src/list.builder.js | 32 ++++++++--------- 12 files changed, 44 insertions(+), 44 deletions(-) diff --git a/dist/easy-autocomplete.css b/dist/easy-autocomplete.css index c804104..a69fb67 100644 --- a/dist/easy-autocomplete.css +++ b/dist/easy-autocomplete.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.0 + * @version 1.4.1 * Copyright License: */ diff --git a/dist/easy-autocomplete.min.css b/dist/easy-autocomplete.min.css index 60dc957..7c1cfe2 100644 --- a/dist/easy-autocomplete.min.css +++ b/dist/easy-autocomplete.min.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.0 + * @version 1.4.1 * Copyright License: */ diff --git a/dist/easy-autocomplete.themes.css b/dist/easy-autocomplete.themes.css index 5f5d3e7..a4957c5 100644 --- a/dist/easy-autocomplete.themes.css +++ b/dist/easy-autocomplete.themes.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.0 + * @version 1.4.1 * Copyright License: */ diff --git a/dist/easy-autocomplete.themes.min.css b/dist/easy-autocomplete.themes.min.css index 72c15ea..9a224ca 100644 --- a/dist/easy-autocomplete.themes.min.css +++ b/dist/easy-autocomplete.themes.min.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.0 + * @version 1.4.1 * Copyright License: */ diff --git a/dist/jquery.easy-autocomplete.js b/dist/jquery.easy-autocomplete.js index 6b26412..905f8af 100644 --- a/dist/jquery.easy-autocomplete.js +++ b/dist/jquery.easy-autocomplete.js @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.0 + * @version 1.4.1 * Copyright License: */ @@ -394,9 +394,9 @@ var EasyAutocomplete = (function (scope) { })(EasyAutocomplete || {}); /* - * EasyAutocomplete - ListBuilderService + * EasyAutocomplete - ListBuilderService * - * @author Łukasz Pawełczak + * @author Łukasz Pawełczak * */ var EasyAutocomplete = (function (scope) { @@ -418,23 +418,23 @@ var EasyAutocomplete = (function (scope) { return listBuilder; }; - this.updateCategories = function (listBuilder, data) { + this.updateCategories = function(listBuilder, data) { + if (configuration.get("categoriesAssigned")) { + listBuilder = []; - if (configuration.get('categoriesAssigned')) { + $.each(data, function( index, value ) { + var builder = convertToListBuilder({ + listLocation: index, + maxNumberOfElements: 10, + header: index.replace(/[_\s]+/g, ' ') + }, data); - listBuilder = []; + listBuilder.push(builder); + }); + } - for (var i = 0; i < configuration.get("categories").length; i += 1) { - - var builder = convertToListBuilder(configuration.get('categories')[i], data); - - listBuilder.push(builder); - } - - } - - return listBuilder; - }; + return listBuilder; + }; this.convertXml = function (listBuilder) { if (configuration.get('dataType').toUpperCase() === 'XML') { diff --git a/dist/jquery.easy-autocomplete.min.js b/dist/jquery.easy-autocomplete.min.js index e91aeea..5d93987 100644 --- a/dist/jquery.easy-autocomplete.min.js +++ b/dist/jquery.easy-autocomplete.min.js @@ -3,8 +3,8 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.0 + * @version 1.4.1 * Copyright License: */ -var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){if("xml"===a.dataType&&(a.getValue||(a.getValue=function(a){return $(a).text()}),a.list||(a.list={}),a.list.sort||(a.list.sort={}),a.list.sort.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),bc?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(a,b){return a.search(b)>-1}),void 0!==a.categories&&a.categories instanceof Array){for(var b=[],c=0,d=a.categories.length;cb?1:0}},maxNumberOfElements:6,hideOnEmptyPhrase:!0,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a.search(b)>-1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onChooseEvent:function(){},onKeyEnterEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){},onShowListEvent:function(){},onHideListEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,requestDelay:0,adjustWidth:!0,ajaxSettings:{},preparePostData:function(a,b){return a},loggerEnabled:!0,template:"",categoriesAssigned:!1,categories:[{maxNumberOfElements:4}]},i=["ajaxSettings","template"];this.get=function(a){return h[a]},this.equals=function(a,b){return!(!f(a)||h[a]!==b)},this.checkDataUrlProperties=function(){return!("list-required"===h.url&&"list-required"===h.data)},this.checkRequiredProperties=function(){for(var a in h)if("required"===h[a])return logger.error("Option "+a+" must be defined"),!1;return!0},this.printPropertiesThatDoesntExist=function(a,b){g(a,b)},b(),c(),!0===h.loggerEnabled&&g(console,a),e(),d()},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Logger=function(){this.error=function(a){console.log("ERROR: "+a)},this.warning=function(a){console.log("WARNING: "+a)}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Constants=function(){var a={CONTAINER_CLASS:"easy-autocomplete-container",CONTAINER_ID:"eac-container-",WRAPPER_CSS_CLASS:"easy-autocomplete"};this.getValue=function(b){return a[b]}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.ListBuilderService=function(a,b){function c(b,c){function d(){var d,e={};return void 0!==b.xmlElementName&&(e.xmlElementName=b.xmlElementName),void 0!==b.listLocation?d=b.listLocation:void 0!==a.get("listLocation")&&(d=a.get("listLocation")),void 0!==d?"string"==typeof d?e.data=$(c).find(d):"function"==typeof d&&(e.data=d(c)):e.data=c,e}function e(){var a={};return void 0!==b.listLocation?"string"==typeof b.listLocation?a.data=c[b.listLocation]:"function"==typeof b.listLocation&&(a.data=b.listLocation(c)):a.data=c,a}var f={};if(f="XML"===a.get("dataType").toUpperCase()?d():e(),void 0!==b.header&&(f.header=b.header),void 0!==b.maxNumberOfElements&&(f.maxNumberOfElements=b.maxNumberOfElements),void 0!==a.get("list").maxNumberOfElements&&(f.maxListSize=a.get("list").maxNumberOfElements),void 0!==b.getValue)if("string"==typeof b.getValue){var g=b.getValue;f.getValue=function(a){return a[g]}}else"function"==typeof b.getValue&&(f.getValue=b.getValue);else f.getValue=a.get("getValue");return f}function d(b){var c=[];return void 0===b.xmlElementName&&(b.xmlElementName=a.get("xmlElementName")),$(b.data).find(b.xmlElementName).each(function(){c.push(this)}),c}this.init=function(b){var c=[],d={};return d.data=a.get("listLocation")(b),d.getValue=a.get("getValue"),d.maxListSize=a.get("list").maxNumberOfElements,c.push(d),c},this.updateCategories=function(b,d){if(a.get("categoriesAssigned")){b=[];for(var e=0;e0)return!0;return!1}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.proccess=function(b,c,d){function e(a,c){var d=[],e="";if(b.get("list").match.enabled)for(var g=0,h=a.length;gc.maxNumberOfElements&&(a=a.slice(0,c.maxNumberOfElements)),a}function h(a){return b.get("list").sort.enabled&&a.sort(b.get("list").sort.method),a}a.proccess.match=f;var i=c.data;return i=e(i,d),i=g(i),i=h(i)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a},cssClass:""},description:{type:"description",fields:{description:"description"},method:function(a){return a+" - description"},cssClass:"eac-description"},iconLeft:{type:"iconLeft",fields:{icon:""},method:function(a){return a},cssClass:"eac-icon-left"},iconRight:{type:"iconRight",fields:{iconSrc:""},method:function(a){return a},cssClass:"eac-icon-right"},links:{type:"links",fields:{link:""},method:function(a){return a},cssClass:""},custom:{type:"custom",method:function(){},cssClass:""}},c=function(a){var c,d=a.fields;return"description"===a.type?(c=b.description.method,"string"==typeof d.description?c=function(a,b){return a+" - "+b[d.description]+""}:"function"==typeof d.description&&(c=function(a,b){return a+" - "+d.description(b)+""}),c):"iconRight"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return a+""}:"function"==typeof d.iconSrc&&(c=function(a,b){return a+""}),c):"iconLeft"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return""+a}:"function"==typeof d.iconSrc&&(c=function(a,b){return""+a}),c):"links"===a.type?("string"==typeof d.link?c=function(a,b){return""+a+""}:"function"==typeof d.link&&(c=function(a,b){return""+a+""}),c):"custom"===a.type?a.method:b.basic.method},d=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},e=function(a){var c=function(){return""};return a&&a.type&&a.type&&b[a.type]?function(){var c=b[a.type].cssClass;return function(){return c}}():c};this.getTemplateClass=e(a),this.build=d(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return 0===t.length?void p.error("Input field doesn't exist."):o.checkDataUrlProperties()?o.checkRequiredProperties()?(e(),void g()):void p.error("Will not work without mentioned properties."):void p.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
"),c=n.getValue("WRAPPER_CSS_CLASS");o.get("theme")&&""!==o.get("theme")&&(c+=" eac-"+o.get("theme")),o.get("cssClasses")&&""!==o.get("cssClasses")&&(c+=" "+o.get("cssClasses")),""!==q.getTemplateClass()&&(c+=" "+q.getTemplateClass()),a.addClass(c),t.wrap(a),!0===o.get("adjustWidth")&&b()}function b(){var a=t.outerWidth();t.parent().css("width",a)}function c(){t.unwrap()}function d(){var a=$("
").addClass(n.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
    ")),function(){a.on("show.eac",function(){if(t.is(":focus")){switch(o.get("list").showAnimation.type){case"slide":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").fadeIn(b);break;default:a.find("ul").show()}o.get("list").onShowListEvent()}}).on("hide.eac",function(){switch(o.get("list").hideAnimation.type){case"slide":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}o.get("list").onHideListEvent()}).on("selectElement.eac",function(){a.find("ul li").removeClass("selected"),a.find("ul li").eq(w).addClass("selected"),o.get("list").onSelectItemEvent()}).on("loadElements.eac",function(b,c,d){var e="",f=a.find("ul");f.empty().detach(),v=[];for(var h=0,i=0,k=c.length;i0&&f.append("
    "+c[i].header+"
    ");for(var m=0,n=l.length;m
    "),function(){var a=m,b=h,f=c[i].getValue(l[a]);e.find(" > div").on("click",function(){t.val(f).trigger("change"),w=b,j(b),o.get("list").onClickEvent(),o.get("list").onChooseEvent()}).mouseover(function(){w=b,j(b),o.get("list").onMouseOverEvent()}).mouseout(function(){o.get("list").onMouseOutEvent()}).html(q.build(g(f,d),l[a]))}(),f.append(e),v.push(l[m]),h+=1}}a.append(f),o.get("list").onLoadEvent()})}(),t.after(a)}function e(){t.next("."+n.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return o.get("highlightPhrase")&&""!==b?i(a,b):a}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(a,b){var c=h(b);return(a+"").replace(new RegExp("("+c+")","gi"),"$1")}t.parent().hasClass(n.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),u=$("#"+f()),o.get("placeholder")&&t.attr("placeholder",o.get("placeholder"))}function f(){var a=t.attr("id");return a=n.getValue("CONTAINER_ID")+a}function g(){function a(){s("autocompleteOff",!0)&&n(),b(),c(),d(),e(),f(),g()}function b(){t.focusout(function(){var a,b=t.val();o.get("list").match.caseSensitive||(b=b.toLowerCase());for(var c=0,d=v.length;c0?h():i()}var f=b();void 0!==f.url&&""!==f.url||(f.url=o.get("url")),void 0!==f.dataType&&""!==f.dataType||(f.dataType=o.get("dataType")),void 0!==f.url&&"list-required"!==f.url&&(f.url=f.url(a),f.data=o.get("preparePostData")(f.data,a),$.ajax(f).done(function(b){var d=r.init(b);d=r.updateCategories(d,b),d=r.convertXml(d),c(a,b)&&(d=r.processData(d,a),k(d,a)),r.checkIfDataExists(d)&&t.parent().find("li").length>0?h():i(),o.get("ajaxCallback")()}).fail(function(){p.warning("Fail to load response data")}).always(function(){}))}}switch(a.keyCode){case 27:i(),l();break;case 38:a.preventDefault(),v.length>0&&w>0&&(w-=1,t.val(o.get("getValue")(v[w])),j(w));break;case 40:a.preventDefault(),v.length>0&&w40||8===a.keyCode||0===a.keyCode){var c=t.val();!0!==o.get("list").hideOnEmptyPhrase||8!==a.keyCode||""!==c?o.get("requestDelay")>0?(void 0!==m&&clearTimeout(m),m=setTimeout(function(){b(c)},o.get("requestDelay"))):b(c):i()}}})}function d(){t.on("keydown",function(a){if(a=a||window.event,38===a.keyCode)return suppressKeypress=!0,!1}).keydown(function(a){13===a.keyCode&&w>-1&&(t.val(o.get("getValue")(v[w])),o.get("list").onKeyEnterEvent(),o.get("list").onChooseEvent(),w=-1,i(),a.preventDefault())})}function e(){t.off("keypress")}function f(){t.focus(function(){""!==t.val()&&v.length>0&&(w=-1,h())})}function g(){t.blur(function(){setTimeout(function(){w=-1,i()},250)})}function n(){t.attr("autocomplete","off")}a()}function h(){u.trigger("show.eac")}function i(){u.trigger("hide.eac")}function j(a){u.trigger("selectElement.eac",a)}function k(a,b){u.trigger("loadElements.eac",[a,b])}function l(){t.trigger("blur")}var m,n=new a.Constants,o=new a.Configuration(c),p=new a.Logger,q=new a.Template(c.template),r=new a.ListBuilderService(o,a.proccess),s=o.equals,t=b,u="",v=[],w=-1;a.consts=n,this.getConstants=function(){return n},this.getConfiguration=function(){return o},this.getContainer=function(){return u},this.getSelectedItemIndex=function(){return w},this.getItems=function(){return v},this.getItemData=function(a){return v.length0},a.assignRandomId=function(b){var c="";do{c="eac-"+Math.floor(1e4*Math.random())}while(0!==$("#"+c).length);elementId=a.consts.getValue("CONTAINER_ID")+c,$(b).attr("id",c)},a.setHandle=function(b,c){a.eacHandles[c]=b},a}(EasyAutocomplete||{});!function(a){a.fn.easyAutocomplete=function(b){return this.each(function(){var c=a(this),d=new EasyAutocomplete.main(c,b);EasyAutocomplete.inputHasId(c)||EasyAutocomplete.assignRandomId(c),d.init(),EasyAutocomplete.setHandle(d,c.attr("id"))})},a.fn.getSelectedItemIndex=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemIndex():-1},a.fn.getItems=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getItems():-1},a.fn.getItemData=function(b){var c=a(this).attr("id");return void 0!==c&&b>-1?EasyAutocomplete.getHandle(c).getItemData(b):-1},a.fn.getSelectedItemData=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemData():-1}}(jQuery); \ No newline at end of file +var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){if("xml"===a.dataType&&(a.getValue||(a.getValue=function(a){return $(a).text()}),a.list||(a.list={}),a.list.sort||(a.list.sort={}),a.list.sort.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),bc?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(a,b){return a.search(b)>-1}),void 0!==a.categories&&a.categories instanceof Array){for(var b=[],c=0,d=a.categories.length;cb?1:0}},maxNumberOfElements:6,hideOnEmptyPhrase:!0,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a.search(b)>-1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onChooseEvent:function(){},onKeyEnterEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){},onShowListEvent:function(){},onHideListEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,requestDelay:0,adjustWidth:!0,ajaxSettings:{},preparePostData:function(a,b){return a},loggerEnabled:!0,template:"",categoriesAssigned:!1,categories:[{maxNumberOfElements:4}]},i=["ajaxSettings","template"];this.get=function(a){return h[a]},this.equals=function(a,b){return!(!f(a)||h[a]!==b)},this.checkDataUrlProperties=function(){return!("list-required"===h.url&&"list-required"===h.data)},this.checkRequiredProperties=function(){for(var a in h)if("required"===h[a])return logger.error("Option "+a+" must be defined"),!1;return!0},this.printPropertiesThatDoesntExist=function(a,b){g(a,b)},b(),c(),!0===h.loggerEnabled&&g(console,a),e(),d()},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Logger=function(){this.error=function(a){console.log("ERROR: "+a)},this.warning=function(a){console.log("WARNING: "+a)}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Constants=function(){var a={CONTAINER_CLASS:"easy-autocomplete-container",CONTAINER_ID:"eac-container-",WRAPPER_CSS_CLASS:"easy-autocomplete"};this.getValue=function(b){return a[b]}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.ListBuilderService=function(a,b){function c(b,c){function d(){var d,e={};return void 0!==b.xmlElementName&&(e.xmlElementName=b.xmlElementName),void 0!==b.listLocation?d=b.listLocation:void 0!==a.get("listLocation")&&(d=a.get("listLocation")),void 0!==d?"string"==typeof d?e.data=$(c).find(d):"function"==typeof d&&(e.data=d(c)):e.data=c,e}function e(){var a={};return void 0!==b.listLocation?"string"==typeof b.listLocation?a.data=c[b.listLocation]:"function"==typeof b.listLocation&&(a.data=b.listLocation(c)):a.data=c,a}var f={};if(f="XML"===a.get("dataType").toUpperCase()?d():e(),void 0!==b.header&&(f.header=b.header),void 0!==b.maxNumberOfElements&&(f.maxNumberOfElements=b.maxNumberOfElements),void 0!==a.get("list").maxNumberOfElements&&(f.maxListSize=a.get("list").maxNumberOfElements),void 0!==b.getValue)if("string"==typeof b.getValue){var g=b.getValue;f.getValue=function(a){return a[g]}}else"function"==typeof b.getValue&&(f.getValue=b.getValue);else f.getValue=a.get("getValue");return f}function d(b){var c=[];return void 0===b.xmlElementName&&(b.xmlElementName=a.get("xmlElementName")),$(b.data).find(b.xmlElementName).each(function(){c.push(this)}),c}this.init=function(b){var c=[],d={};return d.data=a.get("listLocation")(b),d.getValue=a.get("getValue"),d.maxListSize=a.get("list").maxNumberOfElements,c.push(d),c},this.updateCategories=function(b,d){return a.get("categoriesAssigned")&&(b=[],$.each(d,function(a,e){var f=c({listLocation:a,maxNumberOfElements:10,header:a.replace(/[_\s]+/g," ")},d);b.push(f)})),b},this.convertXml=function(b){if("XML"===a.get("dataType").toUpperCase())for(var c=0;c0)return!0;return!1}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.proccess=function(b,c,d){function e(a,c){var d=[],e="";if(b.get("list").match.enabled)for(var g=0,h=a.length;gc.maxNumberOfElements&&(a=a.slice(0,c.maxNumberOfElements)),a}function h(a){return b.get("list").sort.enabled&&a.sort(b.get("list").sort.method),a}a.proccess.match=f;var i=c.data;return i=e(i,d),i=g(i),i=h(i)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a},cssClass:""},description:{type:"description",fields:{description:"description"},method:function(a){return a+" - description"},cssClass:"eac-description"},iconLeft:{type:"iconLeft",fields:{icon:""},method:function(a){return a},cssClass:"eac-icon-left"},iconRight:{type:"iconRight",fields:{iconSrc:""},method:function(a){return a},cssClass:"eac-icon-right"},links:{type:"links",fields:{link:""},method:function(a){return a},cssClass:""},custom:{type:"custom",method:function(){},cssClass:""}},c=function(a){var c,d=a.fields;return"description"===a.type?(c=b.description.method,"string"==typeof d.description?c=function(a,b){return a+" - "+b[d.description]+""}:"function"==typeof d.description&&(c=function(a,b){return a+" - "+d.description(b)+""}),c):"iconRight"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return a+""}:"function"==typeof d.iconSrc&&(c=function(a,b){return a+""}),c):"iconLeft"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return""+a}:"function"==typeof d.iconSrc&&(c=function(a,b){return""+a}),c):"links"===a.type?("string"==typeof d.link?c=function(a,b){return""+a+""}:"function"==typeof d.link&&(c=function(a,b){return""+a+""}),c):"custom"===a.type?a.method:b.basic.method},d=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},e=function(a){var c=function(){return""};return a&&a.type&&a.type&&b[a.type]?function(){var c=b[a.type].cssClass;return function(){return c}}():c};this.getTemplateClass=e(a),this.build=d(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return 0===t.length?void p.error("Input field doesn't exist."):o.checkDataUrlProperties()?o.checkRequiredProperties()?(e(),void g()):void p.error("Will not work without mentioned properties."):void p.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
    "),c=n.getValue("WRAPPER_CSS_CLASS");o.get("theme")&&""!==o.get("theme")&&(c+=" eac-"+o.get("theme")),o.get("cssClasses")&&""!==o.get("cssClasses")&&(c+=" "+o.get("cssClasses")),""!==q.getTemplateClass()&&(c+=" "+q.getTemplateClass()),a.addClass(c),t.wrap(a),!0===o.get("adjustWidth")&&b()}function b(){var a=t.outerWidth();t.parent().css("width",a)}function c(){t.unwrap()}function d(){var a=$("
    ").addClass(n.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
      ")),function(){a.on("show.eac",function(){if(t.is(":focus")){switch(o.get("list").showAnimation.type){case"slide":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").fadeIn(b);break;default:a.find("ul").show()}o.get("list").onShowListEvent()}}).on("hide.eac",function(){switch(o.get("list").hideAnimation.type){case"slide":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}o.get("list").onHideListEvent()}).on("selectElement.eac",function(){a.find("ul li").removeClass("selected"),a.find("ul li").eq(w).addClass("selected"),o.get("list").onSelectItemEvent()}).on("loadElements.eac",function(b,c,d){var e="",f=a.find("ul");f.empty().detach(),v=[];for(var h=0,i=0,k=c.length;i0&&f.append("
      "+c[i].header+"
      ");for(var m=0,n=l.length;m
      "),function(){var a=m,b=h,f=c[i].getValue(l[a]);e.find(" > div").on("click",function(){t.val(f).trigger("change"),w=b,j(b),o.get("list").onClickEvent(),o.get("list").onChooseEvent()}).mouseover(function(){w=b,j(b),o.get("list").onMouseOverEvent()}).mouseout(function(){o.get("list").onMouseOutEvent()}).html(q.build(g(f,d),l[a]))}(),f.append(e),v.push(l[m]),h+=1}}a.append(f),o.get("list").onLoadEvent()})}(),t.after(a)}function e(){t.next("."+n.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return o.get("highlightPhrase")&&""!==b?i(a,b):a}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(a,b){var c=h(b);return(a+"").replace(new RegExp("("+c+")","gi"),"$1")}t.parent().hasClass(n.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),u=$("#"+f()),o.get("placeholder")&&t.attr("placeholder",o.get("placeholder"))}function f(){var a=t.attr("id");return a=n.getValue("CONTAINER_ID")+a}function g(){function a(){s("autocompleteOff",!0)&&n(),b(),c(),d(),e(),f(),g()}function b(){t.focusout(function(){var a,b=t.val();o.get("list").match.caseSensitive||(b=b.toLowerCase());for(var c=0,d=v.length;c0?h():i()}var f=b();void 0!==f.url&&""!==f.url||(f.url=o.get("url")),void 0!==f.dataType&&""!==f.dataType||(f.dataType=o.get("dataType")),void 0!==f.url&&"list-required"!==f.url&&(f.url=f.url(a),f.data=o.get("preparePostData")(f.data,a),$.ajax(f).done(function(b){var d=r.init(b);d=r.updateCategories(d,b),d=r.convertXml(d),c(a,b)&&(d=r.processData(d,a),k(d,a)),r.checkIfDataExists(d)&&t.parent().find("li").length>0?h():i(),o.get("ajaxCallback")()}).fail(function(){p.warning("Fail to load response data")}).always(function(){}))}}switch(a.keyCode){case 27:i(),l();break;case 38:a.preventDefault(),v.length>0&&w>0&&(w-=1,t.val(o.get("getValue")(v[w])),j(w));break;case 40:a.preventDefault(),v.length>0&&w40||8===a.keyCode||0===a.keyCode){var c=t.val();!0!==o.get("list").hideOnEmptyPhrase||8!==a.keyCode||""!==c?o.get("requestDelay")>0?(void 0!==m&&clearTimeout(m),m=setTimeout(function(){b(c)},o.get("requestDelay"))):b(c):i()}}})}function d(){t.on("keydown",function(a){if(a=a||window.event,38===a.keyCode)return suppressKeypress=!0,!1}).keydown(function(a){13===a.keyCode&&w>-1&&(t.val(o.get("getValue")(v[w])),o.get("list").onKeyEnterEvent(),o.get("list").onChooseEvent(),w=-1,i(),a.preventDefault())})}function e(){t.off("keypress")}function f(){t.focus(function(){""!==t.val()&&v.length>0&&(w=-1,h())})}function g(){t.blur(function(){setTimeout(function(){w=-1,i()},250)})}function n(){t.attr("autocomplete","off")}a()}function h(){u.trigger("show.eac")}function i(){u.trigger("hide.eac")}function j(a){u.trigger("selectElement.eac",a)}function k(a,b){u.trigger("loadElements.eac",[a,b])}function l(){t.trigger("blur")}var m,n=new a.Constants,o=new a.Configuration(c),p=new a.Logger,q=new a.Template(c.template),r=new a.ListBuilderService(o,a.proccess),s=o.equals,t=b,u="",v=[],w=-1;a.consts=n,this.getConstants=function(){return n},this.getConfiguration=function(){return o},this.getContainer=function(){return u},this.getSelectedItemIndex=function(){return w},this.getItems=function(){return v},this.getItemData=function(a){return v.length0},a.assignRandomId=function(b){var c="";do{c="eac-"+Math.floor(1e4*Math.random())}while(0!==$("#"+c).length);elementId=a.consts.getValue("CONTAINER_ID")+c,$(b).attr("id",c)},a.setHandle=function(b,c){a.eacHandles[c]=b},a}(EasyAutocomplete||{});!function(a){a.fn.easyAutocomplete=function(b){return this.each(function(){var c=a(this),d=new EasyAutocomplete.main(c,b);EasyAutocomplete.inputHasId(c)||EasyAutocomplete.assignRandomId(c),d.init(),EasyAutocomplete.setHandle(d,c.attr("id"))})},a.fn.getSelectedItemIndex=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemIndex():-1},a.fn.getItems=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getItems():-1},a.fn.getItemData=function(b){var c=a(this).attr("id");return void 0!==c&&b>-1?EasyAutocomplete.getHandle(c).getItemData(b):-1},a.fn.getSelectedItemData=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemData():-1}}(jQuery); \ No newline at end of file diff --git a/dist/maps/easy-autocomplete.css.map b/dist/maps/easy-autocomplete.css.map index ffb2187..9c7fbd9 100644 --- a/dist/maps/easy-autocomplete.css.map +++ b/dist/maps/easy-autocomplete.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.0 + * @version 1.4.1 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.min.css.map b/dist/maps/easy-autocomplete.min.css.map index dc55a5b..9768450 100644 --- a/dist/maps/easy-autocomplete.min.css.map +++ b/dist/maps/easy-autocomplete.min.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.0 + * @version 1.4.1 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.themes.css.map b/dist/maps/easy-autocomplete.themes.css.map index d4e1212..a898b46 100644 --- a/dist/maps/easy-autocomplete.themes.css.map +++ b/dist/maps/easy-autocomplete.themes.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.0 + * @version 1.4.1 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.themes.min.css.map b/dist/maps/easy-autocomplete.themes.min.css.map index 100110d..143729c 100644 --- a/dist/maps/easy-autocomplete.themes.min.css.map +++ b/dist/maps/easy-autocomplete.themes.min.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.0 + * @version 1.4.1 * Copyright License: */ diff --git a/package.json b/package.json index 03b1316..d5d97b3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "easy-autocomplete", "title": "jQuery plugin for autocompletion", "author": "Łukasz Pawełczak (http://github.com/pawelczak)", - "version": "1.4.0", + "version": "1.4.1", "keywords": [ "jquery", "jquery-plugin", diff --git a/src/list.builder.js b/src/list.builder.js index 9525770..48cc9b1 100644 --- a/src/list.builder.js +++ b/src/list.builder.js @@ -1,7 +1,7 @@ /* - * EasyAutocomplete - ListBuilderService + * EasyAutocomplete - ListBuilderService * - * @author Łukasz Pawełczak + * @author Łukasz Pawełczak * */ var EasyAutocomplete = (function (scope) { @@ -23,23 +23,23 @@ var EasyAutocomplete = (function (scope) { return listBuilder; }; - this.updateCategories = function (listBuilder, data) { + this.updateCategories = function(listBuilder, data) { + if (configuration.get("categoriesAssigned")) { + listBuilder = []; - if (configuration.get('categoriesAssigned')) { + $.each(data, function( index, value ) { + var builder = convertToListBuilder({ + listLocation: index, + maxNumberOfElements: 10, + header: index.replace(/[_\s]+/g, ' ') + }, data); - listBuilder = []; + listBuilder.push(builder); + }); + } - for (var i = 0; i < configuration.get("categories").length; i += 1) { - - var builder = convertToListBuilder(configuration.get('categories')[i], data); - - listBuilder.push(builder); - } - - } - - return listBuilder; - }; + return listBuilder; + }; this.convertXml = function (listBuilder) { if (configuration.get('dataType').toUpperCase() === 'XML') { From b5c1b83b037da8fb7c7d97ebc235d3f0b23f81f8 Mon Sep 17 00:00:00 2001 From: Mai Abuthraa Date: Tue, 25 May 2021 14:23:11 +0300 Subject: [PATCH 2/5] DC-7463: Keep the old functionality --- dist/easy-autocomplete.css | 2 +- dist/easy-autocomplete.min.css | 2 +- dist/easy-autocomplete.themes.css | 2 +- dist/easy-autocomplete.themes.min.css | 2 +- dist/jquery.easy-autocomplete.js | 34 +++++++++++++------ dist/jquery.easy-autocomplete.min.js | 4 +-- dist/maps/easy-autocomplete.css.map | 2 +- dist/maps/easy-autocomplete.min.css.map | 2 +- dist/maps/easy-autocomplete.themes.css.map | 2 +- .../maps/easy-autocomplete.themes.min.css.map | 2 +- package.json | 2 +- src/configuration.js | 6 +++- src/list.builder.js | 26 +++++++++----- 13 files changed, 58 insertions(+), 30 deletions(-) diff --git a/dist/easy-autocomplete.css b/dist/easy-autocomplete.css index a69fb67..510a3e4 100644 --- a/dist/easy-autocomplete.css +++ b/dist/easy-autocomplete.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.1 + * @version 1.4.2 * Copyright License: */ diff --git a/dist/easy-autocomplete.min.css b/dist/easy-autocomplete.min.css index 7c1cfe2..18447fd 100644 --- a/dist/easy-autocomplete.min.css +++ b/dist/easy-autocomplete.min.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.1 + * @version 1.4.2 * Copyright License: */ diff --git a/dist/easy-autocomplete.themes.css b/dist/easy-autocomplete.themes.css index a4957c5..ec0c4f8 100644 --- a/dist/easy-autocomplete.themes.css +++ b/dist/easy-autocomplete.themes.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.1 + * @version 1.4.2 * Copyright License: */ diff --git a/dist/easy-autocomplete.themes.min.css b/dist/easy-autocomplete.themes.min.css index 9a224ca..2cc5265 100644 --- a/dist/easy-autocomplete.themes.min.css +++ b/dist/easy-autocomplete.themes.min.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.1 + * @version 1.4.2 * Copyright License: */ diff --git a/dist/jquery.easy-autocomplete.js b/dist/jquery.easy-autocomplete.js index 905f8af..9d0f769 100644 --- a/dist/jquery.easy-autocomplete.js +++ b/dist/jquery.easy-autocomplete.js @@ -3,12 +3,12 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.1 + * @version 1.4.2 * Copyright License: */ /* - * EasyAutocomplete - Configuration + * EasyAutocomplete - Configuration */ var EasyAutocomplete = (function (scope) { @@ -133,6 +133,10 @@ var EasyAutocomplete = (function (scope) { var externalObjects = ['ajaxSettings', 'template']; + this.getOptions = function (propertyName) { + return options[propertyName]; + }; + this.get = function (propertyName) { return defaults[propertyName]; }; @@ -420,17 +424,27 @@ var EasyAutocomplete = (function (scope) { this.updateCategories = function(listBuilder, data) { if (configuration.get("categoriesAssigned")) { + listBuilder = []; - $.each(data, function( index, value ) { - var builder = convertToListBuilder({ - listLocation: index, - maxNumberOfElements: 10, - header: index.replace(/[_\s]+/g, ' ') - }, data); + if (configuration.getOptions('categories') !== undefined) { + for (var i = 0; i < configuration.get("categories").length; i += 1) { + + var builder = convertToListBuilder(configuration.get('categories')[i], data); + + listBuilder.push(builder); + } + } else { + $.each(data, function( index, value ) { + var builder = convertToListBuilder({ + listLocation: index, + maxNumberOfElements: 10, + header: index.replace(/[_\s]+/g, ' ') + }, data); - listBuilder.push(builder); - }); + listBuilder.push(builder); + }); + } } return listBuilder; diff --git a/dist/jquery.easy-autocomplete.min.js b/dist/jquery.easy-autocomplete.min.js index 5d93987..570df1e 100644 --- a/dist/jquery.easy-autocomplete.min.js +++ b/dist/jquery.easy-autocomplete.min.js @@ -3,8 +3,8 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.1 + * @version 1.4.2 * Copyright License: */ -var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){if("xml"===a.dataType&&(a.getValue||(a.getValue=function(a){return $(a).text()}),a.list||(a.list={}),a.list.sort||(a.list.sort={}),a.list.sort.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),bc?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(a,b){return a.search(b)>-1}),void 0!==a.categories&&a.categories instanceof Array){for(var b=[],c=0,d=a.categories.length;cb?1:0}},maxNumberOfElements:6,hideOnEmptyPhrase:!0,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a.search(b)>-1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onChooseEvent:function(){},onKeyEnterEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){},onShowListEvent:function(){},onHideListEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,requestDelay:0,adjustWidth:!0,ajaxSettings:{},preparePostData:function(a,b){return a},loggerEnabled:!0,template:"",categoriesAssigned:!1,categories:[{maxNumberOfElements:4}]},i=["ajaxSettings","template"];this.get=function(a){return h[a]},this.equals=function(a,b){return!(!f(a)||h[a]!==b)},this.checkDataUrlProperties=function(){return!("list-required"===h.url&&"list-required"===h.data)},this.checkRequiredProperties=function(){for(var a in h)if("required"===h[a])return logger.error("Option "+a+" must be defined"),!1;return!0},this.printPropertiesThatDoesntExist=function(a,b){g(a,b)},b(),c(),!0===h.loggerEnabled&&g(console,a),e(),d()},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Logger=function(){this.error=function(a){console.log("ERROR: "+a)},this.warning=function(a){console.log("WARNING: "+a)}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Constants=function(){var a={CONTAINER_CLASS:"easy-autocomplete-container",CONTAINER_ID:"eac-container-",WRAPPER_CSS_CLASS:"easy-autocomplete"};this.getValue=function(b){return a[b]}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.ListBuilderService=function(a,b){function c(b,c){function d(){var d,e={};return void 0!==b.xmlElementName&&(e.xmlElementName=b.xmlElementName),void 0!==b.listLocation?d=b.listLocation:void 0!==a.get("listLocation")&&(d=a.get("listLocation")),void 0!==d?"string"==typeof d?e.data=$(c).find(d):"function"==typeof d&&(e.data=d(c)):e.data=c,e}function e(){var a={};return void 0!==b.listLocation?"string"==typeof b.listLocation?a.data=c[b.listLocation]:"function"==typeof b.listLocation&&(a.data=b.listLocation(c)):a.data=c,a}var f={};if(f="XML"===a.get("dataType").toUpperCase()?d():e(),void 0!==b.header&&(f.header=b.header),void 0!==b.maxNumberOfElements&&(f.maxNumberOfElements=b.maxNumberOfElements),void 0!==a.get("list").maxNumberOfElements&&(f.maxListSize=a.get("list").maxNumberOfElements),void 0!==b.getValue)if("string"==typeof b.getValue){var g=b.getValue;f.getValue=function(a){return a[g]}}else"function"==typeof b.getValue&&(f.getValue=b.getValue);else f.getValue=a.get("getValue");return f}function d(b){var c=[];return void 0===b.xmlElementName&&(b.xmlElementName=a.get("xmlElementName")),$(b.data).find(b.xmlElementName).each(function(){c.push(this)}),c}this.init=function(b){var c=[],d={};return d.data=a.get("listLocation")(b),d.getValue=a.get("getValue"),d.maxListSize=a.get("list").maxNumberOfElements,c.push(d),c},this.updateCategories=function(b,d){return a.get("categoriesAssigned")&&(b=[],$.each(d,function(a,e){var f=c({listLocation:a,maxNumberOfElements:10,header:a.replace(/[_\s]+/g," ")},d);b.push(f)})),b},this.convertXml=function(b){if("XML"===a.get("dataType").toUpperCase())for(var c=0;c0)return!0;return!1}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.proccess=function(b,c,d){function e(a,c){var d=[],e="";if(b.get("list").match.enabled)for(var g=0,h=a.length;gc.maxNumberOfElements&&(a=a.slice(0,c.maxNumberOfElements)),a}function h(a){return b.get("list").sort.enabled&&a.sort(b.get("list").sort.method),a}a.proccess.match=f;var i=c.data;return i=e(i,d),i=g(i),i=h(i)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a},cssClass:""},description:{type:"description",fields:{description:"description"},method:function(a){return a+" - description"},cssClass:"eac-description"},iconLeft:{type:"iconLeft",fields:{icon:""},method:function(a){return a},cssClass:"eac-icon-left"},iconRight:{type:"iconRight",fields:{iconSrc:""},method:function(a){return a},cssClass:"eac-icon-right"},links:{type:"links",fields:{link:""},method:function(a){return a},cssClass:""},custom:{type:"custom",method:function(){},cssClass:""}},c=function(a){var c,d=a.fields;return"description"===a.type?(c=b.description.method,"string"==typeof d.description?c=function(a,b){return a+" - "+b[d.description]+""}:"function"==typeof d.description&&(c=function(a,b){return a+" - "+d.description(b)+""}),c):"iconRight"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return a+""}:"function"==typeof d.iconSrc&&(c=function(a,b){return a+""}),c):"iconLeft"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return""+a}:"function"==typeof d.iconSrc&&(c=function(a,b){return""+a}),c):"links"===a.type?("string"==typeof d.link?c=function(a,b){return""+a+""}:"function"==typeof d.link&&(c=function(a,b){return""+a+""}),c):"custom"===a.type?a.method:b.basic.method},d=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},e=function(a){var c=function(){return""};return a&&a.type&&a.type&&b[a.type]?function(){var c=b[a.type].cssClass;return function(){return c}}():c};this.getTemplateClass=e(a),this.build=d(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return 0===t.length?void p.error("Input field doesn't exist."):o.checkDataUrlProperties()?o.checkRequiredProperties()?(e(),void g()):void p.error("Will not work without mentioned properties."):void p.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
      "),c=n.getValue("WRAPPER_CSS_CLASS");o.get("theme")&&""!==o.get("theme")&&(c+=" eac-"+o.get("theme")),o.get("cssClasses")&&""!==o.get("cssClasses")&&(c+=" "+o.get("cssClasses")),""!==q.getTemplateClass()&&(c+=" "+q.getTemplateClass()),a.addClass(c),t.wrap(a),!0===o.get("adjustWidth")&&b()}function b(){var a=t.outerWidth();t.parent().css("width",a)}function c(){t.unwrap()}function d(){var a=$("
      ").addClass(n.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
        ")),function(){a.on("show.eac",function(){if(t.is(":focus")){switch(o.get("list").showAnimation.type){case"slide":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").fadeIn(b);break;default:a.find("ul").show()}o.get("list").onShowListEvent()}}).on("hide.eac",function(){switch(o.get("list").hideAnimation.type){case"slide":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}o.get("list").onHideListEvent()}).on("selectElement.eac",function(){a.find("ul li").removeClass("selected"),a.find("ul li").eq(w).addClass("selected"),o.get("list").onSelectItemEvent()}).on("loadElements.eac",function(b,c,d){var e="",f=a.find("ul");f.empty().detach(),v=[];for(var h=0,i=0,k=c.length;i0&&f.append("
        "+c[i].header+"
        ");for(var m=0,n=l.length;m
        "),function(){var a=m,b=h,f=c[i].getValue(l[a]);e.find(" > div").on("click",function(){t.val(f).trigger("change"),w=b,j(b),o.get("list").onClickEvent(),o.get("list").onChooseEvent()}).mouseover(function(){w=b,j(b),o.get("list").onMouseOverEvent()}).mouseout(function(){o.get("list").onMouseOutEvent()}).html(q.build(g(f,d),l[a]))}(),f.append(e),v.push(l[m]),h+=1}}a.append(f),o.get("list").onLoadEvent()})}(),t.after(a)}function e(){t.next("."+n.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return o.get("highlightPhrase")&&""!==b?i(a,b):a}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(a,b){var c=h(b);return(a+"").replace(new RegExp("("+c+")","gi"),"$1")}t.parent().hasClass(n.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),u=$("#"+f()),o.get("placeholder")&&t.attr("placeholder",o.get("placeholder"))}function f(){var a=t.attr("id");return a=n.getValue("CONTAINER_ID")+a}function g(){function a(){s("autocompleteOff",!0)&&n(),b(),c(),d(),e(),f(),g()}function b(){t.focusout(function(){var a,b=t.val();o.get("list").match.caseSensitive||(b=b.toLowerCase());for(var c=0,d=v.length;c0?h():i()}var f=b();void 0!==f.url&&""!==f.url||(f.url=o.get("url")),void 0!==f.dataType&&""!==f.dataType||(f.dataType=o.get("dataType")),void 0!==f.url&&"list-required"!==f.url&&(f.url=f.url(a),f.data=o.get("preparePostData")(f.data,a),$.ajax(f).done(function(b){var d=r.init(b);d=r.updateCategories(d,b),d=r.convertXml(d),c(a,b)&&(d=r.processData(d,a),k(d,a)),r.checkIfDataExists(d)&&t.parent().find("li").length>0?h():i(),o.get("ajaxCallback")()}).fail(function(){p.warning("Fail to load response data")}).always(function(){}))}}switch(a.keyCode){case 27:i(),l();break;case 38:a.preventDefault(),v.length>0&&w>0&&(w-=1,t.val(o.get("getValue")(v[w])),j(w));break;case 40:a.preventDefault(),v.length>0&&w40||8===a.keyCode||0===a.keyCode){var c=t.val();!0!==o.get("list").hideOnEmptyPhrase||8!==a.keyCode||""!==c?o.get("requestDelay")>0?(void 0!==m&&clearTimeout(m),m=setTimeout(function(){b(c)},o.get("requestDelay"))):b(c):i()}}})}function d(){t.on("keydown",function(a){if(a=a||window.event,38===a.keyCode)return suppressKeypress=!0,!1}).keydown(function(a){13===a.keyCode&&w>-1&&(t.val(o.get("getValue")(v[w])),o.get("list").onKeyEnterEvent(),o.get("list").onChooseEvent(),w=-1,i(),a.preventDefault())})}function e(){t.off("keypress")}function f(){t.focus(function(){""!==t.val()&&v.length>0&&(w=-1,h())})}function g(){t.blur(function(){setTimeout(function(){w=-1,i()},250)})}function n(){t.attr("autocomplete","off")}a()}function h(){u.trigger("show.eac")}function i(){u.trigger("hide.eac")}function j(a){u.trigger("selectElement.eac",a)}function k(a,b){u.trigger("loadElements.eac",[a,b])}function l(){t.trigger("blur")}var m,n=new a.Constants,o=new a.Configuration(c),p=new a.Logger,q=new a.Template(c.template),r=new a.ListBuilderService(o,a.proccess),s=o.equals,t=b,u="",v=[],w=-1;a.consts=n,this.getConstants=function(){return n},this.getConfiguration=function(){return o},this.getContainer=function(){return u},this.getSelectedItemIndex=function(){return w},this.getItems=function(){return v},this.getItemData=function(a){return v.length0},a.assignRandomId=function(b){var c="";do{c="eac-"+Math.floor(1e4*Math.random())}while(0!==$("#"+c).length);elementId=a.consts.getValue("CONTAINER_ID")+c,$(b).attr("id",c)},a.setHandle=function(b,c){a.eacHandles[c]=b},a}(EasyAutocomplete||{});!function(a){a.fn.easyAutocomplete=function(b){return this.each(function(){var c=a(this),d=new EasyAutocomplete.main(c,b);EasyAutocomplete.inputHasId(c)||EasyAutocomplete.assignRandomId(c),d.init(),EasyAutocomplete.setHandle(d,c.attr("id"))})},a.fn.getSelectedItemIndex=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemIndex():-1},a.fn.getItems=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getItems():-1},a.fn.getItemData=function(b){var c=a(this).attr("id");return void 0!==c&&b>-1?EasyAutocomplete.getHandle(c).getItemData(b):-1},a.fn.getSelectedItemData=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemData():-1}}(jQuery); \ No newline at end of file +var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){if("xml"===a.dataType&&(a.getValue||(a.getValue=function(a){return $(a).text()}),a.list||(a.list={}),a.list.sort||(a.list.sort={}),a.list.sort.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),bc?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(a,b){return a.search(b)>-1}),void 0!==a.categories&&a.categories instanceof Array){for(var b=[],c=0,d=a.categories.length;cb?1:0}},maxNumberOfElements:6,hideOnEmptyPhrase:!0,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a.search(b)>-1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onChooseEvent:function(){},onKeyEnterEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){},onShowListEvent:function(){},onHideListEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,requestDelay:0,adjustWidth:!0,ajaxSettings:{},preparePostData:function(a,b){return a},loggerEnabled:!0,template:"",categoriesAssigned:!1,categories:[{maxNumberOfElements:4}]},i=["ajaxSettings","template"];this.getOptions=function(b){return a[b]},this.get=function(a){return h[a]},this.equals=function(a,b){return!(!f(a)||h[a]!==b)},this.checkDataUrlProperties=function(){return!("list-required"===h.url&&"list-required"===h.data)},this.checkRequiredProperties=function(){for(var a in h)if("required"===h[a])return logger.error("Option "+a+" must be defined"),!1;return!0},this.printPropertiesThatDoesntExist=function(a,b){g(a,b)},b(),c(),!0===h.loggerEnabled&&g(console,a),e(),d()},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Logger=function(){this.error=function(a){console.log("ERROR: "+a)},this.warning=function(a){console.log("WARNING: "+a)}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Constants=function(){var a={CONTAINER_CLASS:"easy-autocomplete-container",CONTAINER_ID:"eac-container-",WRAPPER_CSS_CLASS:"easy-autocomplete"};this.getValue=function(b){return a[b]}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.ListBuilderService=function(a,b){function c(b,c){function d(){var d,e={};return void 0!==b.xmlElementName&&(e.xmlElementName=b.xmlElementName),void 0!==b.listLocation?d=b.listLocation:void 0!==a.get("listLocation")&&(d=a.get("listLocation")),void 0!==d?"string"==typeof d?e.data=$(c).find(d):"function"==typeof d&&(e.data=d(c)):e.data=c,e}function e(){var a={};return void 0!==b.listLocation?"string"==typeof b.listLocation?a.data=c[b.listLocation]:"function"==typeof b.listLocation&&(a.data=b.listLocation(c)):a.data=c,a}var f={};if(f="XML"===a.get("dataType").toUpperCase()?d():e(),void 0!==b.header&&(f.header=b.header),void 0!==b.maxNumberOfElements&&(f.maxNumberOfElements=b.maxNumberOfElements),void 0!==a.get("list").maxNumberOfElements&&(f.maxListSize=a.get("list").maxNumberOfElements),void 0!==b.getValue)if("string"==typeof b.getValue){var g=b.getValue;f.getValue=function(a){return a[g]}}else"function"==typeof b.getValue&&(f.getValue=b.getValue);else f.getValue=a.get("getValue");return f}function d(b){var c=[];return void 0===b.xmlElementName&&(b.xmlElementName=a.get("xmlElementName")),$(b.data).find(b.xmlElementName).each(function(){c.push(this)}),c}this.init=function(b){var c=[],d={};return d.data=a.get("listLocation")(b),d.getValue=a.get("getValue"),d.maxListSize=a.get("list").maxNumberOfElements,c.push(d),c},this.updateCategories=function(b,d){if(a.get("categoriesAssigned"))if(b=[],void 0!==a.getOptions("categories"))for(var e=0;e0)return!0;return!1}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.proccess=function(b,c,d){function e(a,c){var d=[],e="";if(b.get("list").match.enabled)for(var g=0,h=a.length;gc.maxNumberOfElements&&(a=a.slice(0,c.maxNumberOfElements)),a}function h(a){return b.get("list").sort.enabled&&a.sort(b.get("list").sort.method),a}a.proccess.match=f;var i=c.data;return i=e(i,d),i=g(i),i=h(i)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a},cssClass:""},description:{type:"description",fields:{description:"description"},method:function(a){return a+" - description"},cssClass:"eac-description"},iconLeft:{type:"iconLeft",fields:{icon:""},method:function(a){return a},cssClass:"eac-icon-left"},iconRight:{type:"iconRight",fields:{iconSrc:""},method:function(a){return a},cssClass:"eac-icon-right"},links:{type:"links",fields:{link:""},method:function(a){return a},cssClass:""},custom:{type:"custom",method:function(){},cssClass:""}},c=function(a){var c,d=a.fields;return"description"===a.type?(c=b.description.method,"string"==typeof d.description?c=function(a,b){return a+" - "+b[d.description]+""}:"function"==typeof d.description&&(c=function(a,b){return a+" - "+d.description(b)+""}),c):"iconRight"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return a+""}:"function"==typeof d.iconSrc&&(c=function(a,b){return a+""}),c):"iconLeft"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return""+a}:"function"==typeof d.iconSrc&&(c=function(a,b){return""+a}),c):"links"===a.type?("string"==typeof d.link?c=function(a,b){return""+a+""}:"function"==typeof d.link&&(c=function(a,b){return""+a+""}),c):"custom"===a.type?a.method:b.basic.method},d=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},e=function(a){var c=function(){return""};return a&&a.type&&a.type&&b[a.type]?function(){var c=b[a.type].cssClass;return function(){return c}}():c};this.getTemplateClass=e(a),this.build=d(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return 0===t.length?void p.error("Input field doesn't exist."):o.checkDataUrlProperties()?o.checkRequiredProperties()?(e(),void g()):void p.error("Will not work without mentioned properties."):void p.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
        "),c=n.getValue("WRAPPER_CSS_CLASS");o.get("theme")&&""!==o.get("theme")&&(c+=" eac-"+o.get("theme")),o.get("cssClasses")&&""!==o.get("cssClasses")&&(c+=" "+o.get("cssClasses")),""!==q.getTemplateClass()&&(c+=" "+q.getTemplateClass()),a.addClass(c),t.wrap(a),!0===o.get("adjustWidth")&&b()}function b(){var a=t.outerWidth();t.parent().css("width",a)}function c(){t.unwrap()}function d(){var a=$("
        ").addClass(n.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
          ")),function(){a.on("show.eac",function(){if(t.is(":focus")){switch(o.get("list").showAnimation.type){case"slide":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").fadeIn(b);break;default:a.find("ul").show()}o.get("list").onShowListEvent()}}).on("hide.eac",function(){switch(o.get("list").hideAnimation.type){case"slide":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}o.get("list").onHideListEvent()}).on("selectElement.eac",function(){a.find("ul li").removeClass("selected"),a.find("ul li").eq(w).addClass("selected"),o.get("list").onSelectItemEvent()}).on("loadElements.eac",function(b,c,d){var e="",f=a.find("ul");f.empty().detach(),v=[];for(var h=0,i=0,k=c.length;i0&&f.append("
          "+c[i].header+"
          ");for(var m=0,n=l.length;m
          "),function(){var a=m,b=h,f=c[i].getValue(l[a]);e.find(" > div").on("click",function(){t.val(f).trigger("change"),w=b,j(b),o.get("list").onClickEvent(),o.get("list").onChooseEvent()}).mouseover(function(){w=b,j(b),o.get("list").onMouseOverEvent()}).mouseout(function(){o.get("list").onMouseOutEvent()}).html(q.build(g(f,d),l[a]))}(),f.append(e),v.push(l[m]),h+=1}}a.append(f),o.get("list").onLoadEvent()})}(),t.after(a)}function e(){t.next("."+n.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return o.get("highlightPhrase")&&""!==b?i(a,b):a}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(a,b){var c=h(b);return(a+"").replace(new RegExp("("+c+")","gi"),"$1")}t.parent().hasClass(n.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),u=$("#"+f()),o.get("placeholder")&&t.attr("placeholder",o.get("placeholder"))}function f(){var a=t.attr("id");return a=n.getValue("CONTAINER_ID")+a}function g(){function a(){s("autocompleteOff",!0)&&n(),b(),c(),d(),e(),f(),g()}function b(){t.focusout(function(){var a,b=t.val();o.get("list").match.caseSensitive||(b=b.toLowerCase());for(var c=0,d=v.length;c0?h():i()}var f=b();void 0!==f.url&&""!==f.url||(f.url=o.get("url")),void 0!==f.dataType&&""!==f.dataType||(f.dataType=o.get("dataType")),void 0!==f.url&&"list-required"!==f.url&&(f.url=f.url(a),f.data=o.get("preparePostData")(f.data,a),$.ajax(f).done(function(b){var d=r.init(b);d=r.updateCategories(d,b),d=r.convertXml(d),c(a,b)&&(d=r.processData(d,a),k(d,a)),r.checkIfDataExists(d)&&t.parent().find("li").length>0?h():i(),o.get("ajaxCallback")()}).fail(function(){p.warning("Fail to load response data")}).always(function(){}))}}switch(a.keyCode){case 27:i(),l();break;case 38:a.preventDefault(),v.length>0&&w>0&&(w-=1,t.val(o.get("getValue")(v[w])),j(w));break;case 40:a.preventDefault(),v.length>0&&w40||8===a.keyCode||0===a.keyCode){var c=t.val();!0!==o.get("list").hideOnEmptyPhrase||8!==a.keyCode||""!==c?o.get("requestDelay")>0?(void 0!==m&&clearTimeout(m),m=setTimeout(function(){b(c)},o.get("requestDelay"))):b(c):i()}}})}function d(){t.on("keydown",function(a){if(a=a||window.event,38===a.keyCode)return suppressKeypress=!0,!1}).keydown(function(a){13===a.keyCode&&w>-1&&(t.val(o.get("getValue")(v[w])),o.get("list").onKeyEnterEvent(),o.get("list").onChooseEvent(),w=-1,i(),a.preventDefault())})}function e(){t.off("keypress")}function f(){t.focus(function(){""!==t.val()&&v.length>0&&(w=-1,h())})}function g(){t.blur(function(){setTimeout(function(){w=-1,i()},250)})}function n(){t.attr("autocomplete","off")}a()}function h(){u.trigger("show.eac")}function i(){u.trigger("hide.eac")}function j(a){u.trigger("selectElement.eac",a)}function k(a,b){u.trigger("loadElements.eac",[a,b])}function l(){t.trigger("blur")}var m,n=new a.Constants,o=new a.Configuration(c),p=new a.Logger,q=new a.Template(c.template),r=new a.ListBuilderService(o,a.proccess),s=o.equals,t=b,u="",v=[],w=-1;a.consts=n,this.getConstants=function(){return n},this.getConfiguration=function(){return o},this.getContainer=function(){return u},this.getSelectedItemIndex=function(){return w},this.getItems=function(){return v},this.getItemData=function(a){return v.length0},a.assignRandomId=function(b){var c="";do{c="eac-"+Math.floor(1e4*Math.random())}while(0!==$("#"+c).length);elementId=a.consts.getValue("CONTAINER_ID")+c,$(b).attr("id",c)},a.setHandle=function(b,c){a.eacHandles[c]=b},a}(EasyAutocomplete||{});!function(a){a.fn.easyAutocomplete=function(b){return this.each(function(){var c=a(this),d=new EasyAutocomplete.main(c,b);EasyAutocomplete.inputHasId(c)||EasyAutocomplete.assignRandomId(c),d.init(),EasyAutocomplete.setHandle(d,c.attr("id"))})},a.fn.getSelectedItemIndex=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemIndex():-1},a.fn.getItems=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getItems():-1},a.fn.getItemData=function(b){var c=a(this).attr("id");return void 0!==c&&b>-1?EasyAutocomplete.getHandle(c).getItemData(b):-1},a.fn.getSelectedItemData=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemData():-1}}(jQuery); \ No newline at end of file diff --git a/dist/maps/easy-autocomplete.css.map b/dist/maps/easy-autocomplete.css.map index 9c7fbd9..0900da0 100644 --- a/dist/maps/easy-autocomplete.css.map +++ b/dist/maps/easy-autocomplete.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.1 + * @version 1.4.2 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.min.css.map b/dist/maps/easy-autocomplete.min.css.map index 9768450..2a824d1 100644 --- a/dist/maps/easy-autocomplete.min.css.map +++ b/dist/maps/easy-autocomplete.min.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.1 + * @version 1.4.2 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.themes.css.map b/dist/maps/easy-autocomplete.themes.css.map index a898b46..7f482be 100644 --- a/dist/maps/easy-autocomplete.themes.css.map +++ b/dist/maps/easy-autocomplete.themes.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.1 + * @version 1.4.2 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.themes.min.css.map b/dist/maps/easy-autocomplete.themes.min.css.map index 143729c..3eb9240 100644 --- a/dist/maps/easy-autocomplete.themes.min.css.map +++ b/dist/maps/easy-autocomplete.themes.min.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.1 + * @version 1.4.2 * Copyright License: */ diff --git a/package.json b/package.json index d5d97b3..c20d655 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "easy-autocomplete", "title": "jQuery plugin for autocompletion", "author": "Łukasz Pawełczak (http://github.com/pawelczak)", - "version": "1.4.1", + "version": "1.4.2", "keywords": [ "jquery", "jquery-plugin", diff --git a/src/configuration.js b/src/configuration.js index 3b6334b..19f2f8f 100644 --- a/src/configuration.js +++ b/src/configuration.js @@ -1,5 +1,5 @@ /* - * EasyAutocomplete - Configuration + * EasyAutocomplete - Configuration */ var EasyAutocomplete = (function (scope) { @@ -127,6 +127,10 @@ var EasyAutocomplete = (function (scope) { var externalObjects = ['ajaxSettings', 'template']; + this.getOptions = function (propertyName) { + return options[propertyName]; + }; + this.get = function (propertyName) { return defaults[propertyName]; }; diff --git a/src/list.builder.js b/src/list.builder.js index 48cc9b1..93d8b9c 100644 --- a/src/list.builder.js +++ b/src/list.builder.js @@ -25,17 +25,27 @@ var EasyAutocomplete = (function (scope) { this.updateCategories = function(listBuilder, data) { if (configuration.get("categoriesAssigned")) { + listBuilder = []; - $.each(data, function( index, value ) { - var builder = convertToListBuilder({ - listLocation: index, - maxNumberOfElements: 10, - header: index.replace(/[_\s]+/g, ' ') - }, data); + if (configuration.getOptions('categories') !== undefined) { + for (var i = 0; i < configuration.get("categories").length; i += 1) { + + var builder = convertToListBuilder(configuration.get('categories')[i], data); + + listBuilder.push(builder); + } + } else { + $.each(data, function( index, value ) { + var builder = convertToListBuilder({ + listLocation: index, + maxNumberOfElements: 10, + header: index.replace(/[_\s]+/g, ' ') + }, data); - listBuilder.push(builder); - }); + listBuilder.push(builder); + }); + } } return listBuilder; From 6fc223d2b0d131f769e45322cc6cb85bedd2670d Mon Sep 17 00:00:00 2001 From: Mai Abuthraa Date: Tue, 25 May 2021 16:36:43 +0300 Subject: [PATCH 3/5] DC-7463: Remove the default value for categories --- dist/easy-autocomplete.css | 2 +- dist/easy-autocomplete.min.css | 2 +- dist/easy-autocomplete.themes.css | 2 +- dist/easy-autocomplete.themes.min.css | 2 +- dist/jquery.easy-autocomplete.js | 26 +++++++------------ dist/jquery.easy-autocomplete.min.js | 4 +-- dist/maps/easy-autocomplete.css.map | 2 +- dist/maps/easy-autocomplete.min.css.map | 2 +- dist/maps/easy-autocomplete.themes.css.map | 2 +- .../maps/easy-autocomplete.themes.min.css.map | 2 +- package.json | 2 +- src/configuration.js | 9 +------ src/list.builder.js | 16 ++++++------ test/configuration.js | 4 +-- 14 files changed, 31 insertions(+), 46 deletions(-) diff --git a/dist/easy-autocomplete.css b/dist/easy-autocomplete.css index 510a3e4..3c6dd3f 100644 --- a/dist/easy-autocomplete.css +++ b/dist/easy-autocomplete.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.2 + * @version 1.4.3 * Copyright License: */ diff --git a/dist/easy-autocomplete.min.css b/dist/easy-autocomplete.min.css index 18447fd..435079d 100644 --- a/dist/easy-autocomplete.min.css +++ b/dist/easy-autocomplete.min.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.2 + * @version 1.4.3 * Copyright License: */ diff --git a/dist/easy-autocomplete.themes.css b/dist/easy-autocomplete.themes.css index ec0c4f8..c2928df 100644 --- a/dist/easy-autocomplete.themes.css +++ b/dist/easy-autocomplete.themes.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.2 + * @version 1.4.3 * Copyright License: */ diff --git a/dist/easy-autocomplete.themes.min.css b/dist/easy-autocomplete.themes.min.css index 2cc5265..2f0584f 100644 --- a/dist/easy-autocomplete.themes.min.css +++ b/dist/easy-autocomplete.themes.min.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.2 + * @version 1.4.3 * Copyright License: */ diff --git a/dist/jquery.easy-autocomplete.js b/dist/jquery.easy-autocomplete.js index 9d0f769..8ccae16 100644 --- a/dist/jquery.easy-autocomplete.js +++ b/dist/jquery.easy-autocomplete.js @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.2 + * @version 1.4.3 * Copyright License: */ @@ -125,18 +125,12 @@ var EasyAutocomplete = (function (scope) { categoriesAssigned: false, - categories: [{ - maxNumberOfElements: 4 - }] + categories: [] }; var externalObjects = ['ajaxSettings', 'template']; - this.getOptions = function (propertyName) { - return options[propertyName]; - }; - this.get = function (propertyName) { return defaults[propertyName]; }; @@ -427,14 +421,7 @@ var EasyAutocomplete = (function (scope) { listBuilder = []; - if (configuration.getOptions('categories') !== undefined) { - for (var i = 0; i < configuration.get("categories").length; i += 1) { - - var builder = convertToListBuilder(configuration.get('categories')[i], data); - - listBuilder.push(builder); - } - } else { + if (configuration.get('categories').length == 0) { $.each(data, function( index, value ) { var builder = convertToListBuilder({ listLocation: index, @@ -444,6 +431,13 @@ var EasyAutocomplete = (function (scope) { listBuilder.push(builder); }); + } else { + for (var i = 0; i < configuration.get("categories").length; i += 1) { + + var builder = convertToListBuilder(configuration.get('categories')[i], data); + + listBuilder.push(builder); + } } } diff --git a/dist/jquery.easy-autocomplete.min.js b/dist/jquery.easy-autocomplete.min.js index 570df1e..3ce9afb 100644 --- a/dist/jquery.easy-autocomplete.min.js +++ b/dist/jquery.easy-autocomplete.min.js @@ -3,8 +3,8 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.2 + * @version 1.4.3 * Copyright License: */ -var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){if("xml"===a.dataType&&(a.getValue||(a.getValue=function(a){return $(a).text()}),a.list||(a.list={}),a.list.sort||(a.list.sort={}),a.list.sort.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),bc?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(a,b){return a.search(b)>-1}),void 0!==a.categories&&a.categories instanceof Array){for(var b=[],c=0,d=a.categories.length;cb?1:0}},maxNumberOfElements:6,hideOnEmptyPhrase:!0,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a.search(b)>-1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onChooseEvent:function(){},onKeyEnterEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){},onShowListEvent:function(){},onHideListEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,requestDelay:0,adjustWidth:!0,ajaxSettings:{},preparePostData:function(a,b){return a},loggerEnabled:!0,template:"",categoriesAssigned:!1,categories:[{maxNumberOfElements:4}]},i=["ajaxSettings","template"];this.getOptions=function(b){return a[b]},this.get=function(a){return h[a]},this.equals=function(a,b){return!(!f(a)||h[a]!==b)},this.checkDataUrlProperties=function(){return!("list-required"===h.url&&"list-required"===h.data)},this.checkRequiredProperties=function(){for(var a in h)if("required"===h[a])return logger.error("Option "+a+" must be defined"),!1;return!0},this.printPropertiesThatDoesntExist=function(a,b){g(a,b)},b(),c(),!0===h.loggerEnabled&&g(console,a),e(),d()},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Logger=function(){this.error=function(a){console.log("ERROR: "+a)},this.warning=function(a){console.log("WARNING: "+a)}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Constants=function(){var a={CONTAINER_CLASS:"easy-autocomplete-container",CONTAINER_ID:"eac-container-",WRAPPER_CSS_CLASS:"easy-autocomplete"};this.getValue=function(b){return a[b]}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.ListBuilderService=function(a,b){function c(b,c){function d(){var d,e={};return void 0!==b.xmlElementName&&(e.xmlElementName=b.xmlElementName),void 0!==b.listLocation?d=b.listLocation:void 0!==a.get("listLocation")&&(d=a.get("listLocation")),void 0!==d?"string"==typeof d?e.data=$(c).find(d):"function"==typeof d&&(e.data=d(c)):e.data=c,e}function e(){var a={};return void 0!==b.listLocation?"string"==typeof b.listLocation?a.data=c[b.listLocation]:"function"==typeof b.listLocation&&(a.data=b.listLocation(c)):a.data=c,a}var f={};if(f="XML"===a.get("dataType").toUpperCase()?d():e(),void 0!==b.header&&(f.header=b.header),void 0!==b.maxNumberOfElements&&(f.maxNumberOfElements=b.maxNumberOfElements),void 0!==a.get("list").maxNumberOfElements&&(f.maxListSize=a.get("list").maxNumberOfElements),void 0!==b.getValue)if("string"==typeof b.getValue){var g=b.getValue;f.getValue=function(a){return a[g]}}else"function"==typeof b.getValue&&(f.getValue=b.getValue);else f.getValue=a.get("getValue");return f}function d(b){var c=[];return void 0===b.xmlElementName&&(b.xmlElementName=a.get("xmlElementName")),$(b.data).find(b.xmlElementName).each(function(){c.push(this)}),c}this.init=function(b){var c=[],d={};return d.data=a.get("listLocation")(b),d.getValue=a.get("getValue"),d.maxListSize=a.get("list").maxNumberOfElements,c.push(d),c},this.updateCategories=function(b,d){if(a.get("categoriesAssigned"))if(b=[],void 0!==a.getOptions("categories"))for(var e=0;e0)return!0;return!1}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.proccess=function(b,c,d){function e(a,c){var d=[],e="";if(b.get("list").match.enabled)for(var g=0,h=a.length;gc.maxNumberOfElements&&(a=a.slice(0,c.maxNumberOfElements)),a}function h(a){return b.get("list").sort.enabled&&a.sort(b.get("list").sort.method),a}a.proccess.match=f;var i=c.data;return i=e(i,d),i=g(i),i=h(i)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a},cssClass:""},description:{type:"description",fields:{description:"description"},method:function(a){return a+" - description"},cssClass:"eac-description"},iconLeft:{type:"iconLeft",fields:{icon:""},method:function(a){return a},cssClass:"eac-icon-left"},iconRight:{type:"iconRight",fields:{iconSrc:""},method:function(a){return a},cssClass:"eac-icon-right"},links:{type:"links",fields:{link:""},method:function(a){return a},cssClass:""},custom:{type:"custom",method:function(){},cssClass:""}},c=function(a){var c,d=a.fields;return"description"===a.type?(c=b.description.method,"string"==typeof d.description?c=function(a,b){return a+" - "+b[d.description]+""}:"function"==typeof d.description&&(c=function(a,b){return a+" - "+d.description(b)+""}),c):"iconRight"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return a+""}:"function"==typeof d.iconSrc&&(c=function(a,b){return a+""}),c):"iconLeft"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return""+a}:"function"==typeof d.iconSrc&&(c=function(a,b){return""+a}),c):"links"===a.type?("string"==typeof d.link?c=function(a,b){return""+a+""}:"function"==typeof d.link&&(c=function(a,b){return""+a+""}),c):"custom"===a.type?a.method:b.basic.method},d=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},e=function(a){var c=function(){return""};return a&&a.type&&a.type&&b[a.type]?function(){var c=b[a.type].cssClass;return function(){return c}}():c};this.getTemplateClass=e(a),this.build=d(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return 0===t.length?void p.error("Input field doesn't exist."):o.checkDataUrlProperties()?o.checkRequiredProperties()?(e(),void g()):void p.error("Will not work without mentioned properties."):void p.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
          "),c=n.getValue("WRAPPER_CSS_CLASS");o.get("theme")&&""!==o.get("theme")&&(c+=" eac-"+o.get("theme")),o.get("cssClasses")&&""!==o.get("cssClasses")&&(c+=" "+o.get("cssClasses")),""!==q.getTemplateClass()&&(c+=" "+q.getTemplateClass()),a.addClass(c),t.wrap(a),!0===o.get("adjustWidth")&&b()}function b(){var a=t.outerWidth();t.parent().css("width",a)}function c(){t.unwrap()}function d(){var a=$("
          ").addClass(n.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
            ")),function(){a.on("show.eac",function(){if(t.is(":focus")){switch(o.get("list").showAnimation.type){case"slide":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").fadeIn(b);break;default:a.find("ul").show()}o.get("list").onShowListEvent()}}).on("hide.eac",function(){switch(o.get("list").hideAnimation.type){case"slide":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}o.get("list").onHideListEvent()}).on("selectElement.eac",function(){a.find("ul li").removeClass("selected"),a.find("ul li").eq(w).addClass("selected"),o.get("list").onSelectItemEvent()}).on("loadElements.eac",function(b,c,d){var e="",f=a.find("ul");f.empty().detach(),v=[];for(var h=0,i=0,k=c.length;i0&&f.append("
            "+c[i].header+"
            ");for(var m=0,n=l.length;m
            "),function(){var a=m,b=h,f=c[i].getValue(l[a]);e.find(" > div").on("click",function(){t.val(f).trigger("change"),w=b,j(b),o.get("list").onClickEvent(),o.get("list").onChooseEvent()}).mouseover(function(){w=b,j(b),o.get("list").onMouseOverEvent()}).mouseout(function(){o.get("list").onMouseOutEvent()}).html(q.build(g(f,d),l[a]))}(),f.append(e),v.push(l[m]),h+=1}}a.append(f),o.get("list").onLoadEvent()})}(),t.after(a)}function e(){t.next("."+n.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return o.get("highlightPhrase")&&""!==b?i(a,b):a}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(a,b){var c=h(b);return(a+"").replace(new RegExp("("+c+")","gi"),"$1")}t.parent().hasClass(n.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),u=$("#"+f()),o.get("placeholder")&&t.attr("placeholder",o.get("placeholder"))}function f(){var a=t.attr("id");return a=n.getValue("CONTAINER_ID")+a}function g(){function a(){s("autocompleteOff",!0)&&n(),b(),c(),d(),e(),f(),g()}function b(){t.focusout(function(){var a,b=t.val();o.get("list").match.caseSensitive||(b=b.toLowerCase());for(var c=0,d=v.length;c0?h():i()}var f=b();void 0!==f.url&&""!==f.url||(f.url=o.get("url")),void 0!==f.dataType&&""!==f.dataType||(f.dataType=o.get("dataType")),void 0!==f.url&&"list-required"!==f.url&&(f.url=f.url(a),f.data=o.get("preparePostData")(f.data,a),$.ajax(f).done(function(b){var d=r.init(b);d=r.updateCategories(d,b),d=r.convertXml(d),c(a,b)&&(d=r.processData(d,a),k(d,a)),r.checkIfDataExists(d)&&t.parent().find("li").length>0?h():i(),o.get("ajaxCallback")()}).fail(function(){p.warning("Fail to load response data")}).always(function(){}))}}switch(a.keyCode){case 27:i(),l();break;case 38:a.preventDefault(),v.length>0&&w>0&&(w-=1,t.val(o.get("getValue")(v[w])),j(w));break;case 40:a.preventDefault(),v.length>0&&w40||8===a.keyCode||0===a.keyCode){var c=t.val();!0!==o.get("list").hideOnEmptyPhrase||8!==a.keyCode||""!==c?o.get("requestDelay")>0?(void 0!==m&&clearTimeout(m),m=setTimeout(function(){b(c)},o.get("requestDelay"))):b(c):i()}}})}function d(){t.on("keydown",function(a){if(a=a||window.event,38===a.keyCode)return suppressKeypress=!0,!1}).keydown(function(a){13===a.keyCode&&w>-1&&(t.val(o.get("getValue")(v[w])),o.get("list").onKeyEnterEvent(),o.get("list").onChooseEvent(),w=-1,i(),a.preventDefault())})}function e(){t.off("keypress")}function f(){t.focus(function(){""!==t.val()&&v.length>0&&(w=-1,h())})}function g(){t.blur(function(){setTimeout(function(){w=-1,i()},250)})}function n(){t.attr("autocomplete","off")}a()}function h(){u.trigger("show.eac")}function i(){u.trigger("hide.eac")}function j(a){u.trigger("selectElement.eac",a)}function k(a,b){u.trigger("loadElements.eac",[a,b])}function l(){t.trigger("blur")}var m,n=new a.Constants,o=new a.Configuration(c),p=new a.Logger,q=new a.Template(c.template),r=new a.ListBuilderService(o,a.proccess),s=o.equals,t=b,u="",v=[],w=-1;a.consts=n,this.getConstants=function(){return n},this.getConfiguration=function(){return o},this.getContainer=function(){return u},this.getSelectedItemIndex=function(){return w},this.getItems=function(){return v},this.getItemData=function(a){return v.length0},a.assignRandomId=function(b){var c="";do{c="eac-"+Math.floor(1e4*Math.random())}while(0!==$("#"+c).length);elementId=a.consts.getValue("CONTAINER_ID")+c,$(b).attr("id",c)},a.setHandle=function(b,c){a.eacHandles[c]=b},a}(EasyAutocomplete||{});!function(a){a.fn.easyAutocomplete=function(b){return this.each(function(){var c=a(this),d=new EasyAutocomplete.main(c,b);EasyAutocomplete.inputHasId(c)||EasyAutocomplete.assignRandomId(c),d.init(),EasyAutocomplete.setHandle(d,c.attr("id"))})},a.fn.getSelectedItemIndex=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemIndex():-1},a.fn.getItems=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getItems():-1},a.fn.getItemData=function(b){var c=a(this).attr("id");return void 0!==c&&b>-1?EasyAutocomplete.getHandle(c).getItemData(b):-1},a.fn.getSelectedItemData=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemData():-1}}(jQuery); \ No newline at end of file +var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){if("xml"===a.dataType&&(a.getValue||(a.getValue=function(a){return $(a).text()}),a.list||(a.list={}),a.list.sort||(a.list.sort={}),a.list.sort.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),bc?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(a,b){return a.search(b)>-1}),void 0!==a.categories&&a.categories instanceof Array){for(var b=[],c=0,d=a.categories.length;cb?1:0}},maxNumberOfElements:6,hideOnEmptyPhrase:!0,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a.search(b)>-1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onChooseEvent:function(){},onKeyEnterEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){},onShowListEvent:function(){},onHideListEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,requestDelay:0,adjustWidth:!0,ajaxSettings:{},preparePostData:function(a,b){return a},loggerEnabled:!0,template:"",categoriesAssigned:!1,categories:[]},i=["ajaxSettings","template"];this.get=function(a){return h[a]},this.equals=function(a,b){return!(!f(a)||h[a]!==b)},this.checkDataUrlProperties=function(){return!("list-required"===h.url&&"list-required"===h.data)},this.checkRequiredProperties=function(){for(var a in h)if("required"===h[a])return logger.error("Option "+a+" must be defined"),!1;return!0},this.printPropertiesThatDoesntExist=function(a,b){g(a,b)},b(),c(),!0===h.loggerEnabled&&g(console,a),e(),d()},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Logger=function(){this.error=function(a){console.log("ERROR: "+a)},this.warning=function(a){console.log("WARNING: "+a)}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Constants=function(){var a={CONTAINER_CLASS:"easy-autocomplete-container",CONTAINER_ID:"eac-container-",WRAPPER_CSS_CLASS:"easy-autocomplete"};this.getValue=function(b){return a[b]}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.ListBuilderService=function(a,b){function c(b,c){function d(){var d,e={};return void 0!==b.xmlElementName&&(e.xmlElementName=b.xmlElementName),void 0!==b.listLocation?d=b.listLocation:void 0!==a.get("listLocation")&&(d=a.get("listLocation")),void 0!==d?"string"==typeof d?e.data=$(c).find(d):"function"==typeof d&&(e.data=d(c)):e.data=c,e}function e(){var a={};return void 0!==b.listLocation?"string"==typeof b.listLocation?a.data=c[b.listLocation]:"function"==typeof b.listLocation&&(a.data=b.listLocation(c)):a.data=c,a}var f={};if(f="XML"===a.get("dataType").toUpperCase()?d():e(),void 0!==b.header&&(f.header=b.header),void 0!==b.maxNumberOfElements&&(f.maxNumberOfElements=b.maxNumberOfElements),void 0!==a.get("list").maxNumberOfElements&&(f.maxListSize=a.get("list").maxNumberOfElements),void 0!==b.getValue)if("string"==typeof b.getValue){var g=b.getValue;f.getValue=function(a){return a[g]}}else"function"==typeof b.getValue&&(f.getValue=b.getValue);else f.getValue=a.get("getValue");return f}function d(b){var c=[];return void 0===b.xmlElementName&&(b.xmlElementName=a.get("xmlElementName")),$(b.data).find(b.xmlElementName).each(function(){c.push(this)}),c}this.init=function(b){var c=[],d={};return d.data=a.get("listLocation")(b),d.getValue=a.get("getValue"),d.maxListSize=a.get("list").maxNumberOfElements,c.push(d),c},this.updateCategories=function(b,d){if(a.get("categoriesAssigned"))if(b=[],0==a.get("categories").length)$.each(d,function(a,e){var f=c({listLocation:a,maxNumberOfElements:10,header:a.replace(/[_\s]+/g," ")},d);b.push(f)});else for(var e=0;e0)return!0;return!1}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.proccess=function(b,c,d){function e(a,c){var d=[],e="";if(b.get("list").match.enabled)for(var g=0,h=a.length;gc.maxNumberOfElements&&(a=a.slice(0,c.maxNumberOfElements)),a}function h(a){return b.get("list").sort.enabled&&a.sort(b.get("list").sort.method),a}a.proccess.match=f;var i=c.data;return i=e(i,d),i=g(i),i=h(i)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a},cssClass:""},description:{type:"description",fields:{description:"description"},method:function(a){return a+" - description"},cssClass:"eac-description"},iconLeft:{type:"iconLeft",fields:{icon:""},method:function(a){return a},cssClass:"eac-icon-left"},iconRight:{type:"iconRight",fields:{iconSrc:""},method:function(a){return a},cssClass:"eac-icon-right"},links:{type:"links",fields:{link:""},method:function(a){return a},cssClass:""},custom:{type:"custom",method:function(){},cssClass:""}},c=function(a){var c,d=a.fields;return"description"===a.type?(c=b.description.method,"string"==typeof d.description?c=function(a,b){return a+" - "+b[d.description]+""}:"function"==typeof d.description&&(c=function(a,b){return a+" - "+d.description(b)+""}),c):"iconRight"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return a+""}:"function"==typeof d.iconSrc&&(c=function(a,b){return a+""}),c):"iconLeft"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return""+a}:"function"==typeof d.iconSrc&&(c=function(a,b){return""+a}),c):"links"===a.type?("string"==typeof d.link?c=function(a,b){return""+a+""}:"function"==typeof d.link&&(c=function(a,b){return""+a+""}),c):"custom"===a.type?a.method:b.basic.method},d=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},e=function(a){var c=function(){return""};return a&&a.type&&a.type&&b[a.type]?function(){var c=b[a.type].cssClass;return function(){return c}}():c};this.getTemplateClass=e(a),this.build=d(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return 0===t.length?void p.error("Input field doesn't exist."):o.checkDataUrlProperties()?o.checkRequiredProperties()?(e(),void g()):void p.error("Will not work without mentioned properties."):void p.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
            "),c=n.getValue("WRAPPER_CSS_CLASS");o.get("theme")&&""!==o.get("theme")&&(c+=" eac-"+o.get("theme")),o.get("cssClasses")&&""!==o.get("cssClasses")&&(c+=" "+o.get("cssClasses")),""!==q.getTemplateClass()&&(c+=" "+q.getTemplateClass()),a.addClass(c),t.wrap(a),!0===o.get("adjustWidth")&&b()}function b(){var a=t.outerWidth();t.parent().css("width",a)}function c(){t.unwrap()}function d(){var a=$("
            ").addClass(n.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
              ")),function(){a.on("show.eac",function(){if(t.is(":focus")){switch(o.get("list").showAnimation.type){case"slide":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").fadeIn(b);break;default:a.find("ul").show()}o.get("list").onShowListEvent()}}).on("hide.eac",function(){switch(o.get("list").hideAnimation.type){case"slide":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}o.get("list").onHideListEvent()}).on("selectElement.eac",function(){a.find("ul li").removeClass("selected"),a.find("ul li").eq(w).addClass("selected"),o.get("list").onSelectItemEvent()}).on("loadElements.eac",function(b,c,d){var e="",f=a.find("ul");f.empty().detach(),v=[];for(var h=0,i=0,k=c.length;i0&&f.append("
              "+c[i].header+"
              ");for(var m=0,n=l.length;m
              "),function(){var a=m,b=h,f=c[i].getValue(l[a]);e.find(" > div").on("click",function(){t.val(f).trigger("change"),w=b,j(b),o.get("list").onClickEvent(),o.get("list").onChooseEvent()}).mouseover(function(){w=b,j(b),o.get("list").onMouseOverEvent()}).mouseout(function(){o.get("list").onMouseOutEvent()}).html(q.build(g(f,d),l[a]))}(),f.append(e),v.push(l[m]),h+=1}}a.append(f),o.get("list").onLoadEvent()})}(),t.after(a)}function e(){t.next("."+n.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return o.get("highlightPhrase")&&""!==b?i(a,b):a}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(a,b){var c=h(b);return(a+"").replace(new RegExp("("+c+")","gi"),"$1")}t.parent().hasClass(n.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),u=$("#"+f()),o.get("placeholder")&&t.attr("placeholder",o.get("placeholder"))}function f(){var a=t.attr("id");return a=n.getValue("CONTAINER_ID")+a}function g(){function a(){s("autocompleteOff",!0)&&n(),b(),c(),d(),e(),f(),g()}function b(){t.focusout(function(){var a,b=t.val();o.get("list").match.caseSensitive||(b=b.toLowerCase());for(var c=0,d=v.length;c0?h():i()}var f=b();void 0!==f.url&&""!==f.url||(f.url=o.get("url")),void 0!==f.dataType&&""!==f.dataType||(f.dataType=o.get("dataType")),void 0!==f.url&&"list-required"!==f.url&&(f.url=f.url(a),f.data=o.get("preparePostData")(f.data,a),$.ajax(f).done(function(b){var d=r.init(b);d=r.updateCategories(d,b),d=r.convertXml(d),c(a,b)&&(d=r.processData(d,a),k(d,a)),r.checkIfDataExists(d)&&t.parent().find("li").length>0?h():i(),o.get("ajaxCallback")()}).fail(function(){p.warning("Fail to load response data")}).always(function(){}))}}switch(a.keyCode){case 27:i(),l();break;case 38:a.preventDefault(),v.length>0&&w>0&&(w-=1,t.val(o.get("getValue")(v[w])),j(w));break;case 40:a.preventDefault(),v.length>0&&w40||8===a.keyCode||0===a.keyCode){var c=t.val();!0!==o.get("list").hideOnEmptyPhrase||8!==a.keyCode||""!==c?o.get("requestDelay")>0?(void 0!==m&&clearTimeout(m),m=setTimeout(function(){b(c)},o.get("requestDelay"))):b(c):i()}}})}function d(){t.on("keydown",function(a){if(a=a||window.event,38===a.keyCode)return suppressKeypress=!0,!1}).keydown(function(a){13===a.keyCode&&w>-1&&(t.val(o.get("getValue")(v[w])),o.get("list").onKeyEnterEvent(),o.get("list").onChooseEvent(),w=-1,i(),a.preventDefault())})}function e(){t.off("keypress")}function f(){t.focus(function(){""!==t.val()&&v.length>0&&(w=-1,h())})}function g(){t.blur(function(){setTimeout(function(){w=-1,i()},250)})}function n(){t.attr("autocomplete","off")}a()}function h(){u.trigger("show.eac")}function i(){u.trigger("hide.eac")}function j(a){u.trigger("selectElement.eac",a)}function k(a,b){u.trigger("loadElements.eac",[a,b])}function l(){t.trigger("blur")}var m,n=new a.Constants,o=new a.Configuration(c),p=new a.Logger,q=new a.Template(c.template),r=new a.ListBuilderService(o,a.proccess),s=o.equals,t=b,u="",v=[],w=-1;a.consts=n,this.getConstants=function(){return n},this.getConfiguration=function(){return o},this.getContainer=function(){return u},this.getSelectedItemIndex=function(){return w},this.getItems=function(){return v},this.getItemData=function(a){return v.length0},a.assignRandomId=function(b){var c="";do{c="eac-"+Math.floor(1e4*Math.random())}while(0!==$("#"+c).length);elementId=a.consts.getValue("CONTAINER_ID")+c,$(b).attr("id",c)},a.setHandle=function(b,c){a.eacHandles[c]=b},a}(EasyAutocomplete||{});!function(a){a.fn.easyAutocomplete=function(b){return this.each(function(){var c=a(this),d=new EasyAutocomplete.main(c,b);EasyAutocomplete.inputHasId(c)||EasyAutocomplete.assignRandomId(c),d.init(),EasyAutocomplete.setHandle(d,c.attr("id"))})},a.fn.getSelectedItemIndex=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemIndex():-1},a.fn.getItems=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getItems():-1},a.fn.getItemData=function(b){var c=a(this).attr("id");return void 0!==c&&b>-1?EasyAutocomplete.getHandle(c).getItemData(b):-1},a.fn.getSelectedItemData=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemData():-1}}(jQuery); \ No newline at end of file diff --git a/dist/maps/easy-autocomplete.css.map b/dist/maps/easy-autocomplete.css.map index 0900da0..1ee4014 100644 --- a/dist/maps/easy-autocomplete.css.map +++ b/dist/maps/easy-autocomplete.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.2 + * @version 1.4.3 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.min.css.map b/dist/maps/easy-autocomplete.min.css.map index 2a824d1..6638e0e 100644 --- a/dist/maps/easy-autocomplete.min.css.map +++ b/dist/maps/easy-autocomplete.min.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.2 + * @version 1.4.3 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.themes.css.map b/dist/maps/easy-autocomplete.themes.css.map index 7f482be..668adb4 100644 --- a/dist/maps/easy-autocomplete.themes.css.map +++ b/dist/maps/easy-autocomplete.themes.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.2 + * @version 1.4.3 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.themes.min.css.map b/dist/maps/easy-autocomplete.themes.min.css.map index 3eb9240..eaf38aa 100644 --- a/dist/maps/easy-autocomplete.themes.min.css.map +++ b/dist/maps/easy-autocomplete.themes.min.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.2 + * @version 1.4.3 * Copyright License: */ diff --git a/package.json b/package.json index c20d655..8e37de1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "easy-autocomplete", "title": "jQuery plugin for autocompletion", "author": "Łukasz Pawełczak (http://github.com/pawelczak)", - "version": "1.4.2", + "version": "1.4.3", "keywords": [ "jquery", "jquery-plugin", diff --git a/src/configuration.js b/src/configuration.js index 19f2f8f..384276f 100644 --- a/src/configuration.js +++ b/src/configuration.js @@ -118,19 +118,12 @@ var EasyAutocomplete = (function (scope) { categoriesAssigned: false, - categories: [{ - //listLocation: "", - maxNumberOfElements: 4 - }] + categories: [] }; var externalObjects = ['ajaxSettings', 'template']; - this.getOptions = function (propertyName) { - return options[propertyName]; - }; - this.get = function (propertyName) { return defaults[propertyName]; }; diff --git a/src/list.builder.js b/src/list.builder.js index 93d8b9c..9e0dc53 100644 --- a/src/list.builder.js +++ b/src/list.builder.js @@ -28,14 +28,7 @@ var EasyAutocomplete = (function (scope) { listBuilder = []; - if (configuration.getOptions('categories') !== undefined) { - for (var i = 0; i < configuration.get("categories").length; i += 1) { - - var builder = convertToListBuilder(configuration.get('categories')[i], data); - - listBuilder.push(builder); - } - } else { + if (configuration.get('categories').length == 0) { $.each(data, function( index, value ) { var builder = convertToListBuilder({ listLocation: index, @@ -45,6 +38,13 @@ var EasyAutocomplete = (function (scope) { listBuilder.push(builder); }); + } else { + for (var i = 0; i < configuration.get("categories").length; i += 1) { + + var builder = convertToListBuilder(configuration.get('categories')[i], data); + + listBuilder.push(builder); + } } } diff --git a/test/configuration.js b/test/configuration.js index cb3f158..851267c 100644 --- a/test/configuration.js +++ b/test/configuration.js @@ -1,5 +1,5 @@ /* - * Tests for Configuration module - EasyAutocomplete + * Tests for Configuration module - EasyAutocomplete * * @author Łukasz Pawełczak */ @@ -577,8 +577,6 @@ QUnit.test('Categories parameters', function (assert) { assert.equal(6, actualOptions.get('categories')[1].maxNumberOfElements, 'Passed - maxNumberOfElements'); - assert.equal('url', actualOptions.get('categories')[2].listLocation, 'Passed - listLocation'); - assert.equal(4, actualOptions.get('categories')[2].maxNumberOfElements, 'Passed - maxNumberOfElements - default'); }); From 64c48b41008aa6c3b4d8a4d07425778cfbce106a Mon Sep 17 00:00:00 2001 From: Saher Haijawi Date: Sun, 3 Mar 2024 14:41:52 +0200 Subject: [PATCH 4/5] DC-10324: add import jquery --- dist/jquery.easy-autocomplete.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dist/jquery.easy-autocomplete.js b/dist/jquery.easy-autocomplete.js index 8ccae16..c9e8ef2 100644 --- a/dist/jquery.easy-autocomplete.js +++ b/dist/jquery.easy-autocomplete.js @@ -1,15 +1,17 @@ /* * easy-autocomplete * jQuery plugin for autocompletion - * + * * @author Łukasz Pawełczak (http://github.com/pawelczak) * @version 1.4.3 - * Copyright License: + * Copyright License: */ /* * EasyAutocomplete - Configuration */ +import jQuery from 'jquery'; + var EasyAutocomplete = (function (scope) { scope.Configuration = function Configuration(options) { @@ -348,7 +350,7 @@ var EasyAutocomplete = (function (scope) { })(EasyAutocomplete || {}); /* - * EasyAutocomplete - Logger + * EasyAutocomplete - Logger */ var EasyAutocomplete = (function (scope) { @@ -602,7 +604,7 @@ var EasyAutocomplete = (function (scope) { * EasyAutocomplete - Data proccess module * * Process list to display: - * - sort + * - sort * - decrease number to specific number * - show only matching list * @@ -685,9 +687,9 @@ var EasyAutocomplete = (function (scope) { /* - * EasyAutocomplete - Template + * EasyAutocomplete - Template + * * - * * */ var EasyAutocomplete = (function (scope) { @@ -1043,7 +1045,7 @@ var EasyAutocomplete = (function (scope) { /* List show animation */ .on('show.eac', function () { if (!$field.is(':focus')) {return} - + switch(config.get('list').showAnimation.type) { case 'slide': From 1c0a8c555d295a1735abac4a0be2211efc7c4ea7 Mon Sep 17 00:00:00 2001 From: lotfe-obaid Date: Fri, 29 Mar 2024 21:15:31 +0200 Subject: [PATCH 5/5] DC-10324: update version and add task to complile js file --- Gruntfile.js | 4 +++- dist/jquery.easy-autocomplete.js | 21 ++++++--------------- package.json | 2 +- src/dependencies.js | 1 + 4 files changed, 11 insertions(+), 17 deletions(-) create mode 100644 src/dependencies.js diff --git a/Gruntfile.js b/Gruntfile.js index 8f32e74..8b6e283 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -36,7 +36,7 @@ module.exports = function (grunt) { concat: { 'src-js': { - src: ['src/configuration.js', 'src/logger.js', 'src/constants.js', 'src/list.builder.js', 'src/data.processor.js', 'src/template.js', 'src/core.js'], + src: ['src/dependencies.js', 'src/configuration.js', 'src/logger.js', 'src/constants.js', 'src/list.builder.js', 'src/data.processor.js', 'src/template.js', 'src/core.js'], dest: '<%= project.js.dest %>' } }, @@ -200,6 +200,8 @@ module.exports = function (grunt) { grunt.registerTask('build', ['qunit:unit', 'concat', 'comments', 'uglify', 'sass:dev', 'sass:dist', 'usebanner', 'copy', 'clean']); + grunt.registerTask('build:js', ['concat', 'comments', 'copy', 'clean']); + grunt.registerTask('devel', ['build', 'qunit:integration']); grunt.registerTask('build:dev', ['build']); diff --git a/dist/jquery.easy-autocomplete.js b/dist/jquery.easy-autocomplete.js index c9e8ef2..21dd00e 100644 --- a/dist/jquery.easy-autocomplete.js +++ b/dist/jquery.easy-autocomplete.js @@ -1,17 +1,8 @@ -/* - * easy-autocomplete - * jQuery plugin for autocompletion - * - * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.4.3 - * Copyright License: - */ +import jQuery from "jquery"; /* * EasyAutocomplete - Configuration */ -import jQuery from 'jquery'; - var EasyAutocomplete = (function (scope) { scope.Configuration = function Configuration(options) { @@ -350,7 +341,7 @@ var EasyAutocomplete = (function (scope) { })(EasyAutocomplete || {}); /* - * EasyAutocomplete - Logger + * EasyAutocomplete - Logger */ var EasyAutocomplete = (function (scope) { @@ -604,7 +595,7 @@ var EasyAutocomplete = (function (scope) { * EasyAutocomplete - Data proccess module * * Process list to display: - * - sort + * - sort * - decrease number to specific number * - show only matching list * @@ -687,9 +678,9 @@ var EasyAutocomplete = (function (scope) { /* - * EasyAutocomplete - Template - * + * EasyAutocomplete - Template * + * * */ var EasyAutocomplete = (function (scope) { @@ -1045,7 +1036,7 @@ var EasyAutocomplete = (function (scope) { /* List show animation */ .on('show.eac', function () { if (!$field.is(':focus')) {return} - + switch(config.get('list').showAnimation.type) { case 'slide': diff --git a/package.json b/package.json index 8e37de1..33c30da 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "easy-autocomplete", "title": "jQuery plugin for autocompletion", "author": "Łukasz Pawełczak (http://github.com/pawelczak)", - "version": "1.4.3", + "version": "1.4.4", "keywords": [ "jquery", "jquery-plugin", diff --git a/src/dependencies.js b/src/dependencies.js new file mode 100644 index 0000000..5242ba0 --- /dev/null +++ b/src/dependencies.js @@ -0,0 +1 @@ +import jQuery from "jquery";