1 line
3.8 KiB
JavaScript
1 line
3.8 KiB
JavaScript
"use strict";var __webpack_exports__={};const languagesList=jQuery(".post_lang_choice"),initializeConfimationModal=()=>{const{__:t}=wp.i18n,e=jQuery("<div/>",{id:"pll-dialog",style:"display:none;"}).text(t("Are you sure you want to change the language of the current content?","polylang"));languagesList.after(e);const n=new Promise(((n,a)=>{const o=t=>{switch(t){case"yes":languagesList.data("old-value",languagesList.children(":selected").first().val()),n();break;case"no":languagesList.val(languagesList.data("old-value")),a("Cancel")}e.dialog("close")},i={autoOpen:!1,modal:!0,draggable:!1,resizable:!1,title:t("Change language","polylang"),minWidth:600,maxWidth:"100%",open:function(t,e){jQuery("body").hasClass("rtl")&&jQuery(this).parent().css({right:jQuery(this).parent().css("left"),left:"auto"})},close:function(t,e){o("no")},buttons:[{text:t("OK","polylang"),click:function(t){o("yes")}},{text:t("Cancel","polylang"),click:function(t){o("no")}}]};jQuery.ui.version>="1.12.0"?Object.assign(i,{classes:{"ui-dialog":"pll-confirmation-modal"}}):Object.assign(i,{dialogClass:"pll-confirmation-modal"}),e.dialog(i)}));return{dialogContainer:e,dialogResult:n}},initializeLanguageOldValue=()=>{languagesList.attr("data-old-value",languagesList.children(":selected").first().val())};function initMetaboxAutoComplete(){jQuery(".tr_lang").each((function(){var t=jQuery(this).attr("id").substring(8),e=jQuery(this).parent().parent().siblings(".pll-edit-column");jQuery(this).autocomplete({minLength:0,source:ajaxurl+"?action=pll_posts_not_translated&post_language="+jQuery(".post_lang_choice").val()+"&translation_language="+t+"&post_type="+jQuery("#post_type").val()+"&_pll_nonce="+jQuery("#_pll_nonce").val(),select:function(n,a){jQuery("#htr_lang_"+t).val(a.item.id),e.html(a.item.link)}}),jQuery(this).on("blur",(function(){jQuery(this).val()||(jQuery("#htr_lang_"+t).val(0),e.html(e.siblings(".hidden").children().clone()))}))}))}function getCurrentLanguage(){const t=document.querySelector("[name=post_lang_choice]");return null===t?pllDefaultLanguage:t.value}wp.apiFetch.use((function(t,e){return void 0===t.url&&(void 0===t.data||null===t.data?t.path+=(t.path.indexOf("?")>=0?"&lang=":"?lang=")+getCurrentLanguage():t.data.lang=getCurrentLanguage()),e(t)})),jQuery((function(t){initializeLanguageOldValue(),t(".post_lang_choice").on("change",(function(e){const{select:n,dispatch:a,subscribe:o}=wp.data,i=function(){const t=n("core/editor");return!t.getEditedPostAttribute("title")?.trim()&&!t.getEditedPostContent()&&!t.getEditedPostAttribute("excerpt")?.trim()}(),{addQueryArgs:l}=wp.url,s=initializeConfimationModal(),{dialogContainer:r}=s;let{dialogResult:c}=s;const u=e.target;var g;location.pathname.match(/post-new.php/gi)&&i&&(g=u.value,-1!=location.search.indexOf("new_lang")?window.location.search=window.location.search.replace(/(?:new_lang=[^&]*)(&)?(.*)/,"new_lang="+g+"$1$2"):window.location.search=window.location.search+(-1!=window.location.search.indexOf("?")?"&":"?")+"new_lang="+g),t(this).data("old-value")===u.value||i?(initializeLanguageOldValue(),c=Promise.resolve()):r.dialog("open"),c.then((()=>{let e={action:"post_lang_choice",lang:u.value,post_type:t("#post_type").val(),post_id:t("#post_ID").val(),_pll_nonce:t("#_pll_nonce").val()};t.post(ajaxurl,e,(function(){!function(){let t=null;const e=n("core/editor").getCurrentPost(),i=new Promise((function(a,i){t=o((function(){const t=n("core/editor").getCurrentPost(),{id:o,status:s,type:r}=t;n("core").getLastEntitySaveError("postType",r,o)&&i(),e.modified!==t.modified&&(location.pathname.match(/post-new.php/gi)&&"auto-draft"!==s&&o&&window.history.replaceState({id:o},"Post "+o,l("post.php",{post:o,action:"edit"})),a())}))}));a("core/editor").savePost(),i.then((function(){window.location.reload()}),(function(){t()})).catch((function(){t()}))}()}))}),(()=>{}))})),initMetaboxAutoComplete()})); |