05-tilda-export-backup/Tilda_ Сведенборг_ духовидец и тайный агент_files/t-selectbox.min.js
2025-10-29 19:50:39 +03:00

1 line
19 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(()=>{"use strict";const t={ru:"com",by:"biz",kz:"pro",cc:"one"}[function(){const t={ru:"com",by:"biz",kz:"pro",cc:"one"};let e="cc";if("undefined"!=typeof window){const o=window.location.origin.split(".").pop()||"";Object.keys(t).includes(o)&&(e=o)}return e}()],e=[`https://app.tildacdn.${t}/tfront/plugins/tooltip/t-tooltip.min.js`,`https://app.tildacdn.${t}/tfront/plugins/tooltip/t-tooltip.min.css`],o={position:"bottom",closeDelay:0,maxWidth:200,zIndex:999999999},n={position:"top",type:"info",closeDelay:0,maxWidth:250,zIndex:999999999};var s=function(t,e,o,n){var i;e[0]=0;for(var r=1;r<e.length;r++){var d=e[r++],l=e[r]?(e[0]|=d?1:2,o[e[r++]]):e[++r];3===d?n[0]=l:4===d?n[1]=Object.assign(n[1]||{},l):5===d?(n[1]=n[1]||{})[e[++r]]=l:6===d?n[1][e[++r]]+=l+"":d?(i=t.apply(l,s(t,l,o,["",null])),n.push(i),l[0]?e[0]|=2:(e[r-2]=0,e[r]=i)):n.push(l)}return n},i=new Map;(function(t){var e=i.get(this);return e||(e=new Map,i.set(this,e)),(e=s(this,e.get(t)||(e.set(t,e=function(t){for(var e,o,n=1,s="",i="",r=[0],d=function(t){1===n&&(t||(s=s.replace(/^\s*\n\s*|\s*\n\s*$/g,"")))?r.push(0,t,s):3===n&&(t||s)?(r.push(3,t,s),n=2):2===n&&"..."===s&&t?r.push(4,t,0):2===n&&s&&!t?r.push(5,0,!0,s):n>=5&&((s||!t&&5===n)&&(r.push(n,0,s,o),n=6),t&&(r.push(n,t,0,o),n=6)),s=""},l=0;l<t.length;l++){l&&(1===n&&d(),d(l));for(var a=0;a<t[l].length;a++)e=t[l][a],1===n?"<"===e?(d(),r=[r],n=3):s+=e:4===n?"--"===s&&">"===e?(n=1,s=""):s=e+s[0]:i?e===i?i="":s+=e:'"'===e||"'"===e?i=e:">"===e?(d(),n=1):n&&("="===e?(n=5,o=s,s=""):"/"===e&&(n<5||">"===t[l][a+1])?(d(),3===n&&(r=r[0]),n=r,(r=r[0]).push(2,0,n),n=0):" "===e||"\t"===e||"\n"===e||"\r"===e?(d(),n=2):s+=e),3===n&&"!--"===s&&(n=4,r=r[0])}return d(),r}(t)),e),arguments,[])).length>1?e:e[0]}).bind((function(t,s){this[0]=3;for(var i=arguments.length,d=new Array(i>2?i-2:0),l=2;l<i;l++)d[l-2]=arguments[l];if("function"==typeof t){const e=s?.bindTo;e&&delete s.bindTo;const o=new t(s).render(),n=o.querySelector("[children-container]")||o;if(n.append(...d.flat()),n.removeAttribute("children-container"),Array.isArray(e)){const[t,n]=e;t&&"object"==typeof t&&["string","number"].includes(typeof n)&&(t[n]=o)}return o}if("string"==typeof t){const i=document.createElement(t);return s&&Object.entries(s).forEach((t=>{let[s,d]=t;if(s.startsWith("on"))Array.isArray(d)?d.forEach((t=>i.addEventListener(s.substring(2).toLowerCase(),t))):"function"==typeof d&&i.addEventListener(s.substring(2).toLowerCase(),d);else if("className"===s&&"string"==typeof d)i.classList.add(...d.split(" "));else if("tooltip"===s&&"string"==typeof d)l=i,a=d,r(e).then((()=>{if(!window.Tooltip)return;const t=new window.Tooltip({...o,target:l,content:{title:a}});l.updateTooltipContent=t.updateContent.bind(t)}));else if("infoTooltip"===s&&d&&"object"==typeof d)!function(t,o){r(e).then((()=>{if(!window.Tooltip)return;const e=new window.Tooltip({...n,target:t,content:o});t.updateTooltipContent=e.updateContent.bind(e)}))}(i,d);else if("bindTo"===s){if(Array.isArray(d)){const[t,e]=d;t&&"object"==typeof t&&["string","number"].includes(typeof e)&&(t[e]=i)}}else"testid"===s||("string"==typeof d||"number"==typeof d?i.setAttribute(s,d.toString()):"boolean"==typeof d&&d?i.setAttribute(s,""):d&&(i[s]=d));var l,a})),i.append(...d.flat()),i}if(t instanceof Element)return t;throw new Error("Неверный тип для создания элемента")}));function r(t){const e=(Array.isArray(t)?t:[t]).map((t=>{const e=t.split("."),o=e.pop()?.toLowerCase(),n=window.ver?"?v="+window.ver:"";return"js"===o||"css"===o?function(t,e){return new Promise(((o,n)=>{const s="style"===e,i=s?"link":"script",r=s?"href":"src";let d;try{const{pathname:e}=new URL(t,window.location.href);d=e}catch(e){d=t}const l=document.querySelector(`${i}[${r}*="${d}"]`);if(l)return"true"===l.getAttribute("data-loading")?(l.addEventListener("load",o),void l.addEventListener("error",n)):o(new Event("load"));const a=document.createElement(i);a.setAttribute(r,t),s&&a.setAttribute("rel","stylesheet"),a.setAttribute("data-loading","true"),a.addEventListener("load",(()=>{a.removeAttribute("data-loading"),o(new Event("load"))})),a.addEventListener("error",(()=>{document.head.removeChild(a),n(new Error(`Failed to load resource: ${t}`))})),document.head.appendChild(a)}))}(t+n,"js"===o?"script":"style"):Promise.reject(new Error("Unknown resource extension. Make sure the resource url ends with .css or .js"))}));return Promise.all(e)}class d{constructor(t,e){var o=this;if(!(t instanceof HTMLSelectElement))throw new TypeError("select must be a HTMLSelectElement");e="[object Object]"===Object.prototype.toString.call(e)?e:{},this.config={theme:["light","dark"].includes(e.theme)?e.theme:"light",height:e.height&&!isNaN(e.height)?e.height:40,iconSize:d.getIconSize(e.iconSize),minWidth:e.minWidth||null,fontSize:e.fontSize&&!isNaN(e.fontSize)?e.fontSize:null,customClassName:e.customClassName||null,maxHeight:e.maxHeight&&!isNaN(e.maxHeight)?e.maxHeight:300,maxWidth:e.maxWidth||null},this.id=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6;const o=new Uint8Array(1);crypto.getRandomValues(o);const n=t+o[0]%(e-t+1),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",i=s+"0123456789",r=new Uint8Array(n);crypto.getRandomValues(r);let d=s[r[0]%52];for(let t=1;t<n;t++)d+=i[r[t]%62];return d}(),this.select=t,this.disabled=this.select.disabled,this.options=this.getOptions(),this.isDropdownOpened=!1,this.dropdownHeight=this.config.maxHeight,this.touchStartPos=-1,this.openDropdown=this.openDropdown.bind(this),this.handleDocClick=this.handleDocClick.bind(this),this.handleDocKeyDown=this.handleDocKeyDown.bind(this),this.handleOptionClick=this.handleOptionClick.bind(this),this.handleSelectChange=this.handleSelectChange.bind(this),this.preventScroll=this.preventScroll.bind(this),this.handleDropdownScroll=this.handleDropdownScroll.bind(this),this.updateDropdownPosition=this.updateDropdownPosition.bind(this),this.handleOptionFocus=this.handleOptionFocus.bind(this);const n=this.performDropdownScroll.bind(this);let s=null;const i=()=>this.isDropdownOpened;this.scrollShift={value:0,setValue:function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];i()&&(e&&s&&(window.clearInterval(s),s=null),o.value=e?t:o.value+t,Math.abs(o.value)<.5&&(o.value=0),Math.abs(o.value)>5&&!s&&(s=window.setInterval((()=>{const t=5*Math.sign(o.value);n(t),o.value=(Math.abs(o.value)-5)*Math.sign(o.value),Math.abs(o.value)<=5&&(o.value=0,s&&(window.clearInterval(s),s=null))}),0)),Math.abs(o.value)<=5&&(n(o.value),o.value=0,s&&(window.clearInterval(s),s=null)))}},this.init()}init(){const{theme:t,height:e,minWidth:o,customClassName:n}=this.config,s=document.createElement("button");s.classList.add("tsel"),s.type="button",s.role="combobox",s.ariaExpanded=!1,s.ariaControls=this.id,s.setAttribute("aria-owns",this.id),"dark"===t&&s.classList.add("tsel_dark"),s.style.minHeight=`${e}px`,this.disabled&&s.classList.add("tsel_disabled"),n&&s.classList.add(n),this.select.after(s),s.append(this.select),this.select.style.display="none";const i=document.createElement("div");i.classList.add("tsel-dropdown","tsel-dropdown_hidden"),"dark"===t&&i.classList.add("tsel-dropdown_dark"),o&&(i.style.minWidth=o),i.role="listbox",i.id=this.id;const r=this.select.getAttribute("data-hint");if(r){const t=document.createElement("div");t.classList.add("tsel-dropdown__hint"),t.innerHTML=r,i.append(t)}this.createOptionsElements(),i.prepend(...this.options.map((t=>t.element)));const d=document.createElement("div");d.classList.add("tsel-dropdown__scroll-top"),this.dropdownScrollTopIcon=d;const l=document.createElement("div");l.classList.add("tsel-dropdown__scroll-bottom"),this.dropdownScrollBottomIcon=l;const a=document.createElement("div");a.classList.add("tsel__selected-option"),s.append(a);const c=document.createElement("div");c.classList.add("tsel__noaction"),this.container=s,this.dropdown=i,this.selectedElement=a,this.noaction=c,this.setSelectedElement(),this.setHandlers()}destroy(){this.closeDropdown(),this.container.removeEventListener("click",this.openDropdown),this.select.removeEventListener("change",this.handleSelectChange),this.removeOptionsHandlers(),this.container.before(this.select),this.container.remove()}update(){this.isDropdownOpened&&this.closeDropdown(),this.removeOptionsHandlers(),this.options.forEach((t=>{let{element:e}=t;return e.remove()})),this.options=this.getOptions(),this.createOptionsElements(),this.setOptionsHandlers(),this.dropdown.prepend(...this.options.map((t=>t.element))),this.selectedElement.innerHTML="",this.setSelectedElement(),this.disabled=this.select.disabled,this.container.classList.toggle("tsel_disabled",this.disabled)}getOptions(){return Array.from(this.select.querySelectorAll("option, optgroup")).map((t=>{const e="OPTGROUP"===t.tagName,o=t.parentElement&&"OPTGROUP"===t.parentElement.tagName;return{type:e?"group":"option",value:e?void 0:t.value,img:e?void 0:t.getAttribute("data-img"),darkImg:e?void 0:t.getAttribute("data-img-dark"),label:e?t.label?.replace(/\n/g,"").trim():t.textContent.replace(/\n/g,"").trim(),disabled:e?void 0:t.disabled,selected:e?void 0:t.selected,fontFamily:t.getAttribute("data-font-family"),fontWeight:t.getAttribute("data-font-weight"),noInvert:e?void 0:t.hasAttribute("data-no-invert"),isInGroup:o}}))}createOptionsElements(){const t=this.options.some((t=>t.img)),{theme:e,iconSize:o}=this.config;this.options.forEach((n=>{if("group"===n.type){const t=document.createElement("div");return t.classList.add("tsel-dropdown__group"),n.fontFamily&&(t.style.fontFamily=`${n.fontFamily}, tfutura, Arial, sans-serif`),n.fontWeight&&(t.style.fontWeight=n.fontWeight),n.label&&(t.textContent=n.label),void(n.element=t)}const s=document.createElement("button");if(s.type="button",s.classList.add("tsel-dropdown__option"),n.selected&&(s.classList.add("tsel-dropdown__option_selected"),s.ariaSelected=!0),n.disabled&&(s.classList.add("tsel-dropdown__option_disabled"),s.disabled=!0),n.isInGroup&&s.classList.add("tsel-dropdown__option_group"),n.img||t){const t=document.createElement("div");t.classList.add("tsel-dropdown__option-image"),n.noInvert&&t.classList.add("tsel-dropdown__option-image_no-invert"),t.style.width=`${o[0]}px`,t.style.height=`${o[1]}px`,n.img?t.style.backgroundImage=`url('${"dark"===e&&n.darkImg?n.darkImg:n.img}')`:t.classList.add("tsel-dropdown__option-image_placeholder"),s.append(t)}if(n.label){const t=document.createElement("div");t.classList.add("tsel-dropdown__option-label");const e=document.createElement("span");e.classList.add("tsel-dropdown__option-span"),e.textContent=n.label,n.fontFamily&&(e.style.fontFamily=`${n.fontFamily}, tfutura, Arial, sans-serif`),n.fontWeight&&(e.style.fontWeight=n.fontWeight),t.append(e),s.append(t)}n.element=s}))}setHandlers(){this.container.addEventListener("click",this.openDropdown),this.select.addEventListener("change",this.handleSelectChange),this.setOptionsHandlers()}setOptionsHandlers(){this.options.forEach((t=>{const{element:e}=t;e.addEventListener("mouseenter",this.handleOptionHover),e.addEventListener("mouseleave",this.handleOptionLeave),e.addEventListener("click",this.handleOptionClick),e.addEventListener("focus",this.handleOptionFocus),t.disabled||e.addEventListener("mousemove",this.handleOptionMousemove)}))}removeOptionsHandlers(){this.options.forEach((t=>{const{element:e}=t;e.removeEventListener("mouseenter",this.handleOptionHover),e.removeEventListener("mouseleave",this.handleOptionLeave),e.removeEventListener("click",this.handleOptionClick),e.removeEventListener("focus",this.handleOptionFocus),e.removeEventListener("mousemove",this.handleOptionMousemove)}))}setSelectedElement(){const{fontSize:t}=this.config,e=this.options.find((t=>t.selected));if(!e)return;const o=e.element.cloneNode(!0),n=o.querySelector(".tsel-dropdown__option-span");n&&n.removeAttribute("style");const s=o.querySelector(".tsel-dropdown__option-label");s&&t&&(s.style.fontSize=`${t}px`);const i=Array.from(o.children);this.selectedElement.innerHTML="",this.selectedElement.append(...i)}openDropdown(){if(this.disabled||this.isDropdownOpened||!this.options.length)return;const{maxHeight:t,maxWidth:e}=this.config,o=this.container.getBoundingClientRect(),n=document.documentElement.clientHeight;this.dropdownHeight=Math.min(t,n-10),this.dropdown.style.width=e?`min(${o.width}px, ${e})`:`${o.width}px`,this.dropdown.style.maxHeight=`${this.dropdownHeight}px`,this.dropdown.style.left=`${Math.max(5,o.left)}px`,document.body.append(this.noaction,this.dropdown);const s=this.options.find((t=>t.selected))?.element||this.options[0].element;s.focus({preventScroll:!0});const i=Math.min(this.dropdown.clientHeight,t),r=s.offsetTop+s.clientHeight/2,d=this.dropdown.clientHeight/2,l=r-d,a=this.dropdown.scrollHeight-this.dropdown.clientHeight;let c=0;l>a&&(c=l-a),l<0&&(c=l);const h=o.top+o.height/2,p=Math.min(n-10-i,Math.max(5,h-d-c)),u=Math.max(0,5-(h-d-c));this.dropdown.style.top=`${p}px`,this.dropdownHeight=Math.max(i,Math.min(t-u,n-p-10)),this.dropdown.style.maxHeight=`${this.dropdownHeight}px`,this.dropdown.scrollTop=l+u,document.addEventListener("click",this.handleDocClick),document.addEventListener("keydown",this.handleDocKeyDown,{capture:!0,passive:!1}),document.addEventListener("touchstart",this.preventScroll,{passive:!1}),document.addEventListener("touchmove",this.preventScroll,{passive:!1}),window.addEventListener("resize",this.updateDropdownPosition),document.addEventListener("wheel",this.preventScroll,{capture:!0,passive:!1}),this.dropdown.addEventListener("wheel",this.handleDropdownScroll,{passive:!1}),this.isDropdownOpened=!0,this.container.ariaExpanded=!0,this.dropdown.classList.remove("tsel-dropdown_hidden"),this.updateDropdownScrollIcons()}closeDropdown(){this.dropdown.classList.add("tsel-dropdown_hidden"),window.setTimeout((()=>{this.scrollShift.setValue(0,!0),this.dropdown.scrollTop=0,this.dropdownScrollBottomIcon.remove(),this.dropdownScrollTopIcon.remove(),this.dropdown.remove(),this.noaction.remove(),document.removeEventListener("click",this.handleDocClick),document.removeEventListener("keydown",this.handleDocKeyDown,{capture:!0,passive:!1}),document.removeEventListener("touchstart",this.preventScroll,{passive:!1}),document.removeEventListener("touchmove",this.preventScroll,{passive:!1}),window.removeEventListener("resize",this.updateDropdownPosition),document.removeEventListener("wheel",this.preventScroll,{capture:!0,passive:!1}),this.dropdown.removeEventListener("wheel",this.handleDropdownScroll,{passive:!1}),this.dropdown.querySelectorAll(".tsel-dropdown__option-span").forEach((t=>{t.style.removeProperty("transition-duration"),t.style.removeProperty("transform")})),this.isDropdownOpened=!1,this.container.focus(),this.container.ariaExpanded=!1}),100)}handleDocClick(t){this.container.contains(t.target)||this.dropdown.contains(t.target)||this.closeDropdown()}handleDocKeyDown(t){if("Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),this.closeDropdown()),["ArrowUp","ArrowDown","PageUp","PageDown"].includes(t.key)&&(t.preventDefault(),t.stopPropagation(),["ArrowUp","ArrowDown"].includes(t.key))){const e=this.options.findIndex((t=>t.element===document.activeElement));if("ArrowUp"===t.key){const t=Math.max(0,e-1),o=this.options.findLast(((e,o)=>!e.disabled&&o<=t));o&&o.element.focus({preventScroll:!0})}else{const t=Math.min(this.options.length-1,e+1),o=this.options.find(((e,o)=>!e.disabled&&o>=t));o&&o.element.focus({preventScroll:!0})}}"Tab"===t.key&&(t.preventDefault(),t.stopPropagation());const e=t.key.toLowerCase();if(/^[a-zа-я]$/.test(e)&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey){t.preventDefault(),t.stopPropagation();const o=this.options.find((t=>t.label.toLowerCase().startsWith(e)));o&&o.element.focus({preventScroll:!0})}}preventScroll(t){if(this.dropdown.contains(t.target)){const e=this.dropdown.scrollHeight,o=this.dropdown.scrollTop,n=this.dropdown.clientHeight,s=Math.abs(o-(e-n))<1;if((t.deltaY<0&&!o||t.deltaY>=0&&s||["touchstart","touchmove"].includes(t.type))&&("touchstart"!==t.type&&t.preventDefault(),"touchstart"===t.type&&(this.touchStartPos=t.touches[0]?.clientY||-1),"touchmove"===t.type&&this.touchStartPos>-1)){const e=t.changedTouches[0]?.clientY||-1,o=this.touchStartPos;this.touchStartPos=e,e>-1&&this.dropdown.dispatchEvent(new WheelEvent("wheel",{deltaY:o-e}))}}else"touchstart"!==t.type&&(t.preventDefault(),t.stopPropagation())}handleOptionHover(){const t=this.querySelector(".tsel-dropdown__option-span");if(!t)return;let e=t.parentElement.offsetWidth-t.offsetWidth;if(e=Math.min(e,0),e){const o=60,n=Math.abs(e)/o;t.style.setProperty("transition-duration",`${n}s`),t.style.setProperty("transform",`translateX(${e}px)`)}}handleOptionLeave(){const t=this.querySelector(".tsel-dropdown__option-span");t&&(t.style.removeProperty("transition-duration"),t.style.removeProperty("transform"))}handleOptionClick(t){const e=t.target.closest(".tsel-dropdown__option"),o=this.options.find((t=>t.element===e));o.disabled||(o.selected||(this.select.value=o.value,window.setTimeout((()=>{this.select.dispatchEvent(new Event("change"))}),100)),this.closeDropdown())}handleOptionMousemove(){const t=this;document.activeElement!==t&&t.focus({preventScroll:!0})}handleOptionFocus(t){const e=t.target.getBoundingClientRect(),o=this.dropdown.getBoundingClientRect(),n=e.top-o.top,s=n+e.height-o.height,i=n<0?n-10:s>0?s+10:0;i&&this.scrollShift.setValue(i,!0)}handleSelectChange(){const t=this.select.value,e=this.options.find((e=>e.value===t));if(!e)return;const o=this.options.find((t=>t.selected));o&&(o.selected=!1,o.element.classList.remove("tsel-dropdown__option_selected"),o.element.ariaSelected=!1),e.selected=!0,e.element.classList.add("tsel-dropdown__option_selected"),e.element.ariaSelected=!0,this.setSelectedElement()}handleDropdownScroll(t){t.preventDefault();const{deltaY:e}=t;this.scrollShift.setValue(e,Math.sign(this.scrollShift.value)!==Math.sign(e))}performDropdownScroll(t){if(!(t=Math.ceil(Math.abs(t))*Math.sign(t)))return;const e=document.documentElement.clientHeight,o=this.dropdown.offsetTop,n=this.dropdown.scrollTop,s=this.dropdown.scrollHeight,i=this.dropdown.clientHeight,r=Math.abs(n-(s-i))<1;if(this.dropdownHeight===e-10||5===o&&t>0||t>0&&r||t<0&&0===n)return this.dropdown.scrollTop=n+t,void this.updateDropdownScrollIcons();if(o>5&&t>0){const e=Math.max(5,o-Math.abs(t));this.dropdown.style.top=`${e}px`}t<0&&(this.dropdown.scrollTop=n+t),this.dropdownHeight+=Math.abs(t),this.dropdownHeight=Math.min(this.dropdownHeight,e-this.dropdown.offsetTop-5),this.dropdown.style.maxHeight=`${this.dropdownHeight}px`,this.updateDropdownScrollIcons()}updateDropdownPosition(){const{maxWidth:t}=this.config;if(!this.isDropdownOpened)return;const e=this.container.getBoundingClientRect();this.dropdown.style.width=t?`min(${e.width}px, ${t})`:`${e.width}px`;this.dropdown.style.left=`${Math.max(5,e.left)}px`}updateDropdownScrollIcons(){const{scrollTop:t,clientHeight:e,scrollHeight:o}=this.dropdown,n=o-e;t>0?this.dropdown.prepend(this.dropdownScrollTopIcon):this.dropdownScrollTopIcon.remove(),o!==e&&Math.abs(t-n)>=1?this.dropdown.append(this.dropdownScrollBottomIcon):this.dropdownScrollBottomIcon.remove()}static getIconSize(t){const e=Array.isArray(t)?t:[t];return e.length||e.push(18,18),1===e.length&&e.push(e[0]),e.splice(2,e.length),e.every((t=>t&&!isNaN(t)))?e:[18,18]}}window.TSelectbox=d})();