From 2f355e56c37ee861949b85cb1dd35b11737fd0f5 Mon Sep 17 00:00:00 2001 From: TxHawks Date: Wed, 9 Dec 2015 16:11:29 +0200 Subject: [PATCH 01/11] Pass selected item's data to the select* events Pass the selected item's dataset to the `awesomplete-select` and `awesomplete-selectcomplete` events to allow firing actions based on secondary keys in the object --- awesomplete.js | 3 ++- awesomplete.min.js | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/awesomplete.js b/awesomplete.js index 4d8c2886..43a3a7ce 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -197,6 +197,7 @@ _.prototype = { var prevented; $.fire(this.input, "awesomplete-select", { + dataset: selected.dataset, text: selected.textContent, preventDefault: function () { prevented = true; @@ -206,7 +207,7 @@ _.prototype = { if (!prevented) { this.replace(selected.textContent); this.close(); - $.fire(this.input, "awesomplete-selectcomplete"); + $.fire(this.input, "awesomplete-selectcomplete", {dataset: selected.dataset}); } } }, diff --git a/awesomplete.min.js b/awesomplete.min.js index afebcafe..68ed4e89 100644 --- a/awesomplete.min.js +++ b/awesomplete.min.js @@ -4,7 +4,8 @@ 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)}}});this.input.hasAttribute("list")?(this.list="#"+a.getAttribute("list"),a.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&&0 Date: Wed, 9 Dec 2015 16:29:03 +0200 Subject: [PATCH 02/11] Add an array-of objects-list example to the docs --- index.html | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/index.html b/index.html index 84901b22..a94d74d0 100644 --- a/index.html +++ b/index.html @@ -384,6 +384,51 @@

Ajax example (restcountries.eu api)

} ajax.send(); + + +
+

Working with an array of objects

+ + +
		
+
From d94167aec001beba44897d1398af62fa7c950258 Mon Sep 17 00:00:00 2001 From: TxHawks Date: Mon, 28 Dec 2015 17:58:10 +0200 Subject: [PATCH 03/11] Align with changes introduced in #16794; - Fix bug created in #16794, which caused different behaviours when selecting an item with the keyboard and with a mouse. --- awesomplete.js | 11 ++++++++--- index.html | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/awesomplete.js b/awesomplete.js index e33ac013..6abe7756 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -70,8 +70,10 @@ 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(); + evt.originalTarget = li + me.select(li, evt); } else if (c === 27) { // Esc me.close(); @@ -96,6 +98,7 @@ var _ = function (input, o) { } if (li && evt.button === 0) { // Only select on left click + evt.originalTarget = li; me.select(li, evt); } } @@ -199,16 +202,18 @@ _.prototype = { $.fire(this.input, "awesomplete-select", { dataset: selected.dataset, text: selected.textContent, + originalTarget: originalEvent.originalTarget preventDefault: function () { prevented = true; }, - originalEvent: originalEvent }); if (!prevented) { this.replace(selected.textContent); this.close(); - $.fire(this.input, "awesomplete-selectcomplete", {dataset: selected.dataset}); + $.fire(this.input, "awesomplete-selectcomplete", { + originalTarget: originalEvent.originalTarget + }); } } }, diff --git a/index.html b/index.html index a94d74d0..494e2fd2 100644 --- a/index.html +++ b/index.html @@ -424,8 +424,8 @@

Working with an array of objects

}); arrOfObj.addEventListener('awesomplete-selectcomplete', fucntion(e) { - // You can no do something with e.dataset.url - console.log(e.dataset.url); + // You can no do something with e.originalTarget.getAttribute('data-*') + console.log(e.originalTarget.getAttribute('data-url'); });
From 0ea78d728a8a6fccff13f8135b1ba80c4911e4f9 Mon Sep 17 00:00:00 2001 From: TxHawks Date: Mon, 28 Dec 2015 18:03:12 +0200 Subject: [PATCH 04/11] Oops... forgot to add changes to the minified file --- awesomplete.min.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/awesomplete.min.js b/awesomplete.min.js index 68ed4e89..230db2ad 100644 --- a/awesomplete.min.js +++ b/awesomplete.min.js @@ -1,11 +1,2 @@ // 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:"",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)}}});this.input.hasAttribute("list")?(this.list="#"+a.getAttribute("list"),a.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 Date: Mon, 28 Dec 2015 18:17:04 +0200 Subject: [PATCH 05/11] Add missing `,` --- awesomplete.js | 6 +++--- awesomplete.min.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/awesomplete.js b/awesomplete.js index 6abe7756..04934554 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -72,7 +72,7 @@ var _ = function (input, o) { if (c === 13 && me.selected) { // Enter var li = me.ul.children[me.index]; evt.preventDefault(); - evt.originalTarget = li + evt.originalTarget = li; me.select(li, evt); } else if (c === 27) { // Esc @@ -202,10 +202,10 @@ _.prototype = { $.fire(this.input, "awesomplete-select", { dataset: selected.dataset, text: selected.textContent, - originalTarget: originalEvent.originalTarget + originalTarget: originalEvent.originalTarget, preventDefault: function () { prevented = true; - }, + } }); if (!prevented) { diff --git a/awesomplete.min.js b/awesomplete.min.js index 230db2ad..5ff44697 100644 --- a/awesomplete.min.js +++ b/awesomplete.min.js @@ -1,2 +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)b=c.ul.children[c.index],a.preventDefault(),a.originalTarget=b,c.select(b,a);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&&(a.originalTarget=b,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 Date: Mon, 28 Dec 2015 19:09:10 +0200 Subject: [PATCH 06/11] Fix Array of objects example in `index.html` --- index.html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 494e2fd2..ed9fd889 100644 --- a/index.html +++ b/index.html @@ -391,9 +391,9 @@

Working with an array of objects

		
From 52dac8431cddffa0e721f49aeced9fdab606e8ee Mon Sep 17 00:00:00 2001 From: TxHawks Date: Sat, 2 Jan 2016 17:38:20 +0200 Subject: [PATCH 07/11] Remove unused `dataset` property from `awesomplete-select` event --- awesomplete.js | 1 - awesomplete.min.js | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/awesomplete.js b/awesomplete.js index 04934554..e2a4c8ec 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -200,7 +200,6 @@ _.prototype = { var prevented; $.fire(this.input, "awesomplete-select", { - dataset: selected.dataset, text: selected.textContent, originalTarget: originalEvent.originalTarget, preventDefault: function () { diff --git a/awesomplete.min.js b/awesomplete.min.js index 5ff44697..c3389e6e 100644 --- a/awesomplete.min.js +++ b/awesomplete.min.js @@ -5,7 +5,7 @@ this.status=d.create("span",{className:"visually-hidden",role:"status","aria-liv 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&&(a.originalTarget=b,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&&0 Date: Sat, 2 Jan 2016 17:38:34 +0200 Subject: [PATCH 08/11] Fix tests to add an event to select() --- test/api/selectSpec.js | 15 ++++++++------- test/awesompleteShared.js | 4 +++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test/api/selectSpec.js b/test/api/selectSpec.js index 82b40698..90a461ca 100644 --- a/test/api/selectSpec.js +++ b/test/api/selectSpec.js @@ -9,6 +9,7 @@ describe("awesomplete.select", function () { def("firstIndex", function () { return 0 }); def("lastIndex", function () { return this.subject.ul.children.length - 1 }); def("lastLi", function () { return this.subject.ul.children[this.lastIndex] }); + def("mockEvt", function () { return { 'originalTarget': this.lastLi } }); beforeEach(function () { $.type(this.subject.input, "ite"); @@ -43,7 +44,7 @@ describe("awesomplete.select", function () { function itSelects(expectedTxt) { it("fires awesomplete-select event", function () { var handler = $.spyOnEvent(this.subject.input, "awesomplete-select"); - this.subject.select(this.selectArgument); + this.subject.select(this.selectArgument, this.mockEvt); expect(handler).toHaveBeenCalledWith(jasmine.objectContaining({ text: expectedTxt })); }); @@ -54,20 +55,20 @@ describe("awesomplete.select", function () { }); it("changes the input value", function () { - this.subject.select(this.selectArgument); + this.subject.select(this.selectArgument, this.mockEvt); expect(this.subject.input.value).toBe(expectedTxt); }); it("closes completer", function () { spyOn(this.subject, "close"); - this.subject.select(this.selectArgument); + this.subject.select(this.selectArgument, this.mockEvt); expect(this.subject.close).toHaveBeenCalled(); }); it("fires awesomplete-selectcomplete event", function () { var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete"); - this.subject.select(this.selectArgument); + this.subject.select(this.selectArgument, this.mockEvt); expect(handler).toHaveBeenCalled(); }); @@ -79,20 +80,20 @@ describe("awesomplete.select", function () { }); it("does not change the input value", function () { - this.subject.select(this.selectArgument); + this.subject.select(this.selectArgument, this.mockEvt); expect(this.subject.input.value).toBe("ite"); }); it("does not close completer", function () { spyOn(this.subject, "close"); - this.subject.select(this.selectArgument); + this.subject.select(this.selectArgument, this.mockEvt); expect(this.subject.close).not.toHaveBeenCalled(); }); it("does not fire awesomplete-selectcomplete event", function () { var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete"); - this.subject.select(this.selectArgument); + this.subject.select(this.selectArgument, this.mockEvt); expect(handler).not.toHaveBeenCalled(); }); diff --git a/test/awesompleteShared.js b/test/awesompleteShared.js index 64d53f43..78663324 100644 --- a/test/awesompleteShared.js +++ b/test/awesompleteShared.js @@ -24,10 +24,12 @@ var shared = { expectSelectingFirstSuggestionToWorkWith: function(val){ return function(){ var li; + var evt; shared.awesompleter.input.value = val; shared.awesompleter.evaluate(); li = shared.awesompleter.ul.children[0]; - shared.awesompleter.select(li); + evt = {originalTarget: li}; + shared.awesompleter.select(li, evt); expect(shared.awesompleter.input.value).toBe(li.textContent); } }, From d7f99fc125c51ae5dde0110ebe057970cc535bc1 Mon Sep 17 00:00:00 2001 From: TxHawks Date: Sat, 2 Jan 2016 17:45:48 +0200 Subject: [PATCH 09/11] Make passing an event to `select()` optional --- awesomplete.js | 4 ++-- awesomplete.min.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/awesomplete.js b/awesomplete.js index e2a4c8ec..5f9e4e87 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -201,7 +201,7 @@ _.prototype = { $.fire(this.input, "awesomplete-select", { text: selected.textContent, - originalTarget: originalEvent.originalTarget, + originalTarget: typeof originalEvent === 'object' ? originalEvent.originalTarget : 'undefined', preventDefault: function () { prevented = true; } @@ -211,7 +211,7 @@ _.prototype = { this.replace(selected.textContent); this.close(); $.fire(this.input, "awesomplete-selectcomplete", { - originalTarget: originalEvent.originalTarget + originalTarget: typeof originalEvent === 'object' ? originalEvent.originalTarget : 'undefined' }); } } diff --git a/awesomplete.min.js b/awesomplete.min.js index c3389e6e..e60af3bb 100644 --- a/awesomplete.min.js +++ b/awesomplete.min.js @@ -5,7 +5,7 @@ this.status=d.create("span",{className:"visually-hidden",role:"status","aria-liv 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&&(a.originalTarget=b,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&&0 Date: Sat, 2 Jan 2016 17:46:43 +0200 Subject: [PATCH 10/11] Revert "Fix tests to add an event to select()" This reverts commit dc966c9ebc2b85c5481a771fadeaaca427b0fd9d. --- test/api/selectSpec.js | 15 +++++++-------- test/awesompleteShared.js | 4 +--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/test/api/selectSpec.js b/test/api/selectSpec.js index 90a461ca..82b40698 100644 --- a/test/api/selectSpec.js +++ b/test/api/selectSpec.js @@ -9,7 +9,6 @@ describe("awesomplete.select", function () { def("firstIndex", function () { return 0 }); def("lastIndex", function () { return this.subject.ul.children.length - 1 }); def("lastLi", function () { return this.subject.ul.children[this.lastIndex] }); - def("mockEvt", function () { return { 'originalTarget': this.lastLi } }); beforeEach(function () { $.type(this.subject.input, "ite"); @@ -44,7 +43,7 @@ describe("awesomplete.select", function () { function itSelects(expectedTxt) { it("fires awesomplete-select event", function () { var handler = $.spyOnEvent(this.subject.input, "awesomplete-select"); - this.subject.select(this.selectArgument, this.mockEvt); + this.subject.select(this.selectArgument); expect(handler).toHaveBeenCalledWith(jasmine.objectContaining({ text: expectedTxt })); }); @@ -55,20 +54,20 @@ describe("awesomplete.select", function () { }); it("changes the input value", function () { - this.subject.select(this.selectArgument, this.mockEvt); + this.subject.select(this.selectArgument); expect(this.subject.input.value).toBe(expectedTxt); }); it("closes completer", function () { spyOn(this.subject, "close"); - this.subject.select(this.selectArgument, this.mockEvt); + this.subject.select(this.selectArgument); expect(this.subject.close).toHaveBeenCalled(); }); it("fires awesomplete-selectcomplete event", function () { var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete"); - this.subject.select(this.selectArgument, this.mockEvt); + this.subject.select(this.selectArgument); expect(handler).toHaveBeenCalled(); }); @@ -80,20 +79,20 @@ describe("awesomplete.select", function () { }); it("does not change the input value", function () { - this.subject.select(this.selectArgument, this.mockEvt); + this.subject.select(this.selectArgument); expect(this.subject.input.value).toBe("ite"); }); it("does not close completer", function () { spyOn(this.subject, "close"); - this.subject.select(this.selectArgument, this.mockEvt); + this.subject.select(this.selectArgument); expect(this.subject.close).not.toHaveBeenCalled(); }); it("does not fire awesomplete-selectcomplete event", function () { var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete"); - this.subject.select(this.selectArgument, this.mockEvt); + this.subject.select(this.selectArgument); expect(handler).not.toHaveBeenCalled(); }); diff --git a/test/awesompleteShared.js b/test/awesompleteShared.js index 78663324..64d53f43 100644 --- a/test/awesompleteShared.js +++ b/test/awesompleteShared.js @@ -24,12 +24,10 @@ var shared = { expectSelectingFirstSuggestionToWorkWith: function(val){ return function(){ var li; - var evt; shared.awesompleter.input.value = val; shared.awesompleter.evaluate(); li = shared.awesompleter.ul.children[0]; - evt = {originalTarget: li}; - shared.awesompleter.select(li, evt); + shared.awesompleter.select(li); expect(shared.awesompleter.input.value).toBe(li.textContent); } }, From 6342f4384f59c4ddb3c8c09bce949c173e2fc924 Mon Sep 17 00:00:00 2001 From: TxHawks Date: Sat, 9 Jan 2016 19:38:38 +0200 Subject: [PATCH 11/11] Use `selected` instead of originalEvent.originalTarget No need to modify the event object, the selected element just needs to be passed to the fired events in `select()`. --- awesomplete.js | 6 ++---- awesomplete.min.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/awesomplete.js b/awesomplete.js index 5f9e4e87..fd5857fb 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -72,7 +72,6 @@ var _ = function (input, o) { if (c === 13 && me.selected) { // Enter var li = me.ul.children[me.index]; evt.preventDefault(); - evt.originalTarget = li; me.select(li, evt); } else if (c === 27) { // Esc @@ -98,7 +97,6 @@ var _ = function (input, o) { } if (li && evt.button === 0) { // Only select on left click - evt.originalTarget = li; me.select(li, evt); } } @@ -201,7 +199,7 @@ _.prototype = { $.fire(this.input, "awesomplete-select", { text: selected.textContent, - originalTarget: typeof originalEvent === 'object' ? originalEvent.originalTarget : 'undefined', + originalTarget: selected, preventDefault: function () { prevented = true; } @@ -211,7 +209,7 @@ _.prototype = { this.replace(selected.textContent); this.close(); $.fire(this.input, "awesomplete-selectcomplete", { - originalTarget: typeof originalEvent === 'object' ? originalEvent.originalTarget : 'undefined' + originalTarget: selected }); } } diff --git a/awesomplete.min.js b/awesomplete.min.js index 2d129ff2..feb180d6 100644 --- a/awesomplete.min.js +++ b/awesomplete.min.js @@ -1,11 +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)b=c.ul.children[c.index],a.preventDefault(),a.originalTarget=b,c.select(b,a);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&&(a.originalTarget=b,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&&0