let dleFilter = { path: window.location.pathname, title: document.title, content: false, speedbar: false, reset: false, id: '', original: {}, ajax: 0, lazy: 1, ajaxUrl: 0, hideLoading: 0, button: 0, jsSelect: 1, ajaxNav: 0, ajaxPage: 0, ajaxAnim: 0, ionSlider: 0, navApart: 0, filterUrl: 'f', defaultUrl: '/f/sort=date/order=desc/', newsLimit: '12', }; /* pytesNET/tail.select v.0.5.16 | Basic Version | @author SamBrishes, pytesNET | @license MIT */ !function (e, t) { "function" == typeof define && define.amd ? define(function () { return t(e) }) : "object" == typeof module && module.exports ? module.exports = t(e) : (void 0 === e.tail && (e.tail = {}), e.tail.select = t(e), "undefined" != typeof jQuery && (jQuery.fn.tailselect = function (e) { var t, i = []; return this.each(function () { !1 !== (t = tail.select(this, e)) && i.push(t) }), 1 === i.length ? i[0] : 0 !== i.length && i }), "undefined" != typeof MooTools && Element.implement({ tailselect: function (e) { return new tail.select(this, e) } })) }(window, function (e) { "use strict"; var r = e, h = e.document; function b(e, t) { return !!(e && "classList" in e) && e.classList.contains(t) } function c(e, t) { return e && "classList" in e ? e.classList.add(t) : void 0 } function d(e, t) { return e && "classList" in e ? e.classList.remove(t) : void 0 } function s(e, t, i) { if (CustomEvent && CustomEvent.name) var n = new CustomEvent(t, i); else (n = h.createEvent("CustomEvent")).initCustomEvent(t, !!i.bubbles, !!i.cancelable, i.detail); return e.dispatchEvent(n) } function u(e, t) { if ("function" == typeof Object.assign) return Object.assign({}, e, t || {}); var i = Object.constructor(); for (var n in e) i[n] = n in t ? t[n] : e[n]; return i } function g(e, t) { var i = h.createElement(e); return i.className = t && t.join ? t.join(" ") : t || "", i } var a, p = function (e, t) { if ((e = "string" == typeof e ? h.querySelectorAll(e) : e) instanceof NodeList || e instanceof HTMLCollection || e instanceof Array) { for (var i = [], n = e.length, s = 0; s < n; s++) i.push(new p(e[s], u(t, {}))); return 1 === i.length ? i[0] : 0 !== i.length && i } if (!(e instanceof Element && this instanceof p)) return e instanceof Element && new p(e, t); if (p.inst[e.getAttribute("data-tail-select")]) return p.inst[e.getAttribute("data-tail-select")]; if (e.getAttribute("data-select")) { var l = JSON.parse(e.getAttribute("data-select").replace(/\'/g, '"')); l instanceof Object && (t = u(t, l)) } var o = e.getAttribute("placeholder") || e.getAttribute("data-placeholder"), r = "bindSourceSelect", a = "sourceHide"; return (t = t instanceof Object ? t : {}).multiple = "multiple" in t ? t.multiple : e.multiple, t.disabled = "disabled" in t ? t.disabled : e.disabled, t.placeholder = o || t.placeholder || null, t.width = "auto" === t.width ? e.offsetWidth + 50 : t.width, t.sourceBind = r in t ? t[r] : t.sourceBind || !1, t.sourceHide = a in t ? t[a] : t.sourceHide || !0, t.multiLimit = 0 <= t.multiLimit ? t.multiLimit : 1 / 0, this.e = e, this.id = ++p.count, this.con = u(p.defaults, t), this.events = {}, (p.inst["tail-" + this.id] = this).init().bind() }; return p.version = "0.5.16", p.status = "beta", p.count = 0, p.inst = {}, p.defaults = { animate: !0, classNames: null, csvOutput: !1, csvSeparator: ",", descriptions: !1, deselect: !1, disabled: !1, height: 350, hideDisabled: !1, hideSelected: !1, items: {}, locale: "en", linguisticRules: {"е": "ё", a: "ä", o: "ö", u: "ü", ss: "ß"}, multiple: !1, multiLimit: 1 / 0, multiPinSelected: !1, multiContainer: !1, multiShowCount: !0, multiShowLimit: !1, multiSelectAll: !1, multiSelectGroup: !0, openAbove: null, placeholder: null, search: !1, searchConfig: ["text", "value"], searchFocus: !0, searchMarked: !0, searchMinLength: 1, searchDisabled: !0, sortItems: !1, sortGroups: !1, sourceBind: !1, sourceHide: !0, startOpen: !1, stayOpen: !1, width: null, cbComplete: void 0, cbEmpty: void 0, cbLoopItem: void 0, cbLoopGroup: void 0 }, p.strings = { en: { all: "All", none: "None", empty: "No Options available", emptySearch: "No Options found", limit: "You can't select more Options", placeholder: "Select an Option...", placeholderMulti: "Select up to :limit Options...", search: "Type in to search...", disabled: "This Field is disabled" }, ru: { all: "Все", none: "Ничего", actionAll: "Выбрать все", actionNone: "Отменить все", empty: "Здесь пока ничего нет", emptySearch: "Ничего не найдено", limit: "Вы не можете выбрать больше вариантов", placeholder: "Выберите вариант...", placeholderMulti: function (args) { let strings = ["варианта", "вариантов", "вариантов"], cases = [2, 0, 1, 1, 1, 2], num = args[":limit"]; let string = strings[(num % 100 > 4 && num % 100 < 20) ? 2 : cases[(num % 10 < 5) ? num % 10 : 5]]; return "Выбор до :limit " + string + " ..."; }, search: "Начните набирать для поиска...", disabled: "Поле отключено" }, modify: function (e, t, i) { if (!(e in this)) return !1; if (t instanceof Object) for (var n in t) this.modify(e, n, t[n]); else this[e][t] = "string" == typeof i ? i : this[e][t]; return !0 }, register: function (e, t) { return "string" == typeof e && t instanceof Object && (this[e] = t, !0) } }, p.prototype = { _e: function (e, t, i) { if (!(e in this.__)) return i || e; if ("function" == typeof (e = this.__[e]) && (e = e.call(this, t)), "object" == typeof t) for (var n in t) e = e.replace(n, t[n]); return e }, init: function () { var t = this, e = ["tail-select"], i = this.con, n = !0 === i.classNames ? this.e.className : i.classNames; e.push(n && n.push ? n.join(" ") : n && n.split ? n : "no-classes"), i.hideSelected && e.push("hide-selected"), i.hideDisabled && e.push("hide-disabled"), 0 == i.multiLimit && e.push("disabled"), i.multiple && e.push("multiple"), i.deselect && e.push("deselect"), e.push("dle-filter-select-" + Object.values(t)[0].name), i.disabled && e.push("disabled"), this.__ = u(p.strings.en, p.strings[i.locale] || {}), this._init = !0, this._query = !1, this.select = g("DIV", e), this.label = g("DIV", "select-label"), this.dropdown = g("DIV", "select-dropdown"), this.search = g("DIV", "dropdown-search"), this.csvInput = g("INPUT", "select-search"), null !== this.e.getAttribute("tabindex") ? this.select.setAttribute("tabindex", this.e.getAttribute("tabindex")) : this.select.setAttribute("tabindex", 0), i.width && /^[0-9.]+(?:cm|mm|in|px|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax|\%)$/i.test(i.width) ? this.select.style.width = i.width : i.width && !isNaN(parseFloat(i.width, 10)) && (this.select.style.width = i.width + "px"), this.label.addEventListener("click", function (e) { t.toggle.call(t, t.con.animate) }), this.select.appendChild(this.label), isNaN(parseInt(i.height, 10)) || (this.dropdown.style.maxHeight = parseInt(i.height, 10) + "px"), i.search && (this.search.innerHTML = '', this.search.children[0].placeholder = this._e("search"), this.search.children[0].addEventListener("input", function (e) { t.query.call(t, this.value.length > i.searchMinLength ? this.value : void 0) }), this.dropdown.appendChild(this.search)), this.select.appendChild(this.dropdown), this.csvInput.type = "hidden", i.csvOutput && (this.csvInput.name = this.e.name, this.e.removeAttribute("name"), this.select.appendChild(this.csvInput)), i.multiple && i.multiContainer && (h.querySelector(i.multiContainer) ? (this.container = h.querySelector(i.multiContainer), this.container.className += " tail-select-container") : !0 === i.multiContainer && (this.container = this.label, this.container.className += " tail-select-container")), this.options = new a(this.e, this); for (var s = this.e.options.length, l = 0; l < s; l++) this.options.set(this.e.options[l], !1); for (var o in i.items) "string" == typeof i.items[o] && (i.items[o] = {value: i.items[o]}), this.options.add(i.items[o].key || o, i.items[o].value, i.items[o].group, i.items[o].selected, i.items[o].disabled, i.items[o].description); filterStartState = $('.filter-form-cont').serialize(); return this.query(), this.e.nextElementSibling ? this.e.parentElement.insertBefore(this.select, this.e.nextElementSibling) : this.e.parentElement.appendChild(this.select), i.sourceHide && ("none" == this.e.style.display ? (this.select.style.display = "none", this.e.setAttribute("data-select-hidden", "display")) : "hidden" == this.e.style.visibility ? (this.select.style.visibiltiy = "hidden", this.e.setAttribute("data-select-hidden", "visibility")) : (this.e.style.display = "none", this.e.setAttribute("data-select-hidden", "0"))), this.e.setAttribute("data-tail-select", "tail-" + this.id), t.con.startOpen && this.open(i.animate), (i.cbComplete || function () { }).call(this, this.select), this._init = !1, this }, bind: function () { var a = this; return h.addEventListener("keydown", function (e) { var t, i, n, s, l, o = e.keyCode || e.which; if (!(32 == o && a.select === document.activeElement) && (!b(a.select, "active") || [13, 27, 38, 40].indexOf(o) < 0)) return !1; if (e.preventDefault(), e.stopPropagation(), 32 === o) return a.open(a.con.animate); if (13 == o && (t = a.dropdown.querySelector(".dropdown-option.hover:not(.disabled)")) && a.options.select.call(a.options, t), 27 == o || 13 == o) return a.close(a.con.animate); if (t = a.dropdown.querySelector(".dropdown-option.hover:not(.disabled)")) for (d(t, "hover"), n = [(40 == o ? "next" : "previous") + "ElementSibling"]; (t = null !== (s = t[n]) && "LI" == t.tagName ? s : null !== (s = t.parentElement[n]) && 0 < s.children.length && "UL" == s.tagName && s.children[40 == o ? 0 : s.children.length - 1]) && (!b(t, "dropdown-option") || b(t, "disabled"));) ; if (t || 40 != o ? t || 38 != o || (t = (l = a.dropdown.querySelectorAll(".dropdown-option:not(.disabled)"))[l.length - 1]) : t = a.dropdown.querySelector(".dropdown-option:not(.disabled)"), t && (i = a.dropdown.querySelector(".dropdown-inner"))) { var r = function (e) { for (var t = { top: e.offsetTop, height: e.offsetHeight }; (e = e.parentElement) != i;) t.top += e.offsetTop; return t }(t); c(t, "hover"), i.scrollTop = Math.max(0, r.top - 2 * r.height) } return !0 }), h.addEventListener("click", function (e) { if (!b(a.select, "active") || b(a.select, "idle")) return !1; if (!0 === a.con.stayOpen) return !1; for (var t = [a.e, a.select, a.container], i = t.length, n = 0; n < i; n++) { if (t[n] && (t[n].contains(e.target) || t[n] == e.target)) return !1; if (!e.target.parentElement) return !1 } return a.close.call(a, a.con.animate) }), this.con.sourceBind && this.e.addEventListener("change", function (e) { if (null != e.detail) return !1; if (e.preventDefault(), e.stopPropagation(), !this.multiple && this.selectedIndex) a.options.select.call(a.options, this.options[this.selectedIndex]); else { var t = [].concat(a.options.selected), i = [].filter.call(this.querySelectorAll("option:checked"), function (e) { return !(0 <= t.indexOf(e)) || (t.splice(t.indexOf(e), 1), !1) }); a.options.walk.call(a.options, "unselect", t), a.options.walk.call(a.options, "select", i) } }), !0 }, callback: function (e, t, i) { var n = "[data-key='" + e.key.replace(/('|\\)/g, "\\$1") + "'][data-group='" + e.group.replace(/('|\\)/g, "\\$1") + "']"; if ("rebuild" == t) return this.query(); var s = this.dropdown.querySelector(n); return s && 0 <= ["select", "disable"].indexOf(t) ? c(s, "select" == t ? "selected" : "disabled") : s && 0 <= ["unselect", "enable"].indexOf(t) && d(s, "unselect" == t ? "selected" : "disabled"), this.update(e), !0 === i || this.trigger("change", e, t) }, trigger: function (e) { if (this._init) return !1; var t = {bubbles: !1, cancelable: !0, detail: {args: arguments, self: this}}; "change" == e && arguments[2] && 0 <= arguments[2].indexOf("select") && (s(this.e, "input", t), s(this.e, "change", t)), s(this.select, "tail::" + e, t); var i, n = []; return Array.prototype.map.call(arguments, function (e, t) { 0 < t && n.push(e) }), (this.events[e] || []).forEach(function (e) { (i = [].concat(n)).push(e.args || null), (e.cb || function () { }).apply(t.detail.self, i) }), !0 }, calc: function () { var e = this.dropdown.cloneNode(!0), t = this.con.height, i = 0, n = this.dropdown.querySelector(".dropdown-inner"); (e = this.dropdown.cloneNode(!0)).style.cssText = "height:auto;min-height:auto;max-height:none;opacity:0;display:block;visibility:hidden;", e.style.maxHeight = this.con.height + "px", e.className += " cloned", this.dropdown.parentElement.appendChild(e), t = t > e.clientHeight ? e.clientHeight : t, this.con.search && (i = e.querySelector(".dropdown-search").clientHeight), this.dropdown.parentElement.removeChild(e); var s = this.select.getBoundingClientRect(), l = r.innerHeight - (s.top + s.height), o = l < t + i && s.top > l; return !0 === this.con.openAbove || !1 !== this.con.openAbove && o ? (o = !0, t = Math.min(t, s.top - 10), c(this.select, "open-top")) : (o = !1, t = Math.min(t, l - 10), d(this.select, "open-top")), n && (this.dropdown.style.maxHeight = t + "px", n.style.maxHeight = t - i + "px"), this }, query: function (e, t) { var i, n, s, l, o, r, a = this, c = this.con, h = "getAttribute", d = g("DIV", "dropdown-inner"), u = e ? "finder" : "walker", p = e ? [e, t] : [c.sortItems, c.sortGroups]; for (this._query = "string" == typeof e && e; i = this.options[u].apply(this.options, p);) { if (!s || s && s[h]("data-group") !== i.group) { if (!((n = (c.cbLoopGroup || this.cbGroup).call(this, i.group, e, d)) instanceof Element)) break; (s = n).setAttribute("data-group", i.group), d.appendChild(s) } if (null !== (l = (c.cbLoopItem || this.cbItem).call(this, i, s, e, d))) { if (!1 === l) break; l.setAttribute("data-key", i.key), l.setAttribute("data-group", i.group), l.addEventListener("click", function (e) { if (!this.hasAttribute("data-key")) return !1; var t = this[h]("data-key"), i = this[h]("data-group") || "#"; a.options.toggle.call(a.options, t, i) && (!1 !== a.con.stayOpen || a.con.multiple || a.close.call(a, a.con.animate)) }), s.appendChild(l) } } var f = d.querySelectorAll("*[data-key]").length; 0 == f && (this.con.cbEmpty || function (e) { var t = g("SPAN", "dropdown-empty"); t.innerText = this._e("empty"), e.appendChild(t) }).call(this, d, e), 0 < f && c.multiple && c.multiLimit == 1 / 0 && c.multiSelectAll && (o = g("BUTTON", "tail-all"), r = g("BUTTON", "tail-none"), o.innerText = this._e("all"), o.addEventListener("click", function (e) { e.preventDefault(); var t = a.dropdown.querySelectorAll(".dropdown-inner .dropdown-option"); a.options.walk.call(a.options, "select", t) }), r.innerText = this._e("none"), r.addEventListener("click", function (e) { e.preventDefault(); var t = a.dropdown.querySelectorAll(".dropdown-inner .dropdown-option"); a.options.walk.call(a.options, "unselect", t) }), (l = g("SPAN", "dropdown-action")).appendChild(o), l.appendChild(r), d.insertBefore(l, d.children[0])); var m = this.dropdown.querySelector(".dropdown-inner"); return this.dropdown[(m ? "replace" : "append") + "Child"](d, m), b(this.select, "active") && this.calc(), this.updateCSV().updateLabel() }, cbGroup: function (e, t) { var i, n, s = g("UL", "dropdown-optgroup"), l = this; return "#" == e || (s.innerHTML = '
  • ' + e + "
  • ", this.con.multiple && this.con.multiLimit == 1 / 0 && this.con.multiSelectAll && (i = g("BUTTON", "tail-none"), n = g("BUTTON", "tail-all"), i.innerText = this._e("none"), i.addEventListener("click", function (e) { e.preventDefault(); var t = this.parentElement.parentElement.getAttribute("data-group"); l.options.all.call(l.options, "unselect", t) }), n.innerText = this._e("all"), n.addEventListener("click", function (e) { e.preventDefault(); var t = this.parentElement.parentElement.getAttribute("data-group"); l.options.all.call(l.options, "select", t) }), s.children[0].appendChild(i), s.children[0].appendChild(n))), s }, cbItem: function (e, t, i) { var n = g("LI", "dropdown-option" + (e.selected ? " selected" : "") + (e.disabled ? " disabled" : "")); return i && 0 < i.length && this.con.searchMarked ? (i = this.options.applyLinguisticRules(i), n.innerHTML = e.value.replace(new RegExp("(" + i + ")", "i"), "$1")) : n.innerText = e.value, this.con.descriptions && e.description && (n.innerHTML += '' + e.description + ""), n }, update: function (e) { return this.updateLabel().updateContainer(e).updatePin(e).updateCSV(e) }, updateLabel: function (e) { if (this.container == this.label && 0 < this.options.selected.length) return this.label.querySelector(".label-inner") && this.label.removeChild(this.label.querySelector(".label-inner")), this.label.querySelector(".label-count") && this.label.removeChild(this.label.querySelector(".label-count")), this; var t, i = this.con, n = this.options.selected.length; return "string" != typeof e && (e = i.disabled ? "disabled" : 0 == this.dropdown.querySelectorAll("*[data-key]").length ? "empty" + (b(this.select, "in-search") ? "Search" : "") : i.multiLimit <= n ? "limit" : !i.multiple && 0 < this.options.selected.length ? this.options.selected[0].innerText : "string" == typeof i.placeholder ? i.placeholder : "placeholder" + (i.multiple && i.multiLimit < 1 / 0 ? "Multi" : "")), e = '' + (e = this._e(e, {":limit": i.multiLimit}, e)) + "", t = i.multiShowLimit && i.multiLimit < 1 / 0, i.multiple && i.multiShowCount && (e = (e = ':c' + e).replace(":c", n + (t ? " / " + i.multiLimit : ""))), this.label.innerHTML = e, this }, updateContainer: function (e) { if (!this.container || !this.con.multiContainer) return this; var t = "[data-group='" + e.group + "'][data-key='" + e.key + "']"; if (this.container.querySelector(t)) return e.selected || this.container.removeChild(this.container.querySelector(t)), this; if (e.selected) { var n = this, i = g("DIV", "select-handle"); i.innerText = e.value, i.setAttribute("data-key", e.key), i.setAttribute("data-group", e.group), i.addEventListener("click", function (e) { e.preventDefault(), e.stopPropagation(); var t = this.getAttribute("data-key"), i = this.getAttribute("data-group"); n.options.unselect.call(n.options, t, i) }), this.container.appendChild(i) } return this }, updatePin: function (e) { var t = this.dropdown.querySelector(".dropdown-inner ul"), i = "li[data-key='" + e.key + "'][data-group='" + e.group + "']"; if (!this.con.multiPinSelected || !t || !1 !== this._query) return this; if (i = this.dropdown.querySelector(i), e.selected) t.insertBefore(i, t.children[0]); else { for (var n = this.dropdown.querySelector("ul[data-group='" + e.group + "']"), s = this.options[e.index - 1], l = !1; s && s.group == e.group && !(l = n.querySelector("li[data-key='" + s.key + "']"));) s = this.options[s.index - 1]; l && l.nextElementSibling ? n.insertBefore(i, l.nextElementSibling) : n.appendChild(i) } return this }, updateCSV: function (e) { if (!this.csvInput || !this.con.csvOutput) return this; for (var t = [], i = this.options.selected.length, n = 0; n < i; n++) t.push(this.options.selected[n].value); return this.csvInput.value = t.join(this.con.csvSeparator || ","), this }, open: function (e) { if (b(this.select, "active") || b(this.select, "idle") || this.con.disabled) return !1; this.calc(); function n() { c(s.select, "active"), d(s.select, "idle"), this.dropdown.style.height = "auto", this.dropdown.style.overflow = "visible", this.label.removeAttribute("style"), this.con.search && this.con.searchFocus && this.dropdown.querySelector("input").focus(), this.trigger.call(this, "open") } var s = this, l = this.dropdown.style; return !1 !== e ? (this.label.style.zIndex = 25, this.dropdown.style.cssText += "height:0;display:block;overflow:hidden;", c(s.select, "idle"), function e() { var t = parseInt(l.height, 10), i = parseInt(l.maxHeight, 10); if (i <= t) return n.call(s); l.height = (i < t + 50 ? i : t + 50) + "px", setTimeout(e, 20) }()) : (l.cssText = "height:" + l.maxHeight + ";display:block;overflow:hidden;", n.call(this)), this }, close: function (e) { if (!b(this.select, "active") || b(this.select, "idle")) return !1; function t() { d(this.select, "active"), d(this.select, "idle"), this.dropdown.removeAttribute("style"), this.dropdown.querySelector(".dropdown-inner").removeAttribute("style"), this.trigger.call(this, "close") } var i = this, n = this.dropdown; return !1 !== e ? (c(this.select, "idle"), this.dropdown.style.overflow = "hidden", function e() { if (parseInt(n.offsetHeight, 10) - 50 <= 0) return t.call(i); n.style.height = parseInt(n.offsetHeight, 10) - 50 + "px", setTimeout(e, 20) }()) : t.call(this), this }, toggle: function (e) { return b(this.select, "active") ? this.close(e) : b(this.select, "idle") ? this : this.open(e) }, remove: function () { if (this.e.removeAttribute("data-tail-select"), this.e.hasAttribute("data-select-hidden") && ("0" == this.e.getAttribute("data-select-hidden") && this.e.style.removeProperty("display"), this.e.removeAttribute("data-select-hidden")), Array.prototype.map.call(this.e.querySelectorAll("[data-select-option='add']"), function (e) { e.parentElement.removeChild(e) }), Array.prototype.map.call(this.e.querySelectorAll("[data-select-optgroup='add']"), function (e) { e.parentElement.removeChild(e) }), this.e.name = this.csvInput.hasAttribute("name") ? this.csvInput.name : this.e.name, this.select.parentElement && this.select.parentElement.removeChild(this.select), this.container) for (var e = this.container.querySelectorAll(".select-handle"), t = e.length, i = 0; i < t; i++) this.container.removeChild(e[i]); return this }, reload: function () { return this.remove().init().createAdditionalButtons() }, clearPreviousButtons: function (selector) { selector.remove(); }, createAdditionalButtons: function () { // Находим все элементы ul с классом dropdown-optgroup var selects = document.querySelectorAll(".filter-form-cont select") var dropdowns = document.querySelectorAll('.select-dropdown'); // Проходимся по каждому найденному элементу dropdowns.forEach(function(dropdown,index) { const buttonsExist = dropdown.querySelectorAll(".filter-action-buttons") if (buttonsExist.length === 0) { // Создаем новый div var div = document.createElement('div'); div.classList.add("filter-action-buttons"); // Создаем первую кнопку "Применить" var applyButton = document.createElement('button'); applyButton.setAttribute('class','filter-action-buttons-apply') applyButton.textContent = 'Применить'; applyButton.addEventListener('click', function(e) { e.preventDefault(); darkOverlayHeader(true); removeDark = true; console.log('remove dark status:' + removeDark) document.querySelectorAll('.select-dropdown')[index].style.display = 'none'; filterAjax($('.filter-form-cont'), true); console.log('listener STOP') document.removeEventListener('click', outsideClickHandlerFilter); stillOpened = false; //document.querySelectorAll('.select-dropdown')[index].style.display = 'none'; //tail.select('[data-dlefilter*=dle-filter] .select-dropdown[' + index + ']').updateAllPins(); }); // Создаем вторую кнопку "Отмена" var cancelButton = document.createElement('button'); cancelButton.textContent = 'Отмена'; cancelButton.setAttribute('class','filter-action-buttons-cancel') cancelButton.addEventListener('click', function(e) { e.preventDefault(); //console.log('reload!') setStateByIndex(index,thisStepCache) tail.select('[data-dlefilter*=dle-filter] select[data-select-id="' + index + '"]').toggle().reload(); //tail.select('[data-dlefilter*=dle-filter] select[data-select-id="' + index + '"]').updateAllPins(); //resetFormLogic(e.target,dropdown); }) // Создаем третью кнопку "Очистить" var resetButton = document.createElement('button'); resetButton.textContent = 'Очистить'; resetButton.setAttribute('class','filter-action-buttons-reset') // Назначаем обработчик события для кнопки сброса resetButton.addEventListener('click', function(e) { e.preventDefault(); resetFormLogic(e.target,dropdown,index,true); }); div.appendChild(applyButton); div.appendChild(cancelButton); if (index === 3 || index === 2 || index === 4) { // Кнопка "Все, кроме первого" (тогглит состояние: все кроме первого <-> снять всё) var chooseAllBtn = document.createElement('button'); chooseAllBtn.textContent = 'Выбрать все'; chooseAllBtn.setAttribute('class','filter-action-buttons-choseall'); chooseAllBtn.addEventListener('click', function(e) { // не даём дропдауну закрыться e.preventDefault(); e.stopPropagation(); if (e.stopImmediatePropagation) e.stopImmediatePropagation(); // Тогглим выбор для селекта с данным индексом // (функция использует tail.select().options.select/unselect, не делает reload, // оставляет дропдаун открытым и возвращает фокус в поиск) toggleAllExceptFirstLogic(e, dropdown, index, true); // при желании можно обновить ваш счётчик/кнопку: if (typeof resetButtonStatus === 'function') { resetButtonStatus(index); } }); // Добавляем кнопку в панель действий (до "Отмена" / "Очистить") div.appendChild(chooseAllBtn); } if (selects[index].classList.contains('dualmode')) { const container = document.createElement('div'); container.setAttribute('class', 'dualmode-cont'); // обязательный класс const uid = `dualmode-toggle-${index}-${Math.random().toString(36).slice(2, 7)}`; // чекбокс (семантика + доступность) const changeSearchModeButton = document.createElement('input'); changeSearchModeButton.type = 'checkbox'; changeSearchModeButton.className = 'chk'; changeSearchModeButton.id = uid; changeSearchModeButton.setAttribute('role', 'switch'); if (checkCurrentStatusOfSearch(index)) { changeSearchModeButton.checked = true; } // label-контейнер Retro Radio + LED const label = document.createElement('label'); label.className = 'switch theme-radio'; label.setAttribute('for', uid); const ui = document.createElement('span'); ui.className = 'ui-toggle'; const knob = document.createElement('span'); knob.className = 'knob'; ui.appendChild(knob); const txt = document.createElement('span'); txt.className = 'txt'; txt.textContent = 'Точное совпадение'; // Значок «?» + поп-ап (одинаково для ПК и мобилы) const HELP = 'Будут показаны только те ленты, где есть ВСЕ выбранные пункты.'; const q = document.createElement('span'); q.className = 'q'; q.textContent = '?'; q.tabIndex = 0; // фокус с клавиатуры q.setAttribute('role', 'button'); q.setAttribute('aria-label', 'Пояснение'); q.setAttribute('aria-expanded', 'false'); const pop = document.createElement('span'); pop.className = 'help-pop'; pop.setAttribute('role', 'tooltip'); pop.setAttribute('aria-hidden', 'true'); pop.textContent = HELP; // связь кнопки и тултипа const tipId = `${uid}-tip`; pop.id = tipId; q.setAttribute('aria-controls', tipId); // собираем label.appendChild(ui); label.appendChild(txt); q.appendChild(pop); label.appendChild(q); // переключение режима changeSearchModeButton.addEventListener('change', function () { if (changeSearchModeButton.checked) { changeSearchMode(selects[index], 'or'); } else { changeSearchMode(selects[index], 'and'); } }); // ——— управление поп-апом ——— const closeAllPopups = () => { document.querySelectorAll('.dualmode-cont .q[data-open="1"]').forEach(el => { el.dataset.open = ''; const p = el.querySelector('.help-pop'); if (p) p.setAttribute('aria-hidden', 'true'); el.setAttribute('aria-expanded', 'false'); }); }; const togglePopup = (open) => { const willOpen = (open === undefined) ? q.dataset.open !== '1' : !!open; if (willOpen) { closeAllPopups(); q.dataset.open = '1'; pop.setAttribute('aria-hidden', 'false'); q.setAttribute('aria-expanded', 'true'); } else { q.dataset.open = ''; pop.setAttribute('aria-hidden', 'true'); q.setAttribute('aria-expanded', 'false'); } }; // клик по «?» — показываем подсказку (и НЕ переключаем чекбокс) q.addEventListener('click', (e) => { e.preventDefault(); e.stopPropagation(); togglePopup(); }); // клавиатура: Enter/Space — открыть/закрыть, Esc — закрыть q.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); e.stopPropagation(); togglePopup(); } else if (e.key === 'Escape') { togglePopup(false); } }); // закрытие по клику вне if (!window.__dualmodePopupCloseBound) { document.addEventListener('click', (e) => { if (!e.target.closest('.q')) closeAllPopups(); }, true); window.addEventListener('scroll', closeAllPopups, { passive: true }); window.addEventListener('resize', closeAllPopups); window.__dualmodePopupCloseBound = true; } container.appendChild(changeSearchModeButton); container.appendChild(label); div.appendChild(container); } div.appendChild(resetButton); dropdown.appendChild(div); } resetButtonStatus(index) }); }, updateAllPins: function () { $('[data-dlefilter*=dle-filter]').find('select').each(function(index) { tail.select('[data-dlefilter*=dle-filter] select[data-select-id="' + index + '"]').updatePin(index); }) }, config: function (e, t, i) { if (e instanceof Object) { for (var n in e) this.config(n, e[n], !1); return this.reload(), this.con } return void 0 === e ? this.con : e in this.con && (void 0 === t ? this.con[e] : (this.con[e] = t, !1 !== i && this.reload(), this)) }, enable: function (e) { return d(this.select, "disabled"), this.e.disabled = !1, (this.con.disabled = !1) === e ? this : this.reload() }, disable: function (e) { return c(this.select, "disabled"), this.e.disabled = !0, !(this.con.disabled = !0) === e ? this : this.reload() }, on: function (e, t, i) { return !(["open", "close", "change"].indexOf(e) < 0 || "function" != typeof t) && (e in this.events || (this.events[e] = []), this.events[e].push({ cb: t, args: i instanceof Array ? i : [] }), this) }, value: function () { return 0 == this.options.selected.length ? null : this.con.multiple ? this.options.selected.map(function (e) { return e.value }) : this.options.selected[0].value } }, (a = p.options = function (e, t) { return this instanceof a ? (this.self = t, this.element = e, this.length = 0, this.selected = [], this.disabled = [], this.items = {"#": {}}, this.groups = {}, this) : new a(e, t) }).prototype = { _r: function (e) { return e.replace("disabled", "disable").replace("enabled", "enable").replace("selected", "select").replace("unselected", "unselect") }, get: function (e, t) { var i = "getAttribute"; if ("object" == typeof e && e.key && e.group) t = e.group || t, e = e.key; else if (e instanceof Element) "OPTION" == e.tagName ? (t = e.parentElement.label || "#", e = e.value || e.innerText) : e.hasAttribute("data-key") && (t = e[i]("data-group") || e.parentElement[i]("data-group") || "#", e = e[i]("data-key")); else if ("string" != typeof e) return !1; return e = /^[0-9]+$/.test(e) ? "_" + e : e, t in this.items && this.items[t][e] }, set: function (e, t) { var i = e.value || e.innerText, n = e.parentElement.label || "#"; if (n in this.items || (this.items[n] = {}, this.groups[n] = e.parentElement), i in this.items[n]) return !1; var s = /^[0-9]+$/.test(i) ? "_" + i : i, l = this.self.con; if (l.multiple && this.selected.length >= l.multiLimit && (e.selected = !1), !e.selected || !l.deselect || e.hasAttribute("selected") && 0 != l.multiLimit || (e.selected = !1, e.parentElement.selectedIndex = -1), e.hasAttribute("data-description")) { var o = g("SPAN"); o.innerHTML = e.getAttribute("data-description"), e.setAttribute("data-description", o.innerHTML) } return this.items[n][s] = { key: i, value: e.text, description: e.getAttribute("data-description") || null, group: n, option: e, optgroup: "#" != n ? this.groups[n] : void 0, selected: e.selected, disabled: e.disabled, hidden: e.hidden || !1 }, this.length++, e.selected && this.select(this.items[n][s]), e.disabled && this.disable(this.items[n][s]), !t || this.self.callback(this.items[n][i], "rebuild") }, add: function (e, t, i, n, s, l, o) { if (e instanceof Object) { for (var r in e) this.add(e[r].key || r, e[r].value, e[r].group, e[r].selected, e[r].disabled, e[r].description, !1); return this.self.query() } if (this.get(e, i)) return !1; if ("#" !== (i = "string" == typeof i ? i : "#") && !(i in this.groups)) { var a = g("OPTGROUP"); a.label = i, a.setAttribute("data-select-optgroup", "add"), this.element.appendChild(a), this.items[i] = {}, this.groups[i] = a } this.self.con.multiple && this.selected.length >= this.self.con.multiLimit && (n = !1), s = !!s; var c = h.createElement("OPTION"); return c.value = e, c.selected = n, c.disabled = s, c.innerText = t, c.setAttribute("data-select-option", "add"), l && 0 < l.length && c.setAttribute("data-description", l), ("#" == i ? this.element : this.groups[i]).appendChild(c), this.set(c, o) }, move: function (e, t, i, n) { if (!(e = this.get(e, t))) return !1; if ("#" !== i && !(i in this.groups)) { var s = g("OPTGROUP"); s.label = i, this.element.appendChild(s), this.items[i] = {}, this.groups[i] = s, this.groups[i].appendChild(e.option) } return delete this.items[e.group][e.key], e.group = i, e.optgroup = this.groups[i] || void 0, this.items[i][e.key] = e, !n || this.self.query() }, remove: function (e, t, i) { if (!(e = this.get(e, t))) return !1; e.selected && this.unselect(e), e.disabled && this.enable(e), e.option.parentElement.removeChild(e.option); var n = /^[0-9]+$/.test(e.key) ? "_" + e.key : e.key; return delete this.items[e.group][n], this.length--, 0 === Object.keys(this.items[e.group]).length && (delete this.items[e.group], delete this.groups[e.group]), !i || this.self.query() }, is: function (e, t, i) { e = this._r(e); var n = this.get(t, i); return !n || ["select", "unselect", "disable", "enable"].indexOf(e) < 0 ? null : "disable" == e || "enable" == e ? "disable" == e ? n.disabled : !n.disabled : ("select" == e || "unselect" == e) && ("select" == e ? n.selected : !n.selected) }, handle: function (e, t, i, n) { var s = this.get(t, i); e = this._r(e); if (!s || ["select", "unselect", "disable", "enable"].indexOf(e) < 0) return null; if ("disable" == e || "enable" == e) return s.option in this.disabled || "disable" != e ? s.option in this.disabled && "enable" == e && this.disabled.splice(this.disabled.indexOf(s.option), 1) : this.disabled.push(s.option), s.disabled = "disable" == e, s.option.disabled = "disable" == e, this.self.callback.call(this.self, s, e); var l = b(this.self.select, "disabled") || s.disabled || s.option.disabled, o = this.self.con.multiple && this.self.con.multiLimit <= this.selected.length, r = !this.self.con.multiple && 0 < this.selected.indexOf(s.option), a = 0 == this.self.con.multiLimit && 1 == this.self.con.deselect, c = !this.self.con.multiple && !this.self.con.deselect && !0 !== n; if ("select" == e) { if (l || o || a || r) return !1; if (!this.self.con.multiple) for (var h in this.selected) this.unselect(this.selected[h], void 0, !0); this.selected.indexOf(s.option) < 0 && this.selected.push(s.option) } else if ("unselect" == e) { if (l || c) return !1; this.selected.splice(this.selected.indexOf(s.option), 1) } return s.selected = "select" == e, s.option.selected = "select" == e, s.option[(6 < e.length ? "remove" : "set") + "Attribute"]("selected", "selected"), this.self.callback.call(this.self, s, e, n) }, enable: function (e, t) { return this.handle("enable", e, t, !1) }, disable: function (e, t) { return this.handle("disable", e, t, !1) }, select: function (e, t) { return this.handle("select", e, t, !1) }, unselect: function (e, t, i) { return this.handle("unselect", e, t, i) }, toggle: function (e, t) { return !!(e = this.get(e, t)) && this.handle(e.selected ? "unselect" : "select", e, t, !1) }, invert: function (t) { if (t = this._r(t), 0 <= ["enable", "disable"].indexOf(t)) var i = this.disabled, n = "enable" == t ? "disable" : "enable"; else if (0 <= ["select", "unselect"].indexOf(t)) i = this.selected, n = "select" == t ? "unselect" : "select"; var e = Array.prototype.filter.call(this, function (e) { return !(e in i) }), s = this; return [].concat(i).forEach(function (e) { s.handle.call(s, n, e) }), [].concat(e).forEach(function (e) { s.handle.call(s, t, e) }), !0 }, all: function (t, i) { var n = this, e = this; return i in this.items ? e = Object.keys(this.items[i]) : 0 <= ["unselect", "enable"].indexOf(t) && (e = [].concat("unselect" == t ? this.selected : this.disabled)), Array.prototype.forEach.call(e, function (e) { n.handle.call(n, t, e, i, !1) }), !0 }, walk: function (t, e, i) { if (e instanceof Array || e.length) for (var n = e.length, s = 0; s < n; s++) this.handle.apply(this, [t, e[s], null].concat(i)); else if (e instanceof Object) { var l = this; if (e.forEach) e.forEach(function (e) { l.handle.apply(l, [t, e, null].concat(i)) }); else for (var o in e) ("string" == typeof e[o] || "number" == typeof e[o] || e[o] instanceof Element) && this.handle.apply(this, [t, e[o], o in this.items ? o : null]).concat(i) } return this }, applyLinguisticRules: function (e, t) { var i = this.self.con.linguisticRules, n = []; return Object.keys(i).forEach(function (e) { n.push("(" + e + "|[" + i[e] + "])") }), t && (n = n.concat(n.map(function (e) { return e.toUpperCase() }))), e.replace(new RegExp(n.join("|"), t ? "g" : "ig"), function (e) { return n[[].indexOf.call(arguments, e, 1) - 1] }) }, find: function (e, t) { var i, n = this, s = {}; if (t || (t = this.self.con.searchConfig), "function" == typeof t) i = t.bind(this, e); else { (t = t instanceof Array ? t : [t]).forEach(function (e) { "string" == typeof e && (s[e] = !0) }), s.any = s.any ? s.any : s.attributes && s.value, s.regex && !s.text || (e = e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")), s.exactglyphes || (e = this.self.options.applyLinguisticRules(e, s.case)), s.word && (e = "\\b" + e + "\\b"); var l = new RegExp(e, s.case ? "m" : "mi"), o = function (e) { return l.test(e.text || e.value) }; if (i = s.any ? function (e) { return o(e) || [].some.call(e.attributes, o) } : s.attributes ? function (e) { return [].some.call(e.attributes, o) } : o, !this.self.con.searchDisabled) { var r = i; i = function (e) { return !e.disabled && r(e) } } } return [].filter.call(this.self.e.options, i).map(function (e) { return !e.hidden && n.get(e) }) }, finder: function (e, t) { var i; for (void 0 === this._finderLoop && (this._finderLoop = this.find(e, t)); void 0 !== (i = this._finderLoop.shift());) return i; return delete this._finderLoop, !1 }, walker: function (e, t) { if (void 0 !== this._inLoop && this._inLoop) { if (0 < this._inItems.length) { do { var i = this.items[this._inGroup][this._inItems.shift()] } while (!0 === i.hidden); return i } if (0 < this._inGroups.length) { for (; 0 < this._inGroups.length;) { var n = this._inGroups.shift(); if (!(n in this.items)) return !1; var s = Object.keys(this.items[n]); if (0 < s.length) break } return "ASC" == e ? s.sort() : "DESC" == e ? s.sort().reverse() : "function" == typeof e && (s = e.call(this, s)), this._inItems = s, this._inGroup = n, this.walker(null, null) } return delete this._inLoop, delete this._inItems, delete this._inGroup, delete this._inGroups, !1 } var l = Object.keys(this.groups) || []; return "ASC" == t ? l.sort() : "DESC" == t ? l.sort().reverse() : "function" == typeof t && (l = t.call(this, l)), l.unshift("#"), this._inLoop = !0, this._inItems = [], this._inGroups = l, this.walker(e, null) } }, p });