@tarekraafat/autocomplete.js
Advanced tools
Comparing version 10.1.4 to 10.1.5
@@ -189,18 +189,2 @@ (function (global, factory) { | ||
var preInit = (function (ctx) { | ||
var callback = function callback(mutations, observer) { | ||
mutations.forEach(function (mutation) { | ||
if (ctx.input) { | ||
observer.disconnect(); | ||
ctx.init(); | ||
} | ||
}); | ||
}; | ||
var observer = new MutationObserver(callback); | ||
observer.observe(document, { | ||
childList: true, | ||
subtree: true | ||
}); | ||
}); | ||
var select$1 = function select(element) { | ||
@@ -645,5 +629,2 @@ return typeof element === "string" ? document.querySelector(element) : element; | ||
var prototype = autoComplete.prototype; | ||
prototype.preInit = function () { | ||
preInit(this); | ||
}; | ||
prototype.init = function () { | ||
@@ -656,2 +637,7 @@ init(this); | ||
prototype.unInit = function () { | ||
if (this.wrapper) { | ||
var parentNode = this.wrapper.parentNode; | ||
parentNode.insertBefore(this.input, this.wrapper); | ||
parentNode.removeChild(this.wrapper); | ||
} | ||
removeEvents(this); | ||
@@ -699,4 +685,3 @@ }; | ||
extend.call(this, autoComplete); | ||
var run = this.observe ? preInit : init; | ||
run(this); | ||
init(this); | ||
} | ||
@@ -703,0 +688,0 @@ |
@@ -1,1 +0,1 @@ | ||
var t,e;t=this,e=function(){"use strict";function t(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function e(e){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?t(Object(i),!0).forEach((function(t){r(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t){return function(t){if(Array.isArray(t))return s(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||o(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){if(t){if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var u,a=function(t){new MutationObserver((function(e,n){e.forEach((function(e){t.input&&(n.disconnect(),t.init())}))})).observe(document,{childList:!0,subtree:!0})},c=function(t){return"string"==typeof t?document.querySelector(t):t},l=function(t,e){var n="string"==typeof t?document.createElement(t):t;for(var r in e){var i=e[r];if("inside"===r)i.append(n);else if("dest"===r)c(i[0]).insertAdjacentElement(i[1],n);else if("around"===r){var o=c(i);o.parentNode.insertBefore(n,o),n.append(o),null!=o.getAttribute("autofocus")&&o.focus()}else r in n?n[r]=i:n.setAttribute(r,i)}return n},f=function(t,e){return t=t.toString().toLowerCase(),e?t.normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):t},p=function(t,n){return l("mark",e({innerHTML:t},"string"==typeof n&&{class:n})).outerHTML},d=function(t,e){e.input.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:e.feedback,cancelable:!0}))},h=function(t,e,n){var r=n||{},i=r.mode,o=r.diacritics,s=r.highlight,u=f(e,o);if(e=e.toString(),t=f(t,o),"loose"===i){var a=(t=t.replace(/ /g,"")).length,c=0,l=Array.from(e).map((function(e,n){return c<a&&u[n]===t[c]&&(e=s?p(e,s):e,c++),e})).join("");if(c===a)return l}else{var d=u.indexOf(t);if(~d)return t=e.substring(d,d+t.length),d=s?e.replace(t,p(t,s)):e}},m=function(t){return new Promise((function(e,n){var r,i,o;return r=t.input,i=t.query,(o=t.data).cache&&o.store?e():(i=i?i(r.value):r.value,new Promise((function(t,e){return"function"==typeof o.src?o.src(i).then(t,e):t(o.src)})).then((function(r){try{return t.feedback=o.store=r,d("response",t),e()}catch(t){return n(t)}}),n))}))},v=function(t,e){var n=e.data,r=e.searchEngine,i=e.diacritics,s=e.resultsList,u=e.resultItem,a=[];n.store.forEach((function(e,s){var c=function(n){var o=n?e[n]:e,s="function"==typeof r?r(t,o):h(t,o,{mode:r,diacritics:i,highlight:u.highlight});if(s){var c={match:s,value:e};n&&(c.key=n),a.push(c)}};if(n.keys){var l,f=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=o(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,u=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return u=t.done,t},e:function(t){a=!0,s=t},f:function(){try{u||null==n.return||n.return()}finally{if(a)throw s}}}}(n.keys);try{for(f.s();!(l=f.n()).done;)c(l.value)}catch(t){f.e(t)}finally{f.f()}}else c()})),n.filter&&(a=n.filter(a));var c=a.slice(0,s.maxResults);e.feedback={query:t,matches:a,results:c},d("results",e)},b="aria-expanded",y="aria-activedescendant",g="aria-selected",w=function(t,n){t.feedback.selection=e({index:n},t.feedback.results[n])},O=function(t){t.isOpen||((t.wrapper||t.input).setAttribute(b,!0),t.list.removeAttribute("hidden"),t.isOpen=!0,d("open",t))},A=function(t){t.isOpen&&((t.wrapper||t.input).setAttribute(b,!1),t.input.setAttribute(y,""),t.list.setAttribute("hidden",""),t.isOpen=!1,d("close",t))},S=function(t,e){var n=e.list.getElementsByTagName(e.resultItem.tag);if(e.isOpen&&n.length){var r,o,s=e.cursor;t>=n.length&&(t=0),t<0&&(t=n.length-1),e.cursor=t,s>-1&&(n[s].removeAttribute(g),u&&(o=n[s].classList).remove.apply(o,i(u))),n[t].setAttribute(g,!0),u&&(r=n[t].classList).add.apply(r,i(u)),e.input.setAttribute(y,n[e.cursor].id),e.list.scrollTop=n[t].offsetTop-e.list.clientHeight+n[t].clientHeight+5,e.feedback.cursor=e.cursor,w(e,t),d("navigate",e)}},L=function(t){var e=t.cursor+1;S(e,t)},j=function(t){var e=t.cursor-1;S(e,t)},k=function(t,e,n){(n=n>=0?n:t.cursor)<0||(t.feedback.event=e,w(t,n),d("selection",t),A(t))};function E(t){var n=this;return new Promise((function(r,i){var o,s,u,a,c,f,p;return o=t.input,s=t.query,u=t.trigger,a=t.threshold,c=t.resultsList,f=(p=o)instanceof HTMLInputElement||p instanceof HTMLTextAreaElement?p.value:p.innerHTML,function(t,e,n){return e?e(t):t.length>=n}(f=s?s(f):f,u,a)?m(t).then((function(o){try{return t.feedback instanceof Error?r():(v(f,t),c&&function(t){var n=t.resultsList,r=t.list,i=t.resultItem,o=t.feedback;o.query;var s=o.matches,u=o.results;if(t.cursor=-1,r.innerHTML="",s.length||n.noResults){var a=document.createDocumentFragment();u.forEach((function(t,n){var r=l(i.tag,e({id:"".concat(i.id,"_").concat(n),role:"option",innerHTML:t.match,inside:a},i.class&&{class:i.class}));i.element&&i.element(r,t)})),r.append(a),n.element&&n.element(r,o),O(t)}else A(t)}(t),d.call(n))}catch(t){return i(t)}}),i):(A(t),d.call(n));function d(){return r()}}))}var T=function(t,e){for(var n in t)for(var r in t[n])e(r,n)},I=function(t){var n=t.events;t.trigger;var r=t.debounce,i=t.resultsList,o=function(t,e){var n;return function(){clearTimeout(n),n=setTimeout((function(){return t()}),e)}}((function(){return E(t)}),r),s=t.events=e({input:e({},n&&n.input)},i&&{list:n?e({},n.list):{}}),a={input:{input:function(){o()},keydown:function(e){!function(t,e){var n=t.keyCode,r=e.resultItem.selected;switch(r&&(u=r.split(" ")),n){case 40:case 38:t.preventDefault(),40===n?L(e):j(e);break;case 13:t.preventDefault(),e.cursor>=0&&k(e,t);break;case 9:e.resultsList.tabSelect&&e.cursor>=0?(t.preventDefault(),k(e,t)):A(e);break;case 27:t.preventDefault(),e.input.value="",A(e)}}(e,t)},blur:function(){A(t)}},list:{mousedown:function(t){t.preventDefault()},click:function(e){!function(t,e){var n=e.resultItem.tag.toUpperCase(),r=Array.from(e.list.querySelectorAll(n)),i=t.target.closest(n);if(i&&i.nodeName===n){t.preventDefault();var o=r.indexOf(i);k(e,t,o)}}(e,t)}}};T(a,(function(t,e){(i||"list"!==e)&&(s[e][t]||(s[e][t]=a[e][t]))})),T(s,(function(e,n){t[n].addEventListener(e,s[n][e])}))};function x(t){var n=this;return new Promise((function(r,i){var o,s,u,a,c,f;if(o=t.name,s=t.input,u=t.placeHolder,a=t.resultsList,c=t.data,f={role:"combobox","aria-owns":a.id,"aria-haspopup":!0,"aria-expanded":!1},l(s,e(e({"aria-controls":a.id,"aria-autocomplete":"both"},u&&{placeholder:u}),!t.wrapper&&e({},f))),t.wrapper&&(t.wrapper=l("div",e({around:s,class:o+"_wrapper"},f))),a&&(t.list=l(a.tag,e({dest:["string"==typeof a.destination?document.querySelector(a.destination):a.destination(),a.position],id:a.id,role:"listbox",hidden:"hidden"},a.class&&{class:a.class}))),c.cache)return m(t).then((function(t){try{return p.call(n)}catch(t){return i(t)}}),i);function p(){return I(t),d("init",t),r()}return p.call(n)}))}function P(t){var e=t.prototype;e.preInit=function(){a(this)},e.init=function(){x(this)},e.start=function(){E(this)},e.unInit=function(){var t;T((t=this).events,(function(e,n){t[n].removeEventListener(e,t.events[n][e])}))},e.open=function(){O(this)},e.close=function(){A(this)},e.goTo=function(t){S(t,this)},e.next=function(){L(this)},e.previous=function(){j(this)},e.select=function(t){k(this,null,t)},t.search=e.search=function(t,e,n){h(t,e,n)}}return function t(e){this.options=e,this.id=t.instances=(t.instances||0)+1,this.name="autoComplete",this.wrapper=1,this.threshold=1,this.debounce=0,this.resultsList={position:"afterend",tag:"ul",maxResults:5},this.resultItem={tag:"li"},function(t){var e=t.id,r=t.name,i=t.options,o=t.resultsList,s=t.resultItem;for(var u in i)if("object"===n(i[u]))for(var a in t[u]||(t[u]={}),i[u])t[u][a]=i[u][a];else t[u]=i[u];t.selector=t.selector||"#"+r,o.destination=o.destination||t.selector,o.id=o.id||r+"_list_"+e,s.id=s.id||r+"_result",t.input="string"==typeof t.selector?document.querySelector(t.selector):t.selector()}(this),P.call(this,t),(this.observe?a:x)(this)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).autoComplete=e(); | ||
var e,t;e=this,t=function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?e(Object(i),!0).forEach((function(e){r(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||o(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var a,u=function(e){return"string"==typeof e?document.querySelector(e):e},c=function(e,t){var n="string"==typeof e?document.createElement(e):e;for(var r in t){var i=t[r];if("inside"===r)i.append(n);else if("dest"===r)u(i[0]).insertAdjacentElement(i[1],n);else if("around"===r){var o=u(i);o.parentNode.insertBefore(n,o),n.append(o),null!=o.getAttribute("autofocus")&&o.focus()}else r in n?n[r]=i:n.setAttribute(r,i)}return n},l=function(e,t){return e=e.toString().toLowerCase(),t?e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):e},f=function(e,n){return c("mark",t({innerHTML:e},"string"==typeof n&&{class:n})).outerHTML},p=function(e,t){t.input.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:t.feedback,cancelable:!0}))},d=function(e,t,n){var r=n||{},i=r.mode,o=r.diacritics,s=r.highlight,a=l(t,o);if(t=t.toString(),e=l(e,o),"loose"===i){var u=(e=e.replace(/ /g,"")).length,c=0,p=Array.from(t).map((function(t,n){return c<u&&a[n]===e[c]&&(t=s?f(t,s):t,c++),t})).join("");if(c===u)return p}else{var d=a.indexOf(e);if(~d)return e=t.substring(d,d+e.length),d=s?t.replace(e,f(e,s)):t}},h=function(e){return new Promise((function(t,n){var r,i,o;return r=e.input,i=e.query,(o=e.data).cache&&o.store?t():(i=i?i(r.value):r.value,new Promise((function(e,t){return"function"==typeof o.src?o.src(i).then(e,t):e(o.src)})).then((function(r){try{return e.feedback=o.store=r,p("response",e),t()}catch(e){return n(e)}}),n))}))},m=function(e,t){var n=t.data,r=t.searchEngine,i=t.diacritics,s=t.resultsList,a=t.resultItem,u=[];n.store.forEach((function(t,s){var c=function(n){var o=n?t[n]:t,s="function"==typeof r?r(e,o):d(e,o,{mode:r,diacritics:i,highlight:a.highlight});if(s){var c={match:s,value:t};n&&(c.key=n),u.push(c)}};if(n.keys){var l,f=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=o(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw s}}}}(n.keys);try{for(f.s();!(l=f.n()).done;)c(l.value)}catch(e){f.e(e)}finally{f.f()}}else c()})),n.filter&&(u=n.filter(u));var c=u.slice(0,s.maxResults);t.feedback={query:e,matches:u,results:c},p("results",t)},v="aria-expanded",y="aria-activedescendant",b="aria-selected",g=function(e,n){e.feedback.selection=t({index:n},e.feedback.results[n])},w=function(e){e.isOpen||((e.wrapper||e.input).setAttribute(v,!0),e.list.removeAttribute("hidden"),e.isOpen=!0,p("open",e))},O=function(e){e.isOpen&&((e.wrapper||e.input).setAttribute(v,!1),e.input.setAttribute(y,""),e.list.setAttribute("hidden",""),e.isOpen=!1,p("close",e))},A=function(e,t){var n=t.list.getElementsByTagName(t.resultItem.tag);if(t.isOpen&&n.length){var r,o,s=t.cursor;e>=n.length&&(e=0),e<0&&(e=n.length-1),t.cursor=e,s>-1&&(n[s].removeAttribute(b),a&&(o=n[s].classList).remove.apply(o,i(a))),n[e].setAttribute(b,!0),a&&(r=n[e].classList).add.apply(r,i(a)),t.input.setAttribute(y,n[t.cursor].id),t.list.scrollTop=n[e].offsetTop-t.list.clientHeight+n[e].clientHeight+5,t.feedback.cursor=t.cursor,g(t,e),p("navigate",t)}},S=function(e){var t=e.cursor+1;A(t,e)},j=function(e){var t=e.cursor-1;A(t,e)},k=function(e,t,n){(n=n>=0?n:e.cursor)<0||(e.feedback.event=t,g(e,n),p("selection",e),O(e))};function L(e){var n=this;return new Promise((function(r,i){var o,s,a,u,l,f,p;return o=e.input,s=e.query,a=e.trigger,u=e.threshold,l=e.resultsList,f=(p=o)instanceof HTMLInputElement||p instanceof HTMLTextAreaElement?p.value:p.innerHTML,function(e,t,n){return t?t(e):e.length>=n}(f=s?s(f):f,a,u)?h(e).then((function(o){try{return e.feedback instanceof Error?r():(m(f,e),l&&function(e){var n=e.resultsList,r=e.list,i=e.resultItem,o=e.feedback;o.query;var s=o.matches,a=o.results;if(e.cursor=-1,r.innerHTML="",s.length||n.noResults){var u=document.createDocumentFragment();a.forEach((function(e,n){var r=c(i.tag,t({id:"".concat(i.id,"_").concat(n),role:"option",innerHTML:e.match,inside:u},i.class&&{class:i.class}));i.element&&i.element(r,e)})),r.append(u),n.element&&n.element(r,o),w(e)}else O(e)}(e),d.call(n))}catch(e){return i(e)}}),i):(O(e),d.call(n));function d(){return r()}}))}var T=function(e,t){for(var n in e)for(var r in e[n])t(r,n)},E=function(e){var n=e.events;e.trigger;var r=e.debounce,i=e.resultsList,o=function(e,t){var n;return function(){clearTimeout(n),n=setTimeout((function(){return e()}),t)}}((function(){return L(e)}),r),s=e.events=t({input:t({},n&&n.input)},i&&{list:n?t({},n.list):{}}),u={input:{input:function(){o()},keydown:function(t){!function(e,t){var n=e.keyCode,r=t.resultItem.selected;switch(r&&(a=r.split(" ")),n){case 40:case 38:e.preventDefault(),40===n?S(t):j(t);break;case 13:e.preventDefault(),t.cursor>=0&&k(t,e);break;case 9:t.resultsList.tabSelect&&t.cursor>=0?(e.preventDefault(),k(t,e)):O(t);break;case 27:e.preventDefault(),t.input.value="",O(t)}}(t,e)},blur:function(){O(e)}},list:{mousedown:function(e){e.preventDefault()},click:function(t){!function(e,t){var n=t.resultItem.tag.toUpperCase(),r=Array.from(t.list.querySelectorAll(n)),i=e.target.closest(n);if(i&&i.nodeName===n){e.preventDefault();var o=r.indexOf(i);k(t,e,o)}}(t,e)}}};T(u,(function(e,t){(i||"list"!==t)&&(s[t][e]||(s[t][e]=u[t][e]))})),T(s,(function(t,n){e[n].addEventListener(t,s[n][t])}))};function x(e){var n=this;return new Promise((function(r,i){var o,s,a,u,l,f;if(o=e.name,s=e.input,a=e.placeHolder,u=e.resultsList,l=e.data,f={role:"combobox","aria-owns":u.id,"aria-haspopup":!0,"aria-expanded":!1},c(s,t(t({"aria-controls":u.id,"aria-autocomplete":"both"},a&&{placeholder:a}),!e.wrapper&&t({},f))),e.wrapper&&(e.wrapper=c("div",t({around:s,class:o+"_wrapper"},f))),u&&(e.list=c(u.tag,t({dest:["string"==typeof u.destination?document.querySelector(u.destination):u.destination(),u.position],id:u.id,role:"listbox",hidden:"hidden"},u.class&&{class:u.class}))),l.cache)return h(e).then((function(e){try{return d.call(n)}catch(e){return i(e)}}),i);function d(){return E(e),p("init",e),r()}return d.call(n)}))}function I(e){var t=e.prototype;t.init=function(){x(this)},t.start=function(){L(this)},t.unInit=function(){if(this.wrapper){var e=this.wrapper.parentNode;e.insertBefore(this.input,this.wrapper),e.removeChild(this.wrapper)}var t;T((t=this).events,(function(e,n){t[n].removeEventListener(e,t.events[n][e])}))},t.open=function(){w(this)},t.close=function(){O(this)},t.goTo=function(e){A(e,this)},t.next=function(){S(this)},t.previous=function(){j(this)},t.select=function(e){k(this,null,e)},e.search=t.search=function(e,t,n){d(e,t,n)}}return function e(t){this.options=t,this.id=e.instances=(e.instances||0)+1,this.name="autoComplete",this.wrapper=1,this.threshold=1,this.debounce=0,this.resultsList={position:"afterend",tag:"ul",maxResults:5},this.resultItem={tag:"li"},function(e){var t=e.id,r=e.name,i=e.options,o=e.resultsList,s=e.resultItem;for(var a in i)if("object"===n(i[a]))for(var u in e[a]||(e[a]={}),i[a])e[a][u]=i[a][u];else e[a]=i[a];e.selector=e.selector||"#"+r,o.destination=o.destination||e.selector,o.id=o.id||r+"_list_"+t,s.id=s.id||r+"_result",e.input="string"==typeof e.selector?document.querySelector(e.selector):e.selector()}(this),I.call(this,e),x(this)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).autoComplete=t(); |
{ | ||
"version": "10.1.4", | ||
"version": "10.1.5", | ||
"name": "@tarekraafat/autocomplete.js", | ||
@@ -4,0 +4,0 @@ "description": "Simple autocomplete pure vanilla Javascript library.", |
@@ -26,3 +26,3 @@ # autoComplete.js :sparkles: | ||
autoComplete.js is a simple pure vanilla Javascript library that's progressively designed for speed, high versatility and seamless integration with a wide range of projects & systems. <sub><sup>(Made for a better developer experience)</sub></pub> | ||
autoComplete.js is a simple, pure vanilla Javascript library progressively designed for speed, high versatility, and seamless integration with a wide range of projects & systems. <sub><sup>(Made for a better developer experience)</sub></pub> | ||
@@ -51,3 +51,3 @@ ## Features | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.1.4/dist/autoComplete.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.1.5/dist/autoComplete.min.js"></script> | ||
``` | ||
@@ -58,3 +58,3 @@ | ||
```html | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.1.4/dist/css/autoComplete.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.1.5/dist/css/autoComplete.min.css"> | ||
``` | ||
@@ -61,0 +61,0 @@ #### Package Manager |
import configure from "./services/configure"; | ||
import extend from "./services/extend"; | ||
import preInit from "./services/preInit"; | ||
import init from "./services/init"; | ||
@@ -69,6 +68,4 @@ | ||
extend.call(this, autoComplete); | ||
// Set to run "preInit" if "observer" enabled else "init" | ||
const run = this.observe ? preInit : init; | ||
// Run autoComplete.js | ||
run(this); | ||
// Initialize autoComplete.js | ||
init(this); | ||
} |
@@ -276,3 +276,3 @@ import { create } from "../helpers/io"; | ||
// Clear "inputField" value | ||
// Clear "input" value | ||
ctx.input.value = ""; | ||
@@ -279,0 +279,0 @@ |
@@ -8,4 +8,4 @@ /** | ||
export default (name, ctx) => { | ||
// Dispatch event on "inputField" | ||
// Dispatch event on "input" | ||
ctx.input.dispatchEvent(new CustomEvent(name, { bubbles: true, detail: ctx.feedback, cancelable: true })); | ||
}; |
@@ -47,3 +47,3 @@ /** | ||
/** | ||
* Get the "inputField" query value | ||
* Get the "input" query value | ||
* | ||
@@ -63,3 +63,3 @@ * @param {Element} field - input or textarea element | ||
* | ||
* @returns {String} - Raw "inputField" value as a string | ||
* @returns {String} - Raw "input" value as a string | ||
*/ | ||
@@ -66,0 +66,0 @@ const format = (value, diacritics) => { |
@@ -1,2 +0,1 @@ | ||
import preInit from "./preInit"; | ||
import init from "./init"; | ||
@@ -16,7 +15,2 @@ import start from "./start"; | ||
// Pre-Initialize autoComplete.js engine | ||
prototype.preInit = function () { | ||
preInit(this); | ||
}; | ||
// Initialize autoComplete.js engine | ||
@@ -34,2 +28,9 @@ prototype.init = function () { | ||
prototype.unInit = function () { | ||
if (this.wrapper) { | ||
const parentNode = this.wrapper.parentNode; | ||
parentNode.insertBefore(this.input, this.wrapper); | ||
parentNode.removeChild(this.wrapper); | ||
} | ||
removeEvents(this); | ||
@@ -36,0 +37,0 @@ }; |
@@ -21,3 +21,3 @@ import { create } from "../helpers/io"; | ||
// Set "inputField" attributes | ||
// Set "input" attributes | ||
create(input, { | ||
@@ -24,0 +24,0 @@ "aria-controls": resultsList.id, |
@@ -13,3 +13,3 @@ import { getQuery, checkTrigger } from "../helpers/io"; | ||
// Get "inputField" query value | ||
// Get "input" query value | ||
let queryVal = getQuery(input); | ||
@@ -16,0 +16,0 @@ queryVal = query ? query(queryVal) : queryVal; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97559
23
1740