From f0fb4cebf8fcbb55df3d355c9d4e5bdf01349f7b Mon Sep 17 00:00:00 2001 From: Juan Miguel Besada Date: Thu, 23 Apr 2020 17:04:49 +0200 Subject: [PATCH 1/2] feat(): Allow replace ul and status elements --- awesomplete.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/awesomplete.js b/awesomplete.js index 396fb711..dc9efda4 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -36,6 +36,8 @@ var _ = function (input, o) { filter: _.FILTER_CONTAINS, sort: o.sort === false ? false : _.SORT_BYLENGTH, container: _.CONTAINER, + ul: _.UL, + status: _.STATUS, item: _.ITEM, replace: _.REPLACE, tabSelect: false @@ -47,21 +49,9 @@ var _ = function (input, o) { this.container = this.container(input); - this.ul = $.create("ul", { - hidden: "hidden", - role: "listbox", - id: "awesomplete_list_" + this.count, - inside: this.container - }); + this.ul = this.ul(this.container); - this.status = $.create("span", { - className: "visually-hidden", - role: "status", - "aria-live": "assertive", - "aria-atomic": true, - inside: this.container, - textContent: this.minChars != 0 ? ("Type " + this.minChars + " or more characters for results.") : "Begin typing for results." - }); + this.status = this.status(this.container, this.minChars); // Bind events @@ -370,6 +360,26 @@ _.CONTAINER = function (input) { }); } +_.UL = function (container) { + return $.create("ul", { + hidden: "hidden", + role: "listbox", + id: "awesomplete_list_" + this.count, + inside: container + }) +} + +_.STATUS = function(container, minChars) { + return $.create("span", { + className: "visually-hidden", + role: "status", + "aria-live": "assertive", + "aria-atomic": true, + inside: container, + textContent: minChars !== 0 ? ("Type " + minChars + " or more characters for results.") : "Begin typing for results." + }); +} + _.ITEM = function (text, input, item_id) { var html = input.trim() === "" ? text : text.replace(RegExp($.regExpEscape(input.trim()), "gi"), "$&"); return $.create("li", { From b9633c428b8f63b2f9a0ef9e0a34d6541d9e2cc5 Mon Sep 17 00:00:00 2001 From: Juan Miguel Besada Date: Thu, 23 Apr 2020 17:12:34 +0200 Subject: [PATCH 2/2] docs(): Add some docs for new options --- index.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.html b/index.html index 9676d747..c1af65d4 100644 --- a/index.html +++ b/index.html @@ -268,6 +268,18 @@

Extend

Function that takes one parameter, the user’s input and returns an element. Generates <div> with class awesomplete + + ul + Controls how list element is generated. + Function that takes one parameter, the container element and returns an element. + Generates a hidden <ul> with role listbox + + + status + Controls how status element is generated. + Function that takes two parameters, the container element and the minChars option returns an element. + Generates <span> with role status and class visually-hidden + item Controls how list items are generated.