Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

awesomplete

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

awesomplete - npm Package Compare versions

Comparing version 1.1.5 to 1.1.6

56

awesomplete.js

@@ -13,5 +13,5 @@ /**

// Keep track of number of instances for unique IDs
_.count = (_.count || 0) + 1;
this.count = _.count;
// Keep track of number of instances for unique IDs
_.count = (_.count || 0) + 1;
this.count = _.count;

@@ -24,3 +24,5 @@ // Setup

this.input.setAttribute("autocomplete", "off");
this.input.setAttribute("aria-autocomplete", "list");
this.input.setAttribute("aria-expanded", "false");
this.input.setAttribute("aria-controls", "awesomplete_list_" + this.count);
this.input.setAttribute("aria-owns", "awesomplete_list_" + this.count);

@@ -43,3 +45,7 @@ this.input.setAttribute("role", "combobox");

replace: _.REPLACE,
tabSelect: false
tabSelect: false,
listLabel: "Results List",
statusNoResults: "No results found",
statusXResults: "{0} results found", // uses index placeholder {0}
statusTypeXChar: "Type {0} or more characters for results"
}, o);

@@ -55,5 +61,6 @@

hidden: "hidden",
role: "listbox",
id: "awesomplete_list_" + this.count,
inside: this.container
role: "listbox",
id: "awesomplete_list_" + this.count,
inside: this.container,
"aria-label": this.listLabel
});

@@ -65,5 +72,5 @@

"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."
"aria-atomic": true,
inside: this.container,
textContent: "" // live region should start empty. Only when the text is changed it will be read by the screen reader.
});

@@ -88,2 +95,3 @@

else if (c === 9 && me.selected && me.tabSelect) {
evt.preventDefault();
me.select(undefined, undefined, evt);

@@ -228,5 +236,9 @@ }

//remove autocomplete and aria-autocomplete attributes
// remove autocomplete and aria attributes
this.input.removeAttribute("autocomplete");
this.input.removeAttribute("aria-autocomplete");
this.input.removeAttribute("aria-expanded");
this.input.removeAttribute("aria-controls");
this.input.removeAttribute("aria-owns");
this.input.removeAttribute("role");

@@ -266,5 +278,8 @@ //remove this awesomeplete instance from the global array of instances

this.status.textContent = lis[i].textContent + ", list item " + (i + 1) + " of " + lis.length;
// fix: Turned off this status update.
// Screen readers Voiceover and Talkback won't read this status change.
// Narrator and NVDA do, but they already tell: 'X of Y (selected)'
// this.status.textContent = lis[i].textContent + ", list item " + (i + 1) + " of " + lis.length;
this.input.setAttribute("aria-activedescendant", this.ul.id + "_item_" + this.index);
this.input.setAttribute("aria-activedescendant", this.ul.id + "_item_" + this.index);

@@ -336,3 +351,3 @@ // scroll to highlighted element in case parent's height is fixed

this.status.textContent = "No results found";
this.status.textContent = this.statusNoResults;

@@ -344,9 +359,15 @@ this.close({ reason: "nomatches" });

this.status.textContent = this.ul.children.length + " results found";
this.status.textContent = this.statusXResults.replaceAll('{0}', this.ul.children.length); // N results found;
}
}
else {
this.close({ reason: "nomatches" });
this.status.textContent = "No results found";
if (this.minChar <= 1 || value.length >= this.minChars) {
this.status.textContent = this.statusNoResults;
} else {
this.status.textContent = this.statusTypeXChar.replaceAll('{0}', this.minChars); // Type N or more characters for results
}
}

@@ -389,2 +410,3 @@ }

"aria-selected": "false",
"tabindex": '0', // for the Talkback screen reader
"id": "awesomplete_list_" + this.count + "_item_" + item_id

@@ -420,3 +442,3 @@ });

var initial = properties[i],
attrValue = instance.input.getAttribute("data-" + i.toLowerCase());
attrValue = instance.input.getAttribute("data-" + i.toLowerCase());

@@ -423,0 +445,0 @@ if (typeof initial === "number") {

// Awesomplete - Lea Verou - MIT license
!function(){function t(t){var e=Array.isArray(t)?{label:t[0],value:t[1]}:"object"==typeof t&&"label"in t&&"value"in t?t:{label:t,value:t};this.label=e.label||e.value,this.value=e.value}function e(t,e,i){for(var n in e){var s=e[n],r=t.input.getAttribute("data-"+n.toLowerCase());"number"==typeof s?t[n]=parseInt(r):!1===s?t[n]=null!==r:s instanceof Function?t[n]=null:t[n]=r,t[n]||0===t[n]||(t[n]=n in i?i[n]:s)}}function i(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function n(t,e){return o.call((e||document).querySelectorAll(t))}function s(){n("input.awesomplete").forEach(function(t){new r(t)})}var r=function(t,n){var s=this;r.count=(r.count||0)+1,this.count=r.count,this.isOpened=!1,this.input=i(t),this.input.setAttribute("autocomplete","off"),this.input.setAttribute("aria-expanded","false"),this.input.setAttribute("aria-owns","awesomplete_list_"+this.count),this.input.setAttribute("role","combobox"),this.options=n=n||{},e(this,{minChars:2,maxItems:10,autoFirst:!1,data:r.DATA,filter:r.FILTER_CONTAINS,sort:!1!==n.sort&&r.SORT_BYLENGTH,container:r.CONTAINER,item:r.ITEM,replace:r.REPLACE,tabSelect:!1},n),this.index=-1,this.container=this.container(t),this.ul=i.create("ul",{hidden:"hidden",role:"listbox",id:"awesomplete_list_"+this.count,inside:this.container}),this.status=i.create("span",{className:"visually-hidden",role:"status","aria-live":"assertive","aria-atomic":!0,inside:this.container,textContent:0!=this.minChars?"Type "+this.minChars+" or more characters for results.":"Begin typing for results."}),this._events={input:{input:this.evaluate.bind(this),blur:this.close.bind(this,{reason:"blur"}),keydown:function(t){var e=t.keyCode;s.opened&&(13===e&&s.selected?(t.preventDefault(),s.select()):9===e&&s.selected&&s.tabSelect?s.select():27===e?s.close({reason:"esc"}):38!==e&&40!==e||(t.preventDefault(),s[38===e?"previous":"next"]()))}},form:{submit:this.close.bind(this,{reason:"submit"})},ul:{mousedown:function(t){t.preventDefault()},click:function(t){var e=t.target;if(e!==this){for(;e&&!/li/i.test(e.nodeName);)e=e.parentNode;e&&0===t.button&&(t.preventDefault(),s.select(e,t.target))}}}},i.bind(this.input,this._events.input),i.bind(this.input.form,this._events.form),i.bind(this.ul,this._events.ul),this.input.hasAttribute("list")?(this.list="#"+this.input.getAttribute("list"),this.input.removeAttribute("list")):this.list=this.input.getAttribute("data-list")||n.list||[],r.all.push(this)};r.prototype={set list(t){if(Array.isArray(t))this._list=t;else if("string"==typeof t&&t.indexOf(",")>-1)this._list=t.split(/\s*,\s*/);else if((t=i(t))&&t.children){var e=[];o.apply(t.children).forEach(function(t){if(!t.disabled){var i=t.textContent.trim(),n=t.value||i,s=t.label||i;""!==n&&e.push({label:s,value:n})}}),this._list=e}document.activeElement===this.input&&this.evaluate()},get selected(){return this.index>-1},get opened(){return this.isOpened},close:function(t){this.opened&&(this.input.setAttribute("aria-expanded","false"),this.ul.setAttribute("hidden",""),this.isOpened=!1,this.index=-1,this.status.setAttribute("hidden",""),i.fire(this.input,"awesomplete-close",t||{}))},open:function(){this.input.setAttribute("aria-expanded","true"),this.ul.removeAttribute("hidden"),this.isOpened=!0,this.status.removeAttribute("hidden"),this.autoFirst&&-1===this.index&&this.goto(0),i.fire(this.input,"awesomplete-open")},destroy:function(){if(i.unbind(this.input,this._events.input),i.unbind(this.input.form,this._events.form),!this.options.container){var t=this.container.parentNode;t.insertBefore(this.input,this.container),t.removeChild(this.container)}this.input.removeAttribute("autocomplete"),this.input.removeAttribute("aria-autocomplete");var e=r.all.indexOf(this);-1!==e&&r.all.splice(e,1)},next:function(){var t=this.ul.children.length;this.goto(this.index<t-1?this.index+1:t?0:-1)},previous:function(){var t=this.ul.children.length,e=this.index-1;this.goto(this.selected&&-1!==e?e:t-1)},goto:function(t){var e=this.ul.children;this.selected&&e[this.index].setAttribute("aria-selected","false"),this.index=t,t>-1&&e.length>0&&(e[t].setAttribute("aria-selected","true"),this.status.textContent=e[t].textContent+", list item "+(t+1)+" of "+e.length,this.input.setAttribute("aria-activedescendant",this.ul.id+"_item_"+this.index),this.ul.scrollTop=e[t].offsetTop-this.ul.clientHeight+e[t].clientHeight,i.fire(this.input,"awesomplete-highlight",{text:this.suggestions[this.index]}))},select:function(t,e){if(t?this.index=i.siblingIndex(t):t=this.ul.children[this.index],t){var n=this.suggestions[this.index];i.fire(this.input,"awesomplete-select",{text:n,origin:e||t})&&(this.replace(n),this.close({reason:"select"}),i.fire(this.input,"awesomplete-selectcomplete",{text:n}))}},evaluate:function(){var e=this,i=this.input.value;i.length>=this.minChars&&this._list&&this._list.length>0?(this.index=-1,this.ul.innerHTML="",this.suggestions=this._list.map(function(n){return new t(e.data(n,i))}).filter(function(t){return e.filter(t,i)}),!1!==this.sort&&(this.suggestions=this.suggestions.sort(this.sort)),this.suggestions=this.suggestions.slice(0,this.maxItems),this.suggestions.forEach(function(t,n){e.ul.appendChild(e.item(t,i,n))}),0===this.ul.children.length?(this.status.textContent="No results found",this.close({reason:"nomatches"})):(this.open(),this.status.textContent=this.ul.children.length+" results found")):(this.close({reason:"nomatches"}),this.status.textContent="No results found")}},r.all=[],r.FILTER_CONTAINS=function(t,e){return RegExp(i.regExpEscape(e.trim()),"i").test(t)},r.FILTER_STARTSWITH=function(t,e){return RegExp("^"+i.regExpEscape(e.trim()),"i").test(t)},r.SORT_BYLENGTH=function(t,e){return t.length!==e.length?t.length-e.length:t<e?-1:1},r.CONTAINER=function(t){return i.create("div",{className:"awesomplete",around:t})},r.ITEM=function(t,e,n){return i.create("li",{innerHTML:""===e.trim()?t:t.replace(RegExp(i.regExpEscape(e.trim()),"gi"),"<mark>$&</mark>"),role:"option","aria-selected":"false",id:"awesomplete_list_"+this.count+"_item_"+n})},r.REPLACE=function(t){this.input.value=t.value},r.DATA=function(t){return t},Object.defineProperty(t.prototype=Object.create(String.prototype),"length",{get:function(){return this.label.length}}),t.prototype.toString=t.prototype.valueOf=function(){return""+this.label};var o=Array.prototype.slice;i.create=function(t,e){var n=document.createElement(t);for(var s in e){var r=e[s];if("inside"===s)i(r).appendChild(n);else if("around"===s){var o=i(r);o.parentNode.insertBefore(n,o),n.appendChild(o),null!=o.getAttribute("autofocus")&&o.focus()}else s in n?n[s]=r:n.setAttribute(s,r)}return n},i.bind=function(t,e){if(t)for(var i in e){var n=e[i];i.split(/\s+/).forEach(function(e){t.addEventListener(e,n)})}},i.unbind=function(t,e){if(t)for(var i in e){var n=e[i];i.split(/\s+/).forEach(function(e){t.removeEventListener(e,n)})}},i.fire=function(t,e,i){var n=document.createEvent("HTMLEvents");n.initEvent(e,!0,!0);for(var s in i)n[s]=i[s];return t.dispatchEvent(n)},i.regExpEscape=function(t){return t.replace(/[-\\^$*+?.()|[\]{}]/g,"\\$&")},i.siblingIndex=function(t){for(var e=0;t=t.previousElementSibling;e++);return e},"undefined"!=typeof self&&(self.Awesomplete=r),"undefined"!=typeof Document&&("loading"!==document.readyState?s():document.addEventListener("DOMContentLoaded",s)),r.$=i,r.$$=n,"object"==typeof module&&module.exports&&(module.exports=r)}();
!function(){function t(t){var e=Array.isArray(t)?{label:t[0],value:t[1]}:"object"==typeof t&&"label"in t&&"value"in t?t:{label:t,value:t};this.label=e.label||e.value,this.value=e.value}function e(t,e,i){for(var s in e){var n=e[s],r=t.input.getAttribute("data-"+s.toLowerCase());"number"==typeof n?t[s]=parseInt(r):!1===n?t[s]=null!==r:n instanceof Function?t[s]=null:t[s]=r,t[s]||0===t[s]||(t[s]=s in i?i[s]:n)}}function i(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function s(t,e){return o.call((e||document).querySelectorAll(t))}function n(){s("input.awesomplete").forEach(function(t){new r(t)})}var r=function(t,s){var n=this;r.count=(r.count||0)+1,this.count=r.count,this.isOpened=!1,this.input=i(t),this.input.setAttribute("autocomplete","off"),this.input.setAttribute("aria-autocomplete","list"),this.input.setAttribute("aria-expanded","false"),this.input.setAttribute("aria-owns","awesomplete_list_"+this.count),this.input.setAttribute("role","combobox"),this.options=s=s||{},e(this,{minChars:2,maxItems:10,autoFirst:!1,data:r.DATA,filter:r.FILTER_CONTAINS,sort:!1!==s.sort&&r.SORT_BYLENGTH,container:r.CONTAINER,item:r.ITEM,replace:r.REPLACE,tabSelect:!1,listLabel:"Results List",statusNoResults:"No results found",statusXResults:"{0} results found",statusTypeXChar:"Type {0} or more characters for results"},s),this.index=-1,this.container=this.container(t),this.ul=i.create("ul",{hidden:"hidden",role:"listbox",id:"awesomplete_list_"+this.count,inside:this.container,"aria-label":this.listLabel}),this.status=i.create("span",{className:"visually-hidden",role:"status","aria-live":"assertive","aria-atomic":!0,inside:this.container,textContent:""}),this._events={input:{input:this.evaluate.bind(this),blur:this.close.bind(this,{reason:"blur"}),keydown:function(t){var e=t.keyCode;n.opened&&(13===e&&n.selected?(t.preventDefault(),n.select(void 0,void 0,t)):9===e&&n.selected&&n.tabSelect?(t.preventDefault(),n.select(void 0,void 0,t)):27===e?n.close({reason:"esc"}):38!==e&&40!==e||(t.preventDefault(),n[38===e?"previous":"next"]()))}},form:{submit:this.close.bind(this,{reason:"submit"})},ul:{mousedown:function(t){t.preventDefault()},click:function(t){var e=t.target;if(e!==this){for(;e&&!/li/i.test(e.nodeName);)e=e.parentNode;e&&0===t.button&&(t.preventDefault(),n.select(e,t.target,t))}}}},i.bind(this.input,this._events.input),i.bind(this.input.form,this._events.form),i.bind(this.ul,this._events.ul),this.input.hasAttribute("list")?(this.list="#"+this.input.getAttribute("list"),this.input.removeAttribute("list")):this.list=this.input.getAttribute("data-list")||s.list||[],r.all.push(this)};r.prototype={set list(t){if(Array.isArray(t))this._list=t;else if("string"==typeof t&&t.indexOf(",")>-1)this._list=t.split(/\s*,\s*/);else if((t=i(t))&&t.children){var e=[];o.apply(t.children).forEach(function(t){if(!t.disabled){var i=t.textContent.trim(),s=t.value||i,n=t.label||i;""!==s&&e.push({label:n,value:s})}}),this._list=e}document.activeElement===this.input&&this.evaluate()},get selected(){return this.index>-1},get opened(){return this.isOpened},close:function(t){this.opened&&(this.input.setAttribute("aria-expanded","false"),this.ul.setAttribute("hidden",""),this.isOpened=!1,this.index=-1,this.status.setAttribute("hidden",""),i.fire(this.input,"awesomplete-close",t||{}))},open:function(){this.input.setAttribute("aria-expanded","true"),this.ul.removeAttribute("hidden"),this.isOpened=!0,this.status.removeAttribute("hidden"),this.autoFirst&&-1===this.index&&this.goto(0),i.fire(this.input,"awesomplete-open")},destroy:function(){if(i.unbind(this.input,this._events.input),i.unbind(this.input.form,this._events.form),!this.options.container){var t=this.container.parentNode;t.insertBefore(this.input,this.container),t.removeChild(this.container)}this.input.removeAttribute("autocomplete"),this.input.removeAttribute("aria-autocomplete"),this.input.removeAttribute("aria-expanded"),this.input.removeAttribute("aria-owns"),this.input.removeAttribute("role");var e=r.all.indexOf(this);-1!==e&&r.all.splice(e,1)},next:function(){var t=this.ul.children.length;this.goto(this.index<t-1?this.index+1:t?0:-1)},previous:function(){var t=this.ul.children.length,e=this.index-1;this.goto(this.selected&&-1!==e?e:t-1)},goto:function(t){var e=this.ul.children;this.selected&&e[this.index].setAttribute("aria-selected","false"),this.index=t,t>-1&&e.length>0&&(e[t].setAttribute("aria-selected","true"),this.input.setAttribute("aria-activedescendant",this.ul.id+"_item_"+this.index),this.ul.scrollTop=e[t].offsetTop-this.ul.clientHeight+e[t].clientHeight,i.fire(this.input,"awesomplete-highlight",{text:this.suggestions[this.index]}))},select:function(t,e,s){if(t?this.index=i.siblingIndex(t):t=this.ul.children[this.index],t){var n=this.suggestions[this.index];i.fire(this.input,"awesomplete-select",{text:n,origin:e||t,originalEvent:s})&&(this.replace(n),this.close({reason:"select"}),i.fire(this.input,"awesomplete-selectcomplete",{text:n,originalEvent:s}))}},evaluate:function(){var e=this,i=this.input.value;i.length>=this.minChars&&this._list&&this._list.length>0?(this.index=-1,this.ul.innerHTML="",this.suggestions=this._list.map(function(s){return new t(e.data(s,i))}).filter(function(t){return e.filter(t,i)}),!1!==this.sort&&(this.suggestions=this.suggestions.sort(this.sort)),this.suggestions=this.suggestions.slice(0,this.maxItems),this.suggestions.forEach(function(t,s){e.ul.appendChild(e.item(t,i,s))}),0===this.ul.children.length?(this.status.textContent=this.statusNoResults,this.close({reason:"nomatches"})):(this.open(),this.status.textContent=this.statusXResults.replaceAll("{0}",this.ul.children.length))):(this.close({reason:"nomatches"}),this.minChar<=1||i.length>=this.minChars?this.status.textContent=this.statusNoResults:this.status.textContent=this.statusTypeXChar.replaceAll("{0}",this.minChars))}},r.all=[],r.FILTER_CONTAINS=function(t,e){return RegExp(i.regExpEscape(e.trim()),"i").test(t)},r.FILTER_STARTSWITH=function(t,e){return RegExp("^"+i.regExpEscape(e.trim()),"i").test(t)},r.SORT_BYLENGTH=function(t,e){return t.length!==e.length?t.length-e.length:t<e?-1:1},r.CONTAINER=function(t){return i.create("div",{className:"awesomplete",around:t})},r.ITEM=function(t,e,s){return i.create("li",{innerHTML:""===e.trim()?t:t.replace(RegExp(i.regExpEscape(e.trim()),"gi"),"<mark>$&</mark>"),role:"option","aria-selected":"false",tabindex:"0",id:"awesomplete_list_"+this.count+"_item_"+s})},r.REPLACE=function(t){this.input.value=t.value},r.DATA=function(t){return t},Object.defineProperty(t.prototype=Object.create(String.prototype),"length",{get:function(){return this.label.length}}),t.prototype.toString=t.prototype.valueOf=function(){return""+this.label};var o=Array.prototype.slice;i.create=function(t,e){var s=document.createElement(t);for(var n in e){var r=e[n];if("inside"===n)i(r).appendChild(s);else if("around"===n){var o=i(r);o.parentNode.insertBefore(s,o),s.appendChild(o),null!=o.getAttribute("autofocus")&&o.focus()}else n in s?s[n]=r:s.setAttribute(n,r)}return s},i.bind=function(t,e){if(t)for(var i in e){var s=e[i];i.split(/\s+/).forEach(function(e){t.addEventListener(e,s)})}},i.unbind=function(t,e){if(t)for(var i in e){var s=e[i];i.split(/\s+/).forEach(function(e){t.removeEventListener(e,s)})}},i.fire=function(t,e,i){var s=document.createEvent("HTMLEvents");s.initEvent(e,!0,!0);for(var n in i)s[n]=i[n];return t.dispatchEvent(s)},i.regExpEscape=function(t){return t.replace(/[-\\^$*+?.()|[\]{}]/g,"\\$&")},i.siblingIndex=function(t){for(var e=0;t=t.previousElementSibling;e++);return e},"undefined"!=typeof self&&(self.Awesomplete=r),"undefined"!=typeof Document&&("loading"!==document.readyState?n():document.addEventListener("DOMContentLoaded",n)),r.$=i,r.$$=s,"object"==typeof module&&module.exports&&(module.exports=r)}();
//# sourceMappingURL=awesomplete.min.js.map
{
"name": "awesomplete",
"version": "1.1.5",
"version": "1.1.6",
"description": "http://leaverou.github.io/awesomplete/",
"main": "awesomplete.js",
"scripts": {
"release": "release-it",
"test": "karma start --single-run"

@@ -30,4 +31,8 @@ },

"karma-jasmine": "^0.3.6",
"karma-jasmine-def": "^0.1.0"
"karma-jasmine-def": "^0.1.0",
"release-it": "^17.6.0"
},
"overrides": {
"graceful-fs": "^4.2.11"
}
}

@@ -84,2 +84,12 @@ # Awesomplete

## Options
| JS Property | HTML Attribute | Description | Value | Default |
| ----------- | -------------- | ------------------------------------------------------------------------------- | ------- | ------------ |
| `list` | `data-list` | Where to find the list of suggestions. | Array of strings, HTML element, CSS selector (no groups, i.e. no commas), String containing a comma-separated list of items | N/A |
| `minChars` | `data-minchars` | Minimum characters the user has to type before the autocomplete popup shows up. | Number | `2` |
| `maxItems` | `data-maxitems` | Maximum number of suggestions to display. | Number | `10` |
| `autoFirst` | `data-autofirst` | Should the first element be automatically | Boolean | `false` |
| `listLabel` | `data-listlabel` | Denotes a label to be used as aria-label on the generated autocomplete list. | String | Results List |
## License

@@ -86,0 +96,0 @@

@@ -51,18 +51,4 @@ describe("awesomplete.goto", function () {

});
it("updates status", function () {
expect(this.subject.status.textContent).toBe("item1, list item 1 of 3");
});
});
describe("with item index = -1", function () {
beforeEach(function () {
this.subject.goto(0);
this.subject.goto(-1);
});
it("does not update status", function () {
expect(this.subject.status.textContent).toBe("item1, list item 1 of 3");
});
});
});

@@ -93,5 +93,5 @@ describe("keydown event", function () {

$.keydown(this.subject.input, $.k.TAB);
expect(this.subject.select).toHaveBeenCalled();
expect(this.subject.select.calls.mostRecent().args[2].defaultPrevented).toBe(true);
});
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc