This commit is contained in:
2024-06-26 00:48:19 +03:00
parent 69c8e0e86c
commit 3228b3cb49
14 changed files with 42 additions and 39 deletions
+1
View File
@@ -0,0 +1 @@
__PluginManager__.register("collapse",(function(t,e,s){var i=t("bsCore"),{defineJQueryPlugin:n,getElement:a,getSelectorFromElement:r,getElementFromSelector:l,reflow:o,typeCheckConfig:g}=i.util.index,{Data:h,EventHandler:c,Manipulator:_,SelectorEngine:d}=i.dom,f=i.BaseComponent;const m="collapse",p="bs.collapse",u=`.${p}`,A={toggle:!0,parent:""},y={toggle:"boolean",parent:"(string|element)"},b=`show${u}`,L=`shown${u}`,C=`hide${u}`,$=`hidden${u}`,T=`click${u}.data-api`,v="show",w="collapse",E="collapsing",x="collapsed",D="width",I='[data-bs-toggle="collapse"]';class P extends f{constructor(t,e){super(t),this._isTransitioning=!1,this._config=this._getConfig(e),this._triggerArray=d.find(`${I}[href="#${this._element.id}"],${I}[data-bs-target="#${this._element.id}"]`);const s=d.find(I);for(let t=0,e=s.length;t<e;t++){const e=s[t],i=r(e),n=d.find(i).filter((t=>t===this._element));null!==i&&n.length&&(this._selector=i,this._triggerArray.push(e))}this._parent=this._config.parent?this._getParent():null,this._config.parent||this._addAriaAndCollapsedClass(this._element,this._triggerArray),this._config.toggle&&this.toggle()}static get Default(){return A}static get NAME(){return m}toggle(){this._element.classList.contains(v)?this.hide():this.show()}show(){if(this._isTransitioning||this._element.classList.contains(v))return;let t,e;this._parent&&(t=d.find(".show, .collapsing",this._parent).filter((t=>"string"==typeof this._config.parent?t.getAttribute("data-bs-parent")===this._config.parent:t.classList.contains(w))),0===t.length&&(t=null));const s=d.findOne(this._selector);if(t){const i=t.find((t=>s!==t));if(e=i?P.getInstance(i):null,e&&e._isTransitioning)return}if(c.trigger(this._element,b).defaultPrevented)return;t&&t.forEach((t=>{s!==t&&P.collapseInterface(t,"hide"),e||h.set(t,p,null)}));const i=this._getDimension();this._element.classList.remove(w),this._element.classList.add(E),this._element.style[i]=0,this._triggerArray.length&&this._triggerArray.forEach((t=>{t.classList.remove(x),t.setAttribute("aria-expanded",!0)})),this.setTransitioning(!0);const n=`scroll${i[0].toUpperCase()+i.slice(1)}`;this._element.style[i]=`${this._element[n]}px`,this._queueCallback((()=>{this._element.classList.remove(E),this._element.classList.add(w,v),this._element.style[i]="",this.setTransitioning(!1),c.trigger(this._element,L)}),this._element,"true"===this._element.getAttribute("data-bs-animated"))}hide(){if(this._isTransitioning||!this._element.classList.contains(v))return;if(c.trigger(this._element,C).defaultPrevented)return;const t=this._getDimension();this._element.style[t]=`${this._element.getBoundingClientRect()[t]}px`,o(this._element),this._element.classList.add(E),this._element.classList.remove(w,v);const e=this._triggerArray.length;if(e>0)for(let t=0;t<e;t++){const e=this._triggerArray[t],s=l(e);s&&!s.classList.contains(v)&&(e.classList.add(x),e.setAttribute("aria-expanded",!1))}this.setTransitioning(!0);this._element.style[t]="",this._queueCallback((()=>{this.setTransitioning(!1),this._element.classList.remove(E),this._element.classList.add(w),c.trigger(this._element,$)}),this._element,"true"===this._element.getAttribute("data-bs-animated"))}setTransitioning(t){this._isTransitioning=t}_getConfig(t){return(t={...A,...t}).toggle=Boolean(t.toggle),g(m,t,y),t}_getDimension(){return this._element.classList.contains(D)?D:"height"}_getParent(){let{parent:t}=this._config;t=a(t);const e=`${I}[data-bs-parent="${t}"]`;return d.find(e,t).forEach((t=>{const e=l(t);this._addAriaAndCollapsedClass(e,[t])})),t}_addAriaAndCollapsedClass(t,e){if(!t||!e.length)return;const s=t.classList.contains(v);e.forEach((t=>{s?t.classList.remove(x):t.classList.add(x),t.setAttribute("aria-expanded",s)}))}static collapseInterface(t,e){let s=P.getInstance(t);const i={...A,..._.getDataAttributes(t),..."object"==typeof e&&e?e:{}};if(!s&&i.toggle&&"string"==typeof e&&/show|hide/.test(e)&&(i.toggle=!1),s||(s=new P(t,i)),"string"==typeof e){if(void 0===s[e])throw new TypeError(`No method named "${e}"`);s[e]()}}static jQueryInterface(t){return this.each((function(){P.collapseInterface(this,t)}))}}return c.on(document,T,I,(function(t){("A"===t.target.tagName||t.delegateTarget&&"A"===t.delegateTarget.tagName)&&t.preventDefault();const e=_.getDataAttributes(this),s=r(this);d.find(s).forEach((t=>{const s=P.getInstance(t);let i;s?(null===s._parent&&"string"==typeof e.parent&&(s._config.parent=e.parent,s._parent=s._getParent()),i="toggle"):i=e,P.collapseInterface(t,i)}))})),n(P),s.exports=P,s.exports}));