a12s-1.0.0-beta7/modules/theme_builder/js/components/disclosure.js

modules/theme_builder/js/components/disclosure.js
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.A12s=e():(t.A12s=t.A12s||{},t.A12s.Disclosure=e())}(self,(()=>(()=>{"use strict";var t={d:(e,s)=>{for(var n in s)t.o(s,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:s[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function s(t,e){for(;t.childNodes.length>0;)e.appendChild(t.childNodes[0])}t.d(e,{default:()=>i});class n{constructor(t,e){var s;this.eventListener=null,this.transitioning=!1,this.element=t,this.settings=Object.assign({ariaAttribute:n.DEFAULT_ARIA_ATTRIBUTE,collapseOthers:!1,atLeastOneExpanded:!1},e);const i=[];this.isWrapped=!("wrap"in this.element.dataset&&"false"===this.element.dataset.wrap),"target"in this.element.dataset&&""!==this.element.dataset.target&&this.element.dataset.target.split(",").forEach((t=>{""!==(t=t.trim())&&i.push([t,{}])})),i.length||null===(s=this.element.getAttribute("aria-controls"))||void 0===s||s.split(/\s*,\s*/).forEach((t=>{""!==(t=t.trim())&&i.push(["#"+t,{}])})),this.targets=new Map(i),this.attach()}attach(){var t;null===this.eventListener&&(null===(t=this.targets)||void 0===t?void 0:t.size)&&(this.getTargetElements().forEach((t=>{const e=t.classList.contains(n.EXPANDED_CLASS);if(this.setExpandedState(t,e),this.isWrapped){t.classList.add("disclosure-panel");const e=document.createElement("div");e.classList.add("disclosure-panel-inner");const n=document.createElement("div");n.classList.add("disclosure-panel-content"),s(t,n),e.insertAdjacentElement("afterbegin",n),t.insertAdjacentElement("afterbegin",e)}else t.classList.add("disclosure-target");this.toggleContent(t,this.isExpanded())})),this.eventListener=this.onClick.bind(this),this.element.addEventListener("click",this.eventListener))}setExpandedState(t,e){if(t.id){const s="#"+t.id;if(this.targets.has(s)){const t=this.targets.get(s);t.expanded=e,this.targets.set(s,t)}}}getGroup(){return"group"in this.settings&&void 0!==this.settings.group?this.settings.group:null}getOthers(){const t=this.getGroup();return t?[...n.instances.values()].filter((e=>e.getGroup()===t&&e!==this)):[]}isExpanded(){return"true"===this.element.getAttribute(this.settings.ariaAttribute)}getTargetElements(){const t=[];return[...this.targets.keys()].filter((e=>"sibling"!==e||(this.element.nextElementSibling instanceof HTMLElement&&t.push(this.element.nextElementSibling),!1))),document.querySelectorAll([...this.targets.keys()].join(",")).forEach((e=>{e instanceof HTMLElement&&t.push(e)})),t}toggle(){if(!this.transitioning){const t=this.isExpanded();if(t&&this.settings.atLeastOneExpanded&&void 0===this.getOthers().find((t=>t.isExpanded())))return;this.settings.collapseOthers&&!t&&this.getOthers().forEach((t=>{t.isExpanded()&&(t.getTargetElements().forEach((t=>{this.toggleContent(t,!1)})),t.element.setAttribute(this.settings.ariaAttribute,"false"))})),this.transitioning=!0;const e=[],s={detail:{toggle:this.element,disclosureInstance:this}};this.element.dispatchEvent(new CustomEvent(t?"disclosureContent.collapse":"disclosureContent.expand",s)),this.getTargetElements().forEach((s=>{e.push(new Promise((e=>{const n=window.getComputedStyle(s,null),i=Math.max(parseFloat(n.getPropertyValue("animation-duration")||"0"),parseFloat(n.getPropertyValue("transition-duration")||"0"));this.toggleContent(s,!t),i>0?setTimeout((()=>{e()}),1e3*i):e()})))})),this.element.setAttribute(this.settings.ariaAttribute,t?"false":"true"),Promise.all(e).then((()=>{n.instances.forEach(((e,s)=>{var n;if(e!==this){let s=!1;this.targets.size>0&&this.targets.size===(null===(n=e.targets)||void 0===n?void 0:n.size)&&(s=[...this.targets.keys()].every((t=>e.targets.has(t)))),s&&e.element.setAttribute(e.settings.ariaAttribute,t?"false":"true")}})),this.element.dispatchEvent(new CustomEvent(t?"disclosureContent.collapsed":"disclosureContent.expanded",s)),this.transitioning=!1}))}}toggleContent(t,e){t.classList.toggle(n.EXPANDED_CLASS,e),this.setExpandedState(t,e),t.setAttribute("aria-hidden",e?"false":"true")}onClick(t){t.preventDefault(),this.toggle()}destroy(){null!==this.eventListener&&(this.element.removeEventListener("click",this.eventListener),this.eventListener=null),this.getTargetElements().forEach((t=>{const e=t.querySelector(":scope > .disclosure-panel-inner");if(e){const n=e.querySelector(":scope > .disclosure-panel-content");n&&s(n,t),e.remove()}})),n.instances.has(this.element)&&n.instances.delete(this.element)}static init(t={}){const e={toggleSelector:n.DEFAULT_SELECTOR,context:document,ariaAttribute:n.DEFAULT_ARIA_ATTRIBUTE,collapseOthers:!1,atLeastOneExpanded:!1};if((t=Object.assign(Object.assign({},e),t)).context instanceof Element||t.context instanceof Document)if(!("group"in t)||"string"==typeof t.group&&0!==t.group.length||delete t.group,void 0!==t.parentSelector)t.context.querySelectorAll(t.parentSelector).forEach((e=>{const s=Object.assign({},t);delete s.parentSelector,"group"in s||(s.group="disclosureGroup"in e.dataset&&e.dataset.tabsGroup.length>0?e.dataset.tabsGroup:Math.floor(Math.random()*Date.now()).toString(36)),n.init(s)}));else{const e={ariaAttribute:t.ariaAttribute,collapseOthers:t.collapseOthers,atLeastOneExpanded:t.atLeastOneExpanded,group:"group"in t?t.group:void 0};t.context.querySelectorAll(t.toggleSelector).forEach((t=>{n.addInstance(t,e)}))}}static addInstance(t,e={}){return n.instances.has(t)||n.instances.set(t,new n(t,e)),n.instances.get(t)}static getInstance(t){return n.instances.get(t)}static deleteInstance(t){var e;null===(e=n.getInstance(t))||void 0===e||e.destroy()}}n.EXPANDED_CLASS="show",n.DEFAULT_SELECTOR=".disclosure",n.DEFAULT_ARIA_ATTRIBUTE="aria-expanded",n.instances=new Map;const i=n;return e.default})()));
//# sourceMappingURL=disclosure.js.map

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc