function brfUploadBundledFonts(){let e=document.querySelector("body.post-type-bricks_fonts");if(!document.querySelector("ul.font-faces"))return;let t=e.querySelectorAll("ul.font-faces");for(let e of t){let t=document.createElement("li");t.innerHTML="<span style='background: rgb(255 218 70 / 25%); color: #c19d0b; border: 0; font-weight: 600; border-radius: 5px;' class='brf-upload-font-bundle button button-primary'>Upload Font Bundle for this style</span>",e.appendChild(t)}let n=document.createElement("span");n.innerHTML="<span style='background: rgb(255 218 70 / 25%); color: #c19d0b; border: 0; font-weight: 600; border-radius: 5px; bottom: -40px; position: absolute; left: 190px;' class='brf-upload-complete-font-bundle button button-primary'>Upload Bundle from the Google Fonts Helper</span>",document.querySelector("#bricks-custom-fonts-add-font-variant").parentNode.insertBefore(n,document.querySelector("#bricks-custom-fonts-add-font-variant").nextSibling),document.addEventListener("click",(function(e){e.target&&e.target.classList.contains("brf-upload-font-bundle")&&brfOpenMedia(event)})),document.querySelector(".brf-upload-complete-font-bundle").addEventListener("click",brfUploadEntireFontBundle)}function brfOpenMedia(e){e.preventDefault();let t=wp.media({title:"Select Fonts",button:{text:"Use these fonts"},frame:"select",multiple:!0});t.open(),t.on("select",(function(){let n=t.state().get("selection").toJSON();if(n)for(let t of n)brfFillFontsInput(t.url,t.id,t.subtype,e.target)}))}function brfFillFontsInput(e,t,n,o){let l=o.closest(".bricks-font-variant").querySelector(".font-face:first-child input[name=font_url]"),r=o.closest(".bricks-font-variant").querySelector(".font-face:nth-child(2) input[name=font_url]"),a=o.closest(".bricks-font-variant").querySelector(".font-face:nth-child(3) input[name=font_url]"),c=o.closest(".bricks-font-variant").querySelector(".font-face:first-child input[name=font_id]"),i=o.closest(".bricks-font-variant").querySelector(".font-face:nth-child(2) input[name=font_id]"),u=o.closest(".bricks-font-variant").querySelector(".font-face:nth-child(3) input[name=font_id]");switch(n){case"woff2":l.value=e,c.value=t;break;case"woff":r.value=e,i.value=t;break;case"ttf":a.value=e,u.value=t}}function brfUploadEntireFontBundle(e){e.preventDefault();let t=wp.media({title:"Select Fonts",button:{text:"Use these fonts"},frame:"select",multiple:!0});t.open(),t.on("select",(function(){let n=t.state().get("selection").toJSON();if(n)for(let t of n){let n,o,l=t.filename,r=t.url,a=t.id,c=t.subtype,i=(e.target,l.split("-v")[0]);document.querySelector("#titlewrap input[name=post_title]").value=i,document.querySelector("#titlewrap label").classList.add("screen-reader-text"),n=l.indexOf("regular")>-1?"400":l.match(/[1-9]\d\d/gm)?l.match(/[1-9]\d\d/gm)[0]:"400",o=l.indexOf("italic")>-1?"italic":"";let u=!1;for(let e of document.querySelectorAll(".bricks-font-variant"))e.querySelector("select[name=font_weight]").value==n&&e.querySelector("select[name=font_style]").value==o&&(u=!0);u||brfAddFontVariant(n,o);for(let e of document.querySelectorAll(".bricks-font-variant")){let t=e.querySelector(".font-face:first-child input[name=font_url]"),l=e.querySelector(".font-face:nth-child(2) input[name=font_url]"),i=e.querySelector(".font-face:nth-child(3) input[name=font_url]"),u=e.querySelector(".font-face:first-child input[name=font_id]"),f=e.querySelector(".font-face:nth-child(2) input[name=font_id]"),s=e.querySelector(".font-face:nth-child(3) input[name=font_id]"),d=e.querySelector("select[name=font_weight]").value,p=e.querySelector("select[name=font_style]").value;if(d.toString()==n.toString()&&p.toString()==o.toString())switch(c){case"woff2":t.value=r,u.value=a;break;case"woff":l.value=r,f.value=a;break;case"ttf":i.value=r,s.value=a}}}}))}function brfAddFontVariant(e,t){var n=document.querySelectorAll(".bricks-font-variant"),o=n[n.length-1],l=!!o&&o.cloneNode(!0);l&&(l.querySelector("[name=font_weight]").value=e,l.querySelector("[name=font_style]").value=t,l.querySelectorAll("input").forEach((function(e){e.value=""})),l.querySelectorAll(".initialized").forEach((function(e){e.classList.remove("initialized")})),l.querySelector("style")&&l.querySelector("style").remove(),l.querySelector(".pangram").removeAttribute("style"),l.querySelectorAll("button").forEach((function(e){e.classList.contains("upload")?(e.classList.remove("hide"),e.id=Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,12)):e.classList.contains("remove")&&e.classList.add("hide")})),o.after(l),bricksCustomFontsUpload(),bricksCustomFontsToggleEdit(),bricksCustomFontsDeleteVariant())}document.addEventListener("DOMContentLoaded",(function(){brfUploadBundledFonts()}));