diff --git a/awesomplete.js b/awesomplete.js index 41f94eef..fd5857fb 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -70,8 +70,9 @@ var _ = function (input, o) { // Enter / Esc / Up / Down if(me.opened) { if (c === 13 && me.selected) { // Enter + var li = me.ul.children[me.index]; evt.preventDefault(); - me.select(); + me.select(li, evt); } else if (c === 27) { // Esc me.close(); @@ -198,16 +199,18 @@ _.prototype = { $.fire(this.input, "awesomplete-select", { text: selected.textContent, + originalTarget: selected, preventDefault: function () { prevented = true; - }, - originalEvent: originalEvent + } }); if (!prevented) { this.replace(selected.textContent); this.close(); - $.fire(this.input, "awesomplete-selectcomplete"); + $.fire(this.input, "awesomplete-selectcomplete", { + originalTarget: selected + }); } } }, diff --git a/awesomplete.min.js b/awesomplete.min.js index 395d46dc..feb180d6 100644 --- a/awesomplete.min.js +++ b/awesomplete.min.js @@ -1,10 +1,11 @@ // Awesomplete - Lea Verou - MIT license (function(){function m(a,b){for(var c in a){var g=a[c],e=this.input.getAttribute("data-"+c.toLowerCase());this[c]="number"===typeof g?parseInt(e):!1===g?null!==e:g instanceof Function?null:e;this[c]||0===this[c]||(this[c]=c in b?b[c]:g)}}function d(a,b){return"string"===typeof a?(b||document).querySelector(a):a||null}function h(a,b){return k.call((b||document).querySelectorAll(a))}function l(){h("input.awesomplete").forEach(function(a){new f(a)})}var f=function(a,b){var c=this;this.input=d(a);this.input.setAttribute("autocomplete", "off");this.input.setAttribute("aria-autocomplete","list");b=b||{};m.call(this,{minChars:2,maxItems:10,autoFirst:!1,filter:f.FILTER_CONTAINS,sort:f.SORT_BYLENGTH,item:function(a,b){var c=""===b?a:a.replace(RegExp(d.regExpEscape(b.trim()),"gi"),"$&");return d.create("li",{innerHTML:c,"aria-selected":"false"})},replace:function(a){this.input.value=a}},b);this.index=-1;this.container=d.create("div",{className:"awesomplete",around:a});this.ul=d.create("ul",{hidden:"hidden",inside:this.container}); -this.status=d.create("span",{className:"visually-hidden",role:"status","aria-live":"assertive","aria-relevant":"additions",inside:this.container});d.bind(this.input,{input:this.evaluate.bind(this),blur:this.close.bind(this),keydown:function(a){var b=a.keyCode;if(c.opened)if(13===b&&c.selected)a.preventDefault(),c.select();else if(27===b)c.close();else if(38===b||40===b)a.preventDefault(),c[38===b?"previous":"next"]()}});d.bind(this.input.form,{submit:this.close.bind(this)});d.bind(this.ul,{mousedown:function(a){var b= -a.target;if(b!==this){for(;b&&!/li/i.test(b.nodeName);)b=b.parentNode;b&&0===a.button&&c.select(b,a)}}});this.input.hasAttribute("list")?(this.list="#"+this.input.getAttribute("list"),this.input.removeAttribute("list")):this.list=this.input.getAttribute("data-list")||b.list||[];f.all.push(this)};f.prototype={set list(a){Array.isArray(a)?this._list=a:"string"===typeof a&&-1=this.minChars&&0=this.minChars&&0Ajax example (restcountries.eu api) } ajax.send(); + + +
+

Working with an array of objects

+ + +
		
+