From cae901ff3472080723fc7116f48b44b2946680cf Mon Sep 17 00:00:00 2001 From: pawelczak Date: Sat, 19 Sep 2015 21:59:10 +0200 Subject: [PATCH] Closes #74. Test for matchResponseProperty - function --- dist/jquery.easy-autocomplete.js | 12 ++++--- dist/jquery.easy-autocomplete.min.js | 2 +- test/core/response.js | 47 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/dist/jquery.easy-autocomplete.js b/dist/jquery.easy-autocomplete.js index e57c70e..94699c8 100644 --- a/dist/jquery.easy-autocomplete.js +++ b/dist/jquery.easy-autocomplete.js @@ -1079,14 +1079,16 @@ var EasyAutocomplete = (function(scope) { function checkInputPhraseMatchResponse(inputPhrase, data) { - if (config.get("matchResponseProperty") !== false || typeof config.get("matchResponseProperty") === "string") { + if (config.get("matchResponseProperty") !== false) { + if (typeof config.get("matchResponseProperty") === "string") { + return (data[config.get("matchResponseProperty")] == inputPhrase); + } - if (data[config.get("matchResponseProperty")] == inputPhrase) { - return true; - } else { - return false; + if (typeof config.get("matchResponseProperty") === "function") { + return (config.get("matchResponseProperty")(data) === inputPhrase); } + return true; } else { return true; } diff --git a/dist/jquery.easy-autocomplete.min.js b/dist/jquery.easy-autocomplete.min.js index 0926049..3a150f4 100644 --- a/dist/jquery.easy-autocomplete.min.js +++ b/dist/jquery.easy-autocomplete.min.js @@ -7,4 +7,4 @@ * Copyright MIT License: https://github.com/pawelczak/easy-autocomplete/blob/master/LICENSE.txt */ -var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){"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),c>b?-1:b>c?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),b===c?!0:!1})}function c(){function b(a,c){var d=a||{};for(var e in a)void 0!==c[e]&&null!==c[e]&&("object"!=typeof c[e]||c[e]instanceof Array?d[e]=c[e]:b(a[e],c[e]));return void 0!==c.data&&null!==c.data&&"object"==typeof c.data&&(d.data=c.data),d}h=b(h,a)}function d(){if("list-required"!==h.url&&"function"!=typeof h.url){var a=h.url;h.url=function(){return a}}if(void 0!==h.ajaxSettings.url&&"function"!=typeof h.ajaxSettings.url){var a=h.ajaxSettings.url;h.ajaxSettings.url=function(){return a}}if("string"==typeof h.listLocation){var b=h.listLocation;h.listLocation=function(a){return a[b]}}if("string"==typeof h.getValue){var c=h.getValue;h.getValue=function(a){return a[c]}}}function e(){h.ajaxSettings=void 0!==a.ajaxSettings&&"object"==typeof a.ajaxSettings?a.ajaxSettings:{}}function f(a){return void 0!==h[a]&&null!==h[a]?!0:!1}function g(a,b){function c(b,e){for(var f in e)void 0===b[f]&&a.log("Property '"+f+"' does not exist in EasyAutocomplete options API."),"object"!=typeof b[f]||d(f)||c(b[f],e[f])}function d(a){var b=["ajaxSettings","template"];return Array.prototype.contains=function(a){for(var b=this.length;b--;)if(this[b]===a)return!0;return!1},b.contains(a)}c(h,b)}var h={data:"list-required",url:"list-required",dataType:"json",listLocation:function(a){return a},xmlElementName:"",getValue:function(a){return a},autocompleteOff:!0,placeholder:!1,ajaxCallback:function(){},matchResponseProperty:!1,list:{sort:{enabled:!1,method:function(a,b){return a=h.getValue(a),b=h.getValue(b),b>a?-1:a>b?1:0}},maxNumberOfElements:6,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a=h.getValue(a),b=h.getValue(b),a===b?!0:!1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,ajaxSettings:{},loggerEnabled:!0,template:""};this.get=function(a){return h[a]},this.equals=function(a,b){return f(a)&&h[a]===b?!0:!1},this.checkDataUrlProperties=function(){return"list-required"===h.url&&"list-required"===h.data?!1:!0},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(),h.loggerEnabled===!0&&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.Constans=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.proccess=function(a,b,c){function d(b,c){var d=[],e="";if(a.get("list").match.enabled)for(var f=0,g=b.length;g>f;f+=1)e=a.get("getValue")(b[f]),a.get("list").match.caseSensitive||("string"==typeof e&&(e=e.toLowerCase()),c=c.toLowerCase()),e.search(c)>-1&&d.push(b[f]);else d=b;return d}function e(b){return b.length>a.get("list").maxNumberOfElements&&(b=b.slice(0,a.get("list").maxNumberOfElements)),b}function f(b){return a.get("list").sort.enabled&&b.sort(a.get("list").sort.method),b}var g=c;return b=d(b,g),b=e(b),b=f(b)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a}},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}},custom:{type:"custom",method:function(){}}},c=function(a){var c=a.fields;if("description"===a.type){var d=function(a,b){return a+" - "+b[c.description]+""};return d}if("iconRight"===a.type){var d="";return"string"==typeof c.iconSrc?d=function(a,b){return a+""}:"function"==typeof c.iconSrc&&(d=function(a,b){return a+""}),d}if("iconLeft"===a.type){var d="";return"string"==typeof c.iconSrc?d=function(a,b){return""+a}:"function"==typeof c.iconSrc&&(d=function(a,b){return""+a}),d}if("links"===a.type){var d="";return"string"==typeof c.link?d=function(a,b){return""+a+""}:"function"==typeof c.link&&(d=function(a,b){return""+a+""}),d}return"custom"===a.type?a.method:b.basic.method};prepareBuildMethod=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},templateClass=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=templateClass(a),this.build=prepareBuildMethod(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return n.checkDataUrlProperties()?n.checkRequiredProperties()?(e(),void g()):void o.error("Will not work without mentioned properties."):void o.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
"),c=m.getValue("WRAPPER_CSS_CLASS");n.get("theme")&&(c+=" eac-"+n.get("theme")),n.get("cssClasses")&&(c+=" "+n.get("cssClasses")),""!==p.getTemplateClass()&&(c+=" "+p.getTemplateClass()),a.addClass(c),s.wrap(a),b()}function b(){var a=s.outerWidth();s.parent().css("width",a)}function c(){s.unwrap()}function d(){var a=$("
").addClass(m.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
    ")),function(){a.on("show",function(){switch(n.get("list").showAnimation.type){case"slide":var b=n.get("list").showAnimation.time,c=n.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=n.get("list").showAnimation.time,c=n.get("list").showAnimation.callback;a.find("ul").fadeIn(b),c;break;default:a.find("ul").show()}}).on("hide",function(){switch(n.get("list").hideAnimation.type){case"slide":var b=n.get("list").hideAnimation.time,c=n.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=n.get("list").hideAnimation.time,c=n.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}}).on("selectElement",function(){a.find("ul li").removeClass("selected"),a.find("ul li:nth-child("+(v+1)+")").addClass("selected"),n.get("list").onSelectItemEvent()}).on("loadElements",function(b,c,d){var e="",f=($("
      "),a.find("ul"));f.empty().detach();for(var h=0,i=c.length;i>h;h+=1)e=$("
    • "),function(){var a=h,b=n.get("getValue")(c[a]);e.find(" > div").on("click",function(){s.val(b).trigger("change"),j(a),n.get("list").onClickEvent()}).mouseover(function(){v=a,j(a),n.get("list").onMouseOverEvent()}).mouseout(function(){n.get("list").onMouseOutEvent()}).html(p.build(g(b,d),c[a]))}(),f.append(e);a.append(f),n.get("list").onLoadEvent()})}(),s.after(a)}function e(){s.next("."+m.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return n.get("highlightPhrase")&&""!==b?h(a,b):a}function h(a,b){return(a+"").replace(new RegExp("("+b+")","gi"),"$1")}s.parent().hasClass(m.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),t=$("#"+f()),n.get("placeholder")&&s.attr("placeholder",n.get("placeholder"))}function f(){var a=s.attr("id");if(void 0===a||null===a){do a=m.getValue("CONTAINER_ID")+Math.rand(1e4);while(0===$("#"+a).length)}else a=m.getValue("CONTAINER_ID")+a;return a}function g(){function a(){r("autocompleteOff",!0)&&g(),b(),c(),d(),e(),f()}function b(){s.off("keyup").keyup(function(a){function b(){function a(a){var b=[];return $(a).find(n.get("xmlElementName")).each(function(){b.push(this)}),b}function b(){var a=new Object,b=n.get("ajaxSettings")||{};for(set in b)a[set]=b[set];return a}function c(a,b){return n.get("matchResponseProperty")!==!1||"string"==typeof n.get("matchResponseProperty")?b[n.get("matchResponseProperty")]==a?!0:!1:!0}var d=s.val();if(!(d.length0&&v>0&&(v-=1,s.val(n.get("getValue")(u[v])),j(v));break;case 40:a.preventDefault(),u.length>0&&v40||8===a.keyCode)&&b()}})}function c(){s.on("keydown",function(a){a=a||window.event;var b=a.keyCode;return 38===b?(suppressKeypress=!0,!1):void 0}).keydown(function(a){13===a.keyCode&&v>-1&&(s.val(n.get("getValue")(u[v])),v=-1,i(),a.preventDefault())})}function d(){s.off("keypress")}function e(){s.focus(function(){""!==s.val()&&u.length>0&&(v=-1,h())})}function f(){s.blur(function(){setTimeout(function(){v=-1,i()},250)})}function g(){s.attr("autocomplete","off")}a()}function h(){t.trigger("show")}function i(){t.trigger("hide")}function j(a){t.trigger("selectElement",a)}function k(a,b){t.trigger("loadElements",[a,b])}function l(){s.trigger("blur")}var m=new a.Constans,n=new a.Configuration(c),o=new a.Logger,p=new a.Template(c.template),q=a.proccess,r=n.equals,s=b,t="",u=[],v=-1;this.getConstants=function(){return m},this.getConfiguration=function(){return n},this.getContainer=function(){return t},this.build=function(){e()},this.init=function(){d()}},a}(EasyAutocomplete||{});$.fn.easyAutocomplete=function(a){new EasyAutocomplete.main(this,a).init()}; \ No newline at end of file +var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){"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),c>b?-1:b>c?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),b===c?!0:!1})}function c(){function b(a,c){var d=a||{};for(var e in a)void 0!==c[e]&&null!==c[e]&&("object"!=typeof c[e]||c[e]instanceof Array?d[e]=c[e]:b(a[e],c[e]));return void 0!==c.data&&null!==c.data&&"object"==typeof c.data&&(d.data=c.data),d}h=b(h,a)}function d(){if("list-required"!==h.url&&"function"!=typeof h.url){var a=h.url;h.url=function(){return a}}if(void 0!==h.ajaxSettings.url&&"function"!=typeof h.ajaxSettings.url){var a=h.ajaxSettings.url;h.ajaxSettings.url=function(){return a}}if("string"==typeof h.listLocation){var b=h.listLocation;h.listLocation=function(a){return a[b]}}if("string"==typeof h.getValue){var c=h.getValue;h.getValue=function(a){return a[c]}}}function e(){h.ajaxSettings=void 0!==a.ajaxSettings&&"object"==typeof a.ajaxSettings?a.ajaxSettings:{}}function f(a){return void 0!==h[a]&&null!==h[a]?!0:!1}function g(a,b){function c(b,e){for(var f in e)void 0===b[f]&&a.log("Property '"+f+"' does not exist in EasyAutocomplete options API."),"object"!=typeof b[f]||d(f)||c(b[f],e[f])}function d(a){var b=["ajaxSettings","template"];return Array.prototype.contains=function(a){for(var b=this.length;b--;)if(this[b]===a)return!0;return!1},b.contains(a)}c(h,b)}var h={data:"list-required",url:"list-required",dataType:"json",listLocation:function(a){return a},xmlElementName:"",getValue:function(a){return a},autocompleteOff:!0,placeholder:!1,ajaxCallback:function(){},matchResponseProperty:!1,list:{sort:{enabled:!1,method:function(a,b){return a=h.getValue(a),b=h.getValue(b),b>a?-1:a>b?1:0}},maxNumberOfElements:6,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a=h.getValue(a),b=h.getValue(b),a===b?!0:!1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,ajaxSettings:{},loggerEnabled:!0,template:""};this.get=function(a){return h[a]},this.equals=function(a,b){return f(a)&&h[a]===b?!0:!1},this.checkDataUrlProperties=function(){return"list-required"===h.url&&"list-required"===h.data?!1:!0},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(),h.loggerEnabled===!0&&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.Constans=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.proccess=function(a,b,c){function d(b,c){var d=[],e="";if(a.get("list").match.enabled)for(var f=0,g=b.length;g>f;f+=1)e=a.get("getValue")(b[f]),a.get("list").match.caseSensitive||("string"==typeof e&&(e=e.toLowerCase()),c=c.toLowerCase()),e.search(c)>-1&&d.push(b[f]);else d=b;return d}function e(b){return b.length>a.get("list").maxNumberOfElements&&(b=b.slice(0,a.get("list").maxNumberOfElements)),b}function f(b){return a.get("list").sort.enabled&&b.sort(a.get("list").sort.method),b}var g=c;return b=d(b,g),b=e(b),b=f(b)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a}},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}},custom:{type:"custom",method:function(){}}},c=function(a){var c=a.fields;if("description"===a.type){var d=function(a,b){return a+" - "+b[c.description]+""};return d}if("iconRight"===a.type){var d="";return"string"==typeof c.iconSrc?d=function(a,b){return a+""}:"function"==typeof c.iconSrc&&(d=function(a,b){return a+""}),d}if("iconLeft"===a.type){var d="";return"string"==typeof c.iconSrc?d=function(a,b){return""+a}:"function"==typeof c.iconSrc&&(d=function(a,b){return""+a}),d}if("links"===a.type){var d="";return"string"==typeof c.link?d=function(a,b){return""+a+""}:"function"==typeof c.link&&(d=function(a,b){return""+a+""}),d}return"custom"===a.type?a.method:b.basic.method};prepareBuildMethod=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},templateClass=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=templateClass(a),this.build=prepareBuildMethod(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return n.checkDataUrlProperties()?n.checkRequiredProperties()?(e(),void g()):void o.error("Will not work without mentioned properties."):void o.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
      "),c=m.getValue("WRAPPER_CSS_CLASS");n.get("theme")&&(c+=" eac-"+n.get("theme")),n.get("cssClasses")&&(c+=" "+n.get("cssClasses")),""!==p.getTemplateClass()&&(c+=" "+p.getTemplateClass()),a.addClass(c),s.wrap(a),b()}function b(){var a=s.outerWidth();s.parent().css("width",a)}function c(){s.unwrap()}function d(){var a=$("
      ").addClass(m.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
        ")),function(){a.on("show",function(){switch(n.get("list").showAnimation.type){case"slide":var b=n.get("list").showAnimation.time,c=n.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=n.get("list").showAnimation.time,c=n.get("list").showAnimation.callback;a.find("ul").fadeIn(b),c;break;default:a.find("ul").show()}}).on("hide",function(){switch(n.get("list").hideAnimation.type){case"slide":var b=n.get("list").hideAnimation.time,c=n.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=n.get("list").hideAnimation.time,c=n.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}}).on("selectElement",function(){a.find("ul li").removeClass("selected"),a.find("ul li:nth-child("+(v+1)+")").addClass("selected"),n.get("list").onSelectItemEvent()}).on("loadElements",function(b,c,d){var e="",f=($("
          "),a.find("ul"));f.empty().detach();for(var h=0,i=c.length;i>h;h+=1)e=$("
        • "),function(){var a=h,b=n.get("getValue")(c[a]);e.find(" > div").on("click",function(){s.val(b).trigger("change"),j(a),n.get("list").onClickEvent()}).mouseover(function(){v=a,j(a),n.get("list").onMouseOverEvent()}).mouseout(function(){n.get("list").onMouseOutEvent()}).html(p.build(g(b,d),c[a]))}(),f.append(e);a.append(f),n.get("list").onLoadEvent()})}(),s.after(a)}function e(){s.next("."+m.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return n.get("highlightPhrase")&&""!==b?h(a,b):a}function h(a,b){return(a+"").replace(new RegExp("("+b+")","gi"),"$1")}s.parent().hasClass(m.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),t=$("#"+f()),n.get("placeholder")&&s.attr("placeholder",n.get("placeholder"))}function f(){var a=s.attr("id");if(void 0===a||null===a){do a=m.getValue("CONTAINER_ID")+Math.rand(1e4);while(0===$("#"+a).length)}else a=m.getValue("CONTAINER_ID")+a;return a}function g(){function a(){r("autocompleteOff",!0)&&g(),b(),c(),d(),e(),f()}function b(){s.off("keyup").keyup(function(a){function b(){function a(a){var b=[];return $(a).find(n.get("xmlElementName")).each(function(){b.push(this)}),b}function b(){var a=new Object,b=n.get("ajaxSettings")||{};for(set in b)a[set]=b[set];return a}function c(a,b){return n.get("matchResponseProperty")!==!1?"string"==typeof n.get("matchResponseProperty")?b[n.get("matchResponseProperty")]==a:"function"==typeof n.get("matchResponseProperty")?n.get("matchResponseProperty")(b)===a:!0:!0}var d=s.val();if(!(d.length0&&v>0&&(v-=1,s.val(n.get("getValue")(u[v])),j(v));break;case 40:a.preventDefault(),u.length>0&&v40||8===a.keyCode)&&b()}})}function c(){s.on("keydown",function(a){a=a||window.event;var b=a.keyCode;return 38===b?(suppressKeypress=!0,!1):void 0}).keydown(function(a){13===a.keyCode&&v>-1&&(s.val(n.get("getValue")(u[v])),v=-1,i(),a.preventDefault())})}function d(){s.off("keypress")}function e(){s.focus(function(){""!==s.val()&&u.length>0&&(v=-1,h())})}function f(){s.blur(function(){setTimeout(function(){v=-1,i()},250)})}function g(){s.attr("autocomplete","off")}a()}function h(){t.trigger("show")}function i(){t.trigger("hide")}function j(a){t.trigger("selectElement",a)}function k(a,b){t.trigger("loadElements",[a,b])}function l(){s.trigger("blur")}var m=new a.Constans,n=new a.Configuration(c),o=new a.Logger,p=new a.Template(c.template),q=a.proccess,r=n.equals,s=b,t="",u=[],v=-1;this.getConstants=function(){return m},this.getConfiguration=function(){return n},this.getContainer=function(){return t},this.build=function(){e()},this.init=function(){d()}},a}(EasyAutocomplete||{});$.fn.easyAutocomplete=function(a){new EasyAutocomplete.main(this,a).init()}; \ No newline at end of file diff --git a/test/core/response.js b/test/core/response.js index 00c8a2f..d0903c5 100644 --- a/test/core/response.js +++ b/test/core/response.js @@ -234,6 +234,53 @@ QUnit.test("Match response", function( assert ) { } }); +QUnit.test("Match response - property function", function( assert ) { + expect(4); + + //given + var completerOne = new EasyAutocomplete.main($("#inputOne"), + { + url: "resources/response.json", + + listLocation: "items", + + matchResponseProperty: function(data) { + return data.inputPhrase; + }, + + ajaxCallback: function() { + + //assert + assertList(); + } + }); + + + //execute + + completerOne.init(); + + var e = $.Event('keyup'); + e.keyCode = 50; + $("#inputOne").val("rr").trigger(e); + + + QUnit.stop(); + + + //assert + + function assertList() { + var elements = $("#inputOne").next().find("ul li"); + + assert.equal(3, elements.length, "Response size"); + assert.equal("red", elements.eq(0).find("div").text(), "First element value"); + assert.equal("yellow", elements.eq(1).find("div").text(), "Second element value"); + assert.equal("brown", elements.eq(2).find("div").text(), "Third element value"); + + QUnit.start(); + } +}); QUnit.test("Input field should have value changed when user clicks on one element from suggestions list", function( assert ) { expect(1);