1 line
7.7 KiB
JavaScript
1 line
7.7 KiB
JavaScript
|
(()=>{"use strict";var t,e={5062:(t,e,i)=>{var n=i(5311),o=i.n(n);const a=(t,e=!("true"===t.getAttribute("aria-expanded")))=>{const i=document.querySelector(`#${t.getAttribute("aria-controls")}`);i&&(t.setAttribute("aria-expanded",`${e}`),e?i.removeAttribute("hidden"):"onbeforematch"in document.body?i.setAttribute("hidden","until-found"):i.setAttribute("hidden",""),t.dispatchEvent(new CustomEvent("commentAnchorVisibilityChange",{bubbles:!0})),t.dispatchEvent(new CustomEvent("wagtail:panel-toggle",{bubbles:!0,cancelable:!1,detail:{expanded:e}})))};function s(t){const e=t.closest("[data-panel]"),i=document.querySelector(`#${t.getAttribute("aria-controls")}`);if(!i||!e||e.collapsibleInitialised)return;e.collapsibleInitialised=!0;const n=a.bind(null,t),o=e.classList.contains("collapsed"),s=i.querySelector('[aria-invalid="true"], .error, .w-field--error'),r=o&&!s;r&&n(!1),t.addEventListener("click",n.bind(null,void 0));const l=e.querySelector("[data-panel-heading]");l&&l.addEventListener("click",n.bind(null,void 0)),i.addEventListener("beforematch",n.bind(null,!0)),t.dispatchEvent(new CustomEvent("wagtail:panel-init",{bubbles:!0,cancelable:!1,detail:{expanded:!r}}))}var r=i(4038);class l extends r.p{constructor(t){super(t.formsetPrefix,t),this.formsElt=o()("#"+t.formsetPrefix+"-FORMS");for(let t=0;t<this.formCount;t+=1){const e=this.opts.emptyChildFormPrefix.replace(/__prefix__/g,t);this.initChildControls(e)}this.updateControlStates(),setTimeout((()=>{this.formsElt.get(0)?.dispatchEvent(new CustomEvent("w-formset:ready",{bubbles:!0,cancelable:!1,detail:{...t}}))}))}updateControlStates(){this.updateChildCount(),this.updateMoveButtonDisabledStates(),this.updateAddButtonState()}initChildControls(t){const e="inline_child_"+t,i="id_"+t+"-DELETE",n=o()("#"+e),a=n.find("[data-inline-panel-child-move-up]"),s=n.find("[data-inline-panel-child-move-down]");o()("#"+i+"-button").on("click",(()=>{o()("#"+i).val("1").get(0).dispatchEvent(new Event("change",{bubbles:!0})),n.addClass("deleted").slideUp((()=>{this.updateControlStates(),n.get(0).dispatchEvent(new CustomEvent("w-formset:removed",{bubbles:!0,cancelable:!1,detail:{...this.opts}}))}))})),this.opts.canOrder&&(a.on("click",(()=>{const e=n.find(`input[name="${t}-ORDER"]`),i=e.val(),o=n.prevAll(":not(.deleted)").first();if(!o.length)return;const a=o[0].id.replace("inline_child_",""),s=o.find(`input[name="${a}-ORDER"]`),r=s.val();this.animateSwap(n,o),n.insertBefore(o),e.val(r),s.val(i),this.updateControlStates()})),s.on("click",(()=>{const e=n.find(`input[name="${t}-ORDER"]`),i=e.val(),o=n.nextAll(":not(.deleted)").first();if(!o.length)return;const a=o[0].id.replace("inline_child_",""),s=o.find(`input[name="${a}-ORDER"]`),r=s.val();this.animateSwap(n,o),n.insertAfter(o),e.val(r),s.val(i),this.updateControlStates()}))),"1"===o()("#"+i).val()&&(o()("#"+e).addClass("deleted").hide(0,(()=>{this.updateControlStates()})),o()("#"+e).find(".error-message").remove())}updateMoveButtonDisabledStates(){if(this.opts.canOrder){const t=this.formsElt.children(":not(.deleted)");t.each((function(e){const i=0===e,n=e===t.length-1;o()("[data-inline-panel-child-move-up]",this).prop("disabled",i),o()("[data-inline-panel-child-move-down]",this).prop("disabled",n)}))}}updateChildCount(){this.formsElt.children(":not(.deleted)").each((function(t){o()("[data-inline-panel-child-count]",this).first().text(` ${t+1}`)}))}getChildCount(){return o()("> [data-inline-panel-child]",this.formsElt).not(".deleted").length}updateAddButtonState(){if(this.opts.maxForms){const t=o()("#"+this.opts.formsetPrefix+"-ADD");this.getChildCount()>=this.opts.maxForms?t.prop("disabled",!0):t.prop("disabled",!1)}}animateSwap(t,e){const i=this.formsElt,n=i.children(":not(.deleted)");i.css({position:"relative",height:i.height()}),n.each((function(){o()(this).css("top",o()(this).position().top)})).css({position:"absolute",width:"100%"}),t.animate({top:e.position().top},200,(()=>{i.removeAttr("style"),n.removeAttr("style")})),e.animate({top:t.position().top},200,(()=>{i.removeAttr("style"),n.removeAttr("style")}))}initialFocus(t){t&&t.length
|