/** * Tagify (v 2.22.3)- tags input component * By Yair Even-Or * Don't sell this code. (c) * https://github.com/yairEO/tagify */ "use strict"; function _toConsumableArray(t) { return _arrayWithoutHoles(t) || _iterableToArray(t) || _nonIterableSpread() } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance") } function _iterableToArray(t) { if (Symbol.iterator in Object(t) || "[object Arguments]" === Object.prototype.toString.call(t)) return Array.from(t) } function _arrayWithoutHoles(t) { if (Array.isArray(t)) { for (var e = 0, i = new Array(t.length); e < t.length; e++) i[e] = t[e]; return i } } function ownKeys(e, t) { var i = Object.keys(e); return Object.getOwnPropertySymbols && i.push.apply(i, Object.getOwnPropertySymbols(e)), t && (i = i.filter(function (t) { return Object.getOwnPropertyDescriptor(e, t) .enumerable })), i } function _objectSpread(e) { for (var i = 1; i < arguments.length; i++) if (i % 2) { var n = null != arguments[i] ? arguments[i] : {}; ownKeys(n, !0) .forEach(function (t) { _defineProperty(e, t, n[t]) }) } else Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(arguments[i])) : ownKeys(n) .forEach(function (t) { Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(arguments[i], t)) }); return e } function _defineProperty(t, e, i) { return e in t ? Object.defineProperty(t, e, { value: i , enumerable: !0 , configurable: !0 , writable: !0 }) : t[e] = i, t }! function (o) { function n(t, e) { if (!t) return console.warn("Tagify: ", "invalid input element ", t), this; this.applySettings(t, e), this.state = {}, this.value = [], this.listeners = {}, this.DOM = {}, this.extend(this, new this.EventDispatcher(this)), this.build(t), this.loadOriginalValues(), this.events.customBinding.call(this), this.events.binding.call(this), t.autofocus && this.DOM.input.focus() } o.fn.tagify = function () { var i = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {}; return this.each(function () { var t, e = o(this); if (e.data("tagify")) return this; i.isJQueryPlugin = !0, t = new n(e[0], i), e.data("tagify", t) }) }, n.prototype = { isIE: window.document.documentMode , TEXTS: { empty: "empty" , exceed: "number of tags exceeded" , pattern: "pattern mismatch" , duplicate: "already exists" , notAllowed: "not allowed" } , DEFAULTS: { delimiters: "," , pattern: null , maxTags: 1 / 0 , callbacks: {} , addTagOnBlur: !0 , duplicates: !1 , whitelist: [] , blacklist: [] , enforceWhitelist: !1 , keepInvalidTags: !1 , autoComplete: !0 , mixTagsAllowedAfter: /,|\.|\:|\s/ , backspace: !0 , skipInvalid: !1 , transformTag: function () {} , dropdown: { classname: "" , enabled: 2 , maxItems: 10 , itemTemplate: "" , fuzzySearch: !0 } } , templates: { wrapper: function (t, e) { return '') } , tag: function (t, e) { return "\n \n
\n ") .concat(t, "\n
\n
") } , dropdownItem: function (t) { var e = (t.value || t) .replace(/`|'/g, "'"); return "") } } , customEventsList: ["click", "add", "remove", "invalid", "input", "edit"] , applySettings: function (t, e) { var i = t.getAttribute("data-whitelist") , n = t.getAttribute("data-blacklist"); if (this.DEFAULTS.templates = this.templates, this.DEFAULTS.dropdown.itemTemplate = this.templates.dropdownItem, this.settings = this.extend({}, this.DEFAULTS, e), this.settings.readonly = t.hasAttribute("readonly"), this.isIE && (this.settings.autoComplete = !1), n && (n = n.split(this.settings.delimiters)) instanceof Array && (this.settings.blacklist = n), i && (i = i.split(this.settings.delimiters)) instanceof Array && (this.settings.whitelist = i), t.pattern) try { this.settings.pattern = new RegExp(t.pattern) } catch (t) {} if (this.settings && this.settings.delimiters) try { this.settings.delimiters = new RegExp(this.settings.delimiters, "g") } catch (t) {} } , parseHTML: function (t) { return (new DOMParser) .parseFromString(t.trim(), "text/html") .body.firstElementChild } , escapeHTML: function (t) { var e = document.createTextNode(t) , i = document.createElement("p"); return i.appendChild(e), i.innerHTML } , build: function (t) { var e = this.DOM , i = this.settings.templates.wrapper(t, this.settings); e.originalInput = t, e.scope = this.parseHTML(i), e.input = e.scope.querySelector("[contenteditable]"), t.parentNode.insertBefore(e.scope, t), 0 <= this.settings.dropdown.enabled && this.dropdown.init.call(this) } , destroy: function () { this.DOM.scope.parentNode.removeChild(this.DOM.scope), this.dropdown.hide.call(this, !0) } , loadOriginalValues: function (t) { var e = 0 < arguments.length && void 0 !== t ? t : this.DOM.originalInput.value; if (e) { this.removeAllTags(); try { e = JSON.parse(e) } catch (t) {} "mix" == this.settings.mode ? this.parseMixTags(e) : this.addTags(e) .forEach(function (t) { t && t.classList.add("tagify--noAnim") }) } } , extend: function (t, e, i) { function n(t) { var e = Object.prototype.toString.call(t) .split(" ")[1].slice(0, -1); return t === Object(t) && "Array" != e && "Function" != e && "RegExp" != e && "HTMLUnknownElement" != e } function s(t, e) { for (var i in e) e.hasOwnProperty(i) && (n(e[i]) ? n(t[i]) ? s(t[i], e[i]) : t[i] = Object.assign({}, e[i]) : t[i] = e[i]) } return t instanceof Object || (t = {}), s(t, e), i && s(t, i), t } , EventDispatcher: function (n) { var s = document.createTextNode(""); this.off = function (t, e) { return e && s.removeEventListener.call(s, t, e), this }, this.on = function (t, e) { return e && s.addEventListener.call(s, t, e), this }, this.trigger = function (t, e) { var i; if (t) if (n.settings.isJQueryPlugin) o(n.DOM.originalInput) .triggerHandler(t, [e]); else { try { i = new CustomEvent(t, { detail: e }) } catch (t) { console.warn(t) } s.dispatchEvent(i) } } } , events: { customBinding: function () { var e = this; this.customEventsList.forEach(function (t) { e.on(t, e.settings.callbacks[t]) }) } , binding: function (t) { var e, i = !(0 < arguments.length && void 0 !== t) || t , n = this.events.callbacks , s = i ? "addEventListener" : "removeEventListener"; for (var a in i && !this.listeners.main && (this.DOM.input.addEventListener(this.isIE ? "keydown" : "input", n[this.isIE ? "onInputIE" : "onInput"].bind(this)), this.settings.isJQueryPlugin && o(this.DOM.originalInput) .on("tagify.removeAllTags", this.removeAllTags.bind(this))), e = this.listeners.main = this.listeners.main || { paste: ["input", n.onPaste.bind(this)] , focus: ["input", n.onFocusBlur.bind(this)] , blur: ["input", n.onFocusBlur.bind(this)] , keydown: ["input", n.onKeydown.bind(this)] , click: ["scope", n.onClickScope.bind(this)] , dblclick: ["scope", n.onDoubleClickScope.bind(this)] }) this.DOM[e[a][0]][s](a, e[a][1]) } , callbacks: { onFocusBlur: function (t) { var e = t.target.textContent.trim(); "mix" != this.settings.mode && ("focus" == t.type ? (this.DOM.scope.classList.add("tagify--focus"), 0 === this.settings.dropdown.enabled && this.dropdown.show.call(this)) : "blur" == t.type ? (this.DOM.scope.classList.remove("tagify--focus"), e && this.settings.addTagOnBlur && this.addTags(e, !0) .length) : (this.DOM.input.removeAttribute("style"), this.dropdown.hide.call(this))) } , onKeydown: function (t) { var e, i = this , n = t.target.textContent; if ("mix" == this.settings.mode) { switch (t.key) { case "Delete": case "Backspace": var s = []; e = this.DOM.input.children, setTimeout(function () { [].forEach.call(e, function (t) { return s.push(t.getAttribute("value")) }), i.value = i.value.filter(function (t) { return -1 != s.indexOf(t.value) }) }, 20); break; case "Enter": t.preventDefault() } return !0 } switch (t.key) { case "Backspace": "" != n && 8203 != n.charCodeAt(0) || (!0 === this.settings.backspace ? this.removeTag() : "edit" == this.settings.backspace && this.editTag()); break; case "Esc": case "Escape": this.input.set.call(this), t.target.blur(); break; case "ArrowRight": case "Tab": if (!n) return !0; case "Enter": t.preventDefault(), this.addTags(this.input.value || n, !0) } } , onInput: function (t) { var e = this.input.normalize.call(this) , i = e.length >= this.settings.dropdown.enabled , n = { value: e , inputElm: this.DOM.input }; if ("mix" == this.settings.mode) return this.events.callbacks.onMixTagsInput.call(this, t); e ? this.input.value != e && (n.isValid = this.validateTag.call(this, e), this.input.set.call(this, e, !1), this.trigger("input", n), -1 != e.search(this.settings.delimiters) ? this.addTags(e) .length && this.input.set.call(this) : 0 <= this.settings.dropdown.enabled && this.dropdown[i ? "show" : "hide"].call(this, e)) : this.input.set.call(this, "") } , onMixTagsInput: function (t) { var e, i, n, s, a; if (this.maxTagsReached()) return !0; window.getSelection && 0 < (e = window.getSelection()) .rangeCount && ((i = e.getRangeAt(0) .cloneRange()) .collapse(!0), i.setStart(window.getSelection() .focusNode, 0), (s = (n = i.toString() .split(this.settings.mixTagsAllowedAfter))[n.length - 1].match(this.settings.pattern)) && (this.state.tag = { value: s[0] }, s = this.state.tag, a = this.state.tag.value.length >= this.settings.dropdown.enabled)), this.update(), this.trigger("input", this.extend({}, this.state.tag, { textContent: this.DOM.input.textContent })), this.state.tag && this.dropdown[a ? "show" : "hide"].call(this, this.state.tag.value) } , onInputIE: function (t) { var e = this; setTimeout(function () { e.events.callbacks.onInput.call(e, t) }) } , onPaste: function (t) {} , onClickScope: function (t) { var e, i = t.target.closest("tag"); "TAGS" == t.target.tagName ? this.DOM.input.focus() : "X" == t.target.tagName ? this.removeTag(t.target.parentNode) : i && (e = this.getNodeIndex(i), this.trigger("click", { tag: i , index: e , data: this.value[e] })) } , onEditTagInput: function (t) { var e = t.closest("tag") , i = this.getNodeIndex(e) , n = this.input.normalize(t) , s = n.toLowerCase() == t.originalValue.toLowerCase() || this.validateTag(n); e.classList.toggle("tagify--invalid", !0 !== s), e.isValid = s, this.trigger("input", { tag: e , index: i , data: this.extend({}, this.value[i], { newValue: n }) }) } , onEditTagBlur: function (t) { var e, i = t.closest("tag") , n = this.getNodeIndex(i) , s = this.input.normalize(t) || t.originalValue , a = this.input.normalize(t) != t.originalValue , o = i.isValid , r = _objectSpread({}, this.value[n], { value: s }); a && (this.settings.transformTag.call(this, r), o = this.validateTag(r.value)), void 0 !== o && !0 !== o || (t.textContent = r.value, this.value[n].value = r.value, this.update(), (e = t.cloneNode(!0)) .removeAttribute("contenteditable"), i.title = r.value, i.classList.remove("tagify--editable"), t.parentNode.replaceChild(e, t), this.trigger("edit", { tag: i , index: n , data: this.value[n] })) } , onEditTagkeydown: function (t) { switch (t.key) { case "Esc": case "Escape": t.target.textContent = t.target.originalValue; case "Enter": case "Tab": t.preventDefault(), t.target.blur() } } , onDoubleClickScope: function (t) { var e = t.target.closest("tag") , i = this.settings , n = e.classList.contains("tagify--editable") , s = e.hasAttribute("readonly"); "mix" == i.mode || i.readonly || i.enforceWhitelist || !e || n || s || this.editTag(e) } } } , editTag: function (t) { var e = this , i = 0 < arguments.length && void 0 !== t ? t : this.getLastTag() , n = i.querySelector(".tagify__tag-text") , s = this.events.callbacks; n ? (i.classList.add("tagify--editable"), n.originalValue = n.textContent, n.setAttribute("contenteditable", !0), n.addEventListener("blur", s.onEditTagBlur.bind(this, n)), n.addEventListener("input", s.onEditTagInput.bind(this, n)), n.addEventListener("keydown", function (t) { return s.onEditTagkeydown.call(e, t) }), n.focus()) : console.warn("Cannot find element in Tag template: ", ".tagify__tag-text") } , input: { value: "" , set: function (t, e) { var i = 0 < arguments.length && void 0 !== t ? t : "" , n = !(1 < arguments.length && void 0 !== e) || e; this.input.value = i, n && (this.DOM.input.innerHTML = i), i || this.dropdown.hide.call(this), i.length < 2 && this.input.autocomplete.suggest.call(this, ""), this.input.validate.call(this) } , setRangeAtStartEnd: function (t, e) { var i, n, s = 0 < arguments.length && void 0 !== t && t , a = 1 < arguments.length ? e : void 0; document.createRange && ((i = document.createRange()) .selectNodeContents(a || this.DOM.input), i.collapse(s), (n = window.getSelection()) .removeAllRanges(), n.addRange(i)) } , validate: function () { var t = !this.input.value || this.validateTag.call(this, this.input.value); this.DOM.input.classList.toggle("tagify__input--invalid", !0 !== t) } , normalize: function (t) { var e = (0 < arguments.length && void 0 !== t ? t : this.DOM.input) .innerText; return "settings" in this && this.settings.delimiters && (e = e.replace(/(?:\r\n|\r|\n)/g, this.settings.delimiters.source.charAt(1))), e = e.replace(/\s/g, " ") .replace(/^\s+/, "") } , autocomplete: { suggest: function (t) { t && this.input.value ? this.DOM.input.setAttribute("data-suggest", t.substring(this.input.value.length)) : this.DOM.input.removeAttribute("data-suggest") } , set: function (t) { var e = this.DOM.input.getAttribute("data-suggest") , i = t || (e ? this.input.value + e : null); return !!i && (this.input.set.call(this, i), this.input.autocomplete.suggest.call(this, ""), this.dropdown.hide.call(this), this.input.setRangeAtStartEnd.call(this), !0) } } } , getNodeIndex: function (t) { var e = 0; if (t) for (; t = t.previousElementSibling;) e++; return e } , getTagElms: function () { return this.DOM.scope.querySelectorAll("tag") } , getLastTag: function () { var t = this.DOM.scope.querySelectorAll("tag:not(.tagify--hide):not([readonly])"); return t[t.length - 1] } , isTagDuplicate: function (e) { return this.value.findIndex(function (t) { return e.trim() .toLowerCase() === t.value.toLowerCase() }) } , getTagIndexByValue: function (i) { var n = []; return this.getTagElms() .forEach(function (t, e) { t.textContent.trim() .toLowerCase() == i.toLowerCase() && n.push(e) }), n } , getTagElmByValue: function (t) { var e = this.getTagIndexByValue(t)[0]; return this.getTagElms()[e] } , markTagByValue: function (t, e) { return !!(e = e || this.getTagElmByValue(t)) && (e.classList.add("tagify--mark"), e) } , isTagBlacklisted: function (e) { return e = e.toLowerCase() .trim(), this.settings.blacklist.filter(function (t) { return e == t.toLowerCase() }) .length } , isTagWhitelisted: function (e) { return this.settings.whitelist.some(function (t) { if ((t.value || t) .toLowerCase() === e.toLowerCase()) return !0 }) } , validateTag: function (t) { var e = t.trim() , i = !0; return e ? this.settings.pattern && !this.settings.pattern.test(e) ? i = this.TEXTS.pattern : this.settings.duplicates || -1 === this.isTagDuplicate(e) ? (this.isTagBlacklisted(e) || this.settings.enforceWhitelist && !this.isTagWhitelisted(e)) && (i = this.TEXTS.notAllowed) : i = this.TEXTS.duplicate : i = this.TEXTS.empty, i } , maxTagsReached: function () { return this.value.length >= this.settings.maxTags && this.TEXTS.exceed } , normalizeTags: function (t) { function i(t) { return t.split(a) .filter(function (t) { return t }) .map(function (t) { return { value: t.trim() } }) } var e, n = this.settings , s = n.whitelist , a = n.delimiters , o = n.mode , r = !!s && s[0] instanceof Object , l = t instanceof Array && t[0] instanceof Object && "value" in t[0] , c = []; if (l) return t = (e = []) .concat.apply(e, _toConsumableArray(t.map(function (e) { return i(e.value) .map(function (t) { return _objectSpread({}, e, {}, t) }) }))); if ("number" == typeof t && (t = t.toString()), "string" == typeof t) { if (!t.trim()) return []; t = i(t) } else if (!l && t instanceof Array) { var d; t = (d = []) .concat.apply(d, _toConsumableArray(t.map(function (t) { return i(t) }))) } return r && (t.forEach(function (e) { var t = s.filter(function (t) { return t.value.toLowerCase() == e.value.toLowerCase() }); t[0] ? c.push(t[0]) : "mix" != o && c.push(e) }), t = c), t } , parseMixTags: function (t) { for (var e, i, n = !1, s = "", a = t, o = 0; o < t.length; o++) "[" == t[o] && t[o] == t[o + 1] && (n = !0), n && (s += t[o]), "]" == t[o] && t[o] == t[o - 1] && (n = !1, e = s.slice(2) .slice(0, -2), this.isTagWhitelisted(e) && !this.settings.duplicates && -1 == this.isTagDuplicate(e) && (i = this.normalizeTags.call(this, e)[0], a = this.replaceMixStringWithTag(a, s, i) .html), s = ""); return this.DOM.input.innerHTML = a, this.update(), t } , replaceMixStringWithTag: function (t, e, i, n) { return i && t && -1 != t.indexOf(e) && (n = this.createTagElem(i), this.value.push(i), t = t.replace(e, n.outerHTML + "⁠")), { html: t , tagElm: n } } , addMixTag: function (t) { if (t && this.state.tag) { var _1_item = 0; for (var e, i, j, n, s, a = this.state.tag.value, o = document.createNodeIterator(this.DOM.input, NodeFilter.SHOW_TEXT), r = 100; (e = o.nextNode()) && r--;) if (e.nodeType === Node.TEXT_NODE) { var _node_value = e.nodeValue; var index = _node_value.lastIndexOf(a+'­'); if (-1 == (n = index)) continue; if (_1_item > 0) continue; _1_item++; s = e.splitText(n), this.settings.transformTag.call(this, t), i = this.createTagElem(t), j = document.createTextNode(t.value), s.nodeValue = s.nodeValue.replace(a+'­', ""), e.parentNode.insertBefore(j, s) // i.insertAdjacentHTML("afterend", "⁠") } i && (this.value.push(t), this.update(), this.trigger("add", this.extend({}, { index: this.value.length , tag: i }, t))), this.state.tag = null } } , addTags: function (t, e, i) { var s = this , a = 2 < arguments.length && void 0 !== i ? i : this.settings.skipInvalid , o = []; if (!t || !t.length) return console.warn("[addTags]", "no tags to add:", t), o; if (t = this.normalizeTags.call(this, t), "mix" == this.settings.mode) return this.addMixTag(t[0]); return this.DOM.input.removeAttribute("style"), t.forEach(function (t) { var e, i, n = {}; if (t = Object.assign({}, t), s.settings.transformTag.call(s, t), !0 !== (e = s.maxTagsReached() || s.validateTag.call(s, t.value))) { if (a) return; n["aria-invalid"] = !0, n.class = (t.class || "") + " tagify--notAllowed", n.title = e, s.markTagByValue(t.value), s.trigger("invalid", { data: t , index: s.value.length , message: e }) } n.role = "tag", t.readonly && (n["aria-readonly"] = !0), i = s.createTagElem(s.extend({}, t, n)), o.push(i) , function (t) { var e = this.DOM.scope.lastElementChild; e === this.DOM.input ? this.DOM.scope.insertBefore(t, e) : this.DOM.scope.appendChild(t) }.call(s, i), !0 === e ? (s.value.push(t), s.update(), s.DOM.scope.classList.toggle("hasMaxTags", s.value.length >= s.settings.maxTags), s.trigger("add", { tag: i , index: s.value.length - 1 , data: t })) : s.settings.keepInvalidTags || setTimeout(function () { s.removeTag(i, !0) }, 1e3) }), t.length && e && this.input.set.call(this), o } , minify: function (t) { return t.replace(new RegExp(">[\r\n ]+<", "g"), "><") } , createTagElem: function (t) { var e = this.escapeHTML(t.value) , i = this.settings.templates.tag.call(this, e, t); return this.settings.readonly && (t.readonly = !0), i = this.minify(i), this.parseHTML(i) } , removeTag: function (t, e, i) { var n = 0 < arguments.length && void 0 !== t ? t : this.getLastTag() , s = 1 < arguments.length ? e : void 0 , a = 2 < arguments.length && void 0 !== i ? i : 250; if ("string" == typeof n && (n = this.getTagElmByValue(n)), n instanceof HTMLElement) { var o, r = this.getNodeIndex(n); a && 10 < a ? (n.style.width = parseFloat(window.getComputedStyle(n) .width) + "px", document.body.clientTop, n.classList.add("tagify--hide"), setTimeout(l, 400)) : l(), s || (o = this.value.splice(r, 1)[0], this.update(), this.trigger("remove", { tag: n , index: r , data: o }), this.dropdown.render.call(this)) } function l() { n.parentNode && n.parentNode.removeChild(n) } } , removeAllTags: function () { this.value = [], this.update(), Array.prototype.slice.call(this.getTagElms()) .forEach(function (t) { return t.parentNode.removeChild(t) }) } , getAttributes: function (t) { if ("[object Object]" != Object.prototype.toString.call(t)) return ""; var e, i, n = Object.keys(t) , s = ""; for (i = n.length; i--;) "class" != (e = n[i]) && t.hasOwnProperty(e) && (s += " " + e + (t[e] ? '="'.concat(t[e], '"') : "")); return s } , update: function () { this.DOM.originalInput.value = "mix" == this.settings.mode ? this.getMixedTagsAsString() : this.value.length ? JSON.stringify(this.value) : "" } , getMixedTagsAsString: function () { var i = ""; return this.DOM.input.childNodes.forEach(function (t, e) { 1 == t.nodeType ? t.classList.contains("tagify__tag") && (i += "[[" + t.getAttribute("value") + "]]") : i += t.textContent }), i } , dropdown: { init: function () { this.DOM.dropdown = this.dropdown.build.call(this) } , build: function () { var t = this.settings.dropdown , e = t.position , i = t.classname , n = "".concat("manual" == e ? "" : "tagify__dropdown", " ") .concat(i) .trim() , s = ''); return this.parseHTML(s) } , show: function (t) { var e, i = "manual" == this.settings.dropdown.position; if (this.settings.whitelist.length) { if (this.suggestedListItems = this.dropdown.filterListItems.call(this, t), !this.suggestedListItems.length) return this.input.autocomplete.suggest.call(this), void this.dropdown.hide.call(this); e = this.dropdown.createListHTML.call(this, this.suggestedListItems), this.DOM.dropdown.innerHTML = this.minify(e), this.settings.enforceWhitelist && !i && this.dropdown.highlightOption.call(this, this.DOM.dropdown.querySelector(".tagify__dropdown__item")), this.DOM.scope.setAttribute("aria-expanded", !0), this.trigger("dropdown:show", this.DOM.dropdown), document.body.contains(this.DOM.dropdown) || (i || (this.dropdown.position.call(this), document.body.appendChild(this.DOM.dropdown), this.events.binding.call(this, !1)), this.dropdown.events.binding.call(this)) } } , hide: function (t) { var e = this.DOM , i = e.scope , n = e.dropdown , s = "manual" == this.settings.dropdown.position && !t; n && document.body.contains(n) && !s && (window.removeEventListener("resize", this.dropdown.position), this.dropdown.events.binding.call(this, !1), this.events.binding.call(this), i.setAttribute("aria-expanded", !1), n.parentNode.removeChild(n), this.trigger("dropdown:hide", n)) } , render: function () { this.suggestedListItems = this.dropdown.filterListItems.call(this, ""); var t = this.dropdown.createListHTML.call(this, this.suggestedListItems); this.DOM.dropdown.innerHTML = this.minify(t) } , position: function () { var t = this.DOM.scope.getBoundingClientRect(); this.DOM.dropdown.style.cssText = "left: " + (t.left + window.pageXOffset) + "px; top: " + (t.top + t.height - 1 + window.pageYOffset) + "px; width: " + t.width + "px" } , events: { binding: function (t) { var e = !(0 < arguments.length && void 0 !== t) || t , i = this.listeners.dropdown = this.listeners.dropdown || { position: this.dropdown.position.bind(this) , onKeyDown: this.dropdown.events.callbacks.onKeyDown.bind(this) , onMouseOver: this.dropdown.events.callbacks.onMouseOver.bind(this) , onClick: this.dropdown.events.callbacks.onClick.bind(this) } , n = e ? "addEventListener" : "removeEventListener"; "manual" != this.settings.dropdown.position && (window[n]("resize", i.position), window[n]("keydown", i.onKeyDown)), window[n]("mousedown", i.onClick), this.DOM.dropdown[n]("mouseover", i.onMouseOver) } , callbacks: { onKeyDown: function (t) { var e = this , i = this.DOM.dropdown.querySelector("[class$='--active']") , n = i || this.DOM.dropdown.children[0] , s = ""; switch (t.key) { case "ArrowDown": case "ArrowUp": case "Down": case "Up": t.preventDefault(), n = (n = n && n[("ArrowUp" == t.key || "Up" == t.key ? "previous" : "next") + "ElementSibling"]) || this.DOM.dropdown.children["ArrowUp" == t.key || "Up" == t.key ? this.DOM.dropdown.children.length - 1 : 0], this.dropdown.highlightOption.call(this, n, !0); break; case "Escape": case "Esc": this.dropdown.hide.call(this); break; case "ArrowRight": case "Tab": if (t.preventDefault(), !this.input.autocomplete.set.call(this, n ? n.textContent : null)) return !1; case "Enter": if (t.preventDefault(), i) return s = this.suggestedListItems[this.getNodeIndex(i)] || this.input.value, this.addTags([s], !0), this.dropdown.hide.call(this), setTimeout(function () { return e.DOM.input.focus() }, 100), !1; this.addTags(this.input.value, !0) } } , onMouseOver: function (t) { t.target.className.includes("__item") && this.dropdown.highlightOption.call(this, t.target) } , onClick: function (t) { var e, i, n = this; 0 == t.button && t.target != this.DOM.dropdown && ((i = t.target.closest(".tagify__dropdown__item")) && (e = this.suggestedListItems[this.getNodeIndex(i)] || this.input.value, this.addTags([e], !0), setTimeout(function () { return n.DOM.input.focus() }, 100)), this.dropdown.hide.call(this)) } } } , highlightOption: function (t, e) { if (t) { var i, n = "tagify__dropdown__item--active"; this.DOM.dropdown.querySelectorAll("[class$='--active']") .forEach(function (t) { t.classList.remove(n), t.removeAttribute("aria-selected") }), t.classList.add(n), t.setAttribute("aria-selected", !0), e && (t.parentNode.scrollTop = t.clientHeight + t.offsetTop - t.parentNode.clientHeight), this.settings.autoComplete && !this.settings.dropdown.fuzzySearch && (i = this.suggestedListItems[this.getNodeIndex(t)].value || this.input.value, this.input.autocomplete.suggest.call(this, i)) } } , filterListItems: function (t) { var e, i, n, s, a = this , o = [] , r = this.settings.whitelist , l = this.settings.dropdown.maxItems || 1 / 0 , c = 0; if (!t) return r.filter(function (t) { return -1 == a.isTagDuplicate(t.value || t) }) .slice(0, l); for (; c < r.length && (n = (((e = r[c] instanceof Object ? r[c] : { value: r[c] }) .searchBy || "") + " " + e.value) .toLowerCase() .indexOf(t.toLowerCase()), i = this.settings.dropdown.fuzzySearch ? 0 <= n : 0 == n, s = !this.settings.duplicates && -1 < this.isTagDuplicate(e.value), i && !s && l-- && o.push(e), 0 != l); c++); return o } , createListHTML: function (t) { var e = this.settings.templates.dropdownItem.bind(this); return t.map(e) .join("") } } } }(jQuery);