1 line
3.8 KiB
JavaScript
1 line
3.8 KiB
JavaScript
function fcn_getWindowPosition(e){let t=e.getBoundingClientRect();return{top:t.top+window.scrollY,left:t.left+window.scrollX}}var fcn_lastPopupMenu;function fcn_togglePopupMenu(e){let t=_$$$(`popup-${e}`);if(t.classList.contains("hidden")){t.classList.remove("hidden"),fcn_lastPopupMenu&&fcn_togglePopupMenu(fcn_lastPopupMenu.dataset.id);let e=t.closest(".fictioneer-settings"),n=fcn_getWindowPosition(t),o=fcn_getWindowPosition(e),i=window.innerWidth<600?0:o.top;t.style.top=n.top-i+"px",t.style.left=n.left-o.left+"px",t.style.transform="translate(-100%, -50%)",e.append(t),fcn_lastPopupMenu=t}else{t.classList.add("hidden");let n=_$$$(`popup-container-${e}`);t.style.top="50%",t.style.left="0",t.style.transform="",n.append(t),fcn_lastPopupMenu=null}}function fcn_purgeSchema(e){jQuery.ajax({url:fictioneer_ajax.ajax_url,type:"post",data:{action:"fictioneer_ajax_purge_schema",nonce:document.getElementById("fictioneer_admin_nonce").value,id:e},dataType:"json",success:function(t){if(t.success){let t=_$$$(`schema-${e}`);t.querySelector(".text-blob").innerHTML=t.querySelector("summary").innerHTML,t.querySelector(".delete").remove(),t.querySelector(".no-schema-note").classList.remove("hidden")}}})}function fcn_delete_epub(e,t){jQuery.ajax({url:fictioneer_ajax.ajax_url,type:"post",data:{action:"fictioneer_ajax_delete_epub",nonce:document.getElementById("fictioneer_admin_nonce").value,name:e},dataType:"json",success:function(e){e.success&&document.getElementById(`epub-id-${t}`).remove()}})}function fcn_checkInputValidity(e){e.classList.toggle("invalid",e.hasAttribute("required")&&""==e.value||!e.checkValidity())}function fcn_ogMediaUpload(e){e.preventDefault();var t=wp.media({multiple:!1}).open().on("select",(function(){let e=t.state().get("selection").first().toJSON();_$$$("fictioneer-seo-og-image").value=e.id,_$$$("fictioneer-seo-og-display").setAttribute("src",e.url),_$$$("fictioneer-button-seo-og-image-remove").classList.remove("hidden"),_$(".og-source").classList.add("hidden")}))}function fcn_update_seo_title_chars(){let e=_$$$("fictioneer-seo-title");"{{title}} – {{site}}"!=e.value?_$$$("fictioneer-seo-title-chars").innerHTML=`(${e.value.length}/70)`:_$$$("fictioneer-seo-title-chars").innerHTML=""}function fcn_remove_seo_og_image(e){e.preventDefault();let t=_$$$("fictioneer-seo-og-display").dataset.placeholder;_$$$("fictioneer-seo-og-image").value="",_$$$("fictioneer-seo-og-display").setAttribute("src",t),_$$$("fictioneer-button-seo-og-image-remove").classList.add("hidden")}function fcn_confirmIt(e){let t=e.currentTarget.dataset.dialogMessage,n=e.currentTarget.dataset.dialogConfirm;if(!t||!n)return;let o=prompt(t);o?o.toLowerCase()!=n.toLowerCase()&&e.preventDefault():e.preventDefault()}_$$(".popup-menu-toggle").forEach((e=>{e.addEventListener("click",(e=>{fcn_togglePopupMenu(e.currentTarget.dataset.id),e.stopPropagation()}))})),_$("body").addEventListener("click",(()=>{fcn_lastPopupMenu&&fcn_togglePopupMenu(fcn_lastPopupMenu.dataset.id)})),window.addEventListener("resize",(()=>{fcn_lastPopupMenu&&fcn_togglePopupMenu(fcn_lastPopupMenu.dataset.id)})),_$$(".button-purge-schema").forEach((e=>{e.addEventListener("click",(e=>{fcn_purgeSchema(e.currentTarget.dataset.id)}))})),_$$(".button-delete-epub").forEach((e=>{e.addEventListener("click",(e=>{fcn_delete_epub(e.target.dataset.filename,e.target.dataset.id)}))})),_$$(".fictioneer-ui input[type=email]").forEach((e=>{e.addEventListener("blur",(()=>{fcn_checkInputValidity(e)}))})),(button=_$$$("fictioneer-button-og-upload"))&&button.addEventListener("click",fcn_ogMediaUpload),(button=_$$$("fictioneer-seo-title"))&&(fcn_update_seo_title_chars(),button.addEventListener("keyup",fcn_update_seo_title_chars)),(button=_$$$("fictioneer-button-seo-og-image-remove"))&&button.addEventListener("click",fcn_remove_seo_og_image),_$$(".confirm-dialog").forEach((e=>{e.addEventListener("click",(e=>{fcn_confirmIt(e)}))})); |