/*!*
 **                 _     _                         
 ** __      ___ __ | |   (_)_ __   __ _ _   _  __ _ 
 ** \ \ /\ / / '_ \| |   | | '_ \ / _` | | | |/ _` |
 **  \ V  V /| |_) | |___| | | | | (_| | |_| | (_| |
 **   \_/\_/ | .__/|_____|_|_| |_|\__, |\__,_|\__,_|
 **          |_|                  |___/             
 **
 **        -- wpLingua | WordPress plugin --
 **   Translate and make your website multilingual
 **
 **     https://github.com/julien-jacob/wplingua
 **      https://wordpress.org/plugins/wplingua/
 **              https://wplingua.com/
 **
 **/
jQuery(document).ready(function(r){let o=r("#wplng-translation-editor");function s(n){n.height(0),n.height(n[0].scrollHeight-4)}function d(){r("#wplng-modal-edit-container").hide(),r("#wplng-modal-edit-save").prop("disabled",!1),r("#wplng-modal-container").show(),t.onload="",t.now=""}function n(){0<r("#wplng-modal-container").scrollTop()?r("#wplng-scroll-to-top").fadeIn(400):r("#wplng-scroll-to-top").fadeOut(400)}function l(){e=!1,t={onload:a(),now:a()};let n=o.find(".wplng-edit-language textarea");n.off("keyup.textarea").on("keyup.textarea",function(){s(r(this))}),r(window).resize(function(){n.each(function(){s(r(this))})}),n.each(function(){s(r(this))}),o.find('.wplng-mark-as-reviewed input[type="checkbox"]').change(function(){var n=o.find("#wplng-translation-"+r(this).attr("wplng-lang"));n.removeClass("wplng-status-generated"),n.removeClass("wplng-status-reviewed"),n.removeClass("wplng-status-ungenerated"),this.checked?n.addClass("wplng-status-reviewed"):n.addClass("wplng-status-generated")}),o.find(".wplng-edit-language textarea").each(function(){o.find("#wplng_mark_as_reviewed_"+r(this).attr("lang")).prop("disabled",""==r(this).val().trim())}),o.find(".wplng-edit-language textarea").on("keyup paste",function(){var n=o.find("#wplng-translation-"+r(this).attr("lang")),e=o.find("#wplng_mark_as_reviewed_"+r(this).attr("lang"));n.removeClass("wplng-status-generated"),n.removeClass("wplng-status-reviewed"),n.removeClass("wplng-status-ungenerated"),""==r(this).val().trim()?(n.addClass("wplng-status-ungenerated"),e.prop("checked",!1),e.prop("disabled",!0)):(n.addClass("wplng-status-reviewed"),e.prop("checked",!0),e.prop("disabled",!1))}),o.find(".wplng-generate-spin").hide(),o.find(".wplng-generate").on("click",function(){if("disabled"!=r(this).attr("disabled")){var n=o.find("#wplng-original-language").attr("wplng-lang");let i=o.find(this).attr("wplng-lang");var e=o.find("#wplng-source").html();if(null!=n&&null!=i&&null!=e){let l="#wplng-translation-"+i;o.find(l+" .wplng-generate").attr("disabled",!0),o.find(l+" .wplng-generate-spin").show(),r.ajax({url:wplngI18nTranslation.ajaxUrl,method:"POST",data:{action:"wplng_ajax_translation",text:e,language_source:n,language_target:i},success:function(n){var e,t,a;n.success?(e="#wplng_translation_"+i,r(e).val(n.data),""!=n.data&&(t=o.find("#wplng-translation-"+i),a=o.find("#wplng_mark_as_reviewed_"+i),t.removeClass("wplng-status-generated"),t.removeClass("wplng-status-reviewed"),t.removeClass("wplng-status-ungenerated"),t.addClass("wplng-status-reviewed"),a.prop("checked",!0),a.prop("disabled",!1)),s(r(e)),p(),r(l+" .wplng-generate-spin").hide(),setTimeout(function(){o.find(l+" .wplng-generate").attr("disabled",!1)},8e3)):(console.log("wpLingua - Error:"),console.log(n),o.find(l+" .wplng-generate-spin").removeClass("dashicons-update").removeClass("wplng-spin").addClass("dashicons-no"))},error:function(n){console.log("wpLingua - Error:"),console.log(n),o.find(l+" .wplng-generate-spin").removeClass("dashicons-update").removeClass("wplng-spin").addClass("dashicons-no")}})}}}),o.find(".wplng-edit-language textarea, .wplng-edit-language input").on("change input propertychange",p),r("#submitpost [type=submit], #wplng-modal-edit-save").click(function(){e=!0}),r(window).on("beforeunload",function(){if(!e&&t.onload!=t.now)return confirm(wplngI18nTranslation.message.exitPage)})}r("#toplevel_page_wplingua-settings").removeClass("wp-not-current-submenu").addClass("wp-has-current-submenu"),r("a.toplevel_page_wplingua-settings").addClass("wp-menu-open").addClass("wp-has-current-submenu"),n(),r("#wplng-modal-container").scroll(n),r("#wplng-scroll-to-top").click(function(){r("#wplng-modal-container").animate({scrollTop:0},800)}),r("#wplng-modal-edit-show-all").on("click",function(){r(this).hide(),o.find(".wplng-edit-language").show()});let e=!1,t={onload:a(),now:a()};function a(){let n="";return o.find(".wplng-edit-language textarea").each(function(){n+=r(this).val()}),o.find(".wplng-edit-language input[type=checkbox]").each(function(){n+=r(this).prop("checked")}),n}function p(){t.now=a(),t.onload==t.now?r("#wplng-modal-edit-save").prop("disabled",!0):r("#wplng-modal-edit-save").prop("disabled",!1)}function i(){r("html, body").css("cursor","progress"),r("#wplng-modal-edit-save").text(wplngI18nTranslation.message.buttonSave),r("#wplng-modal-edit-save").prop("disabled",!0);let t=r(this).attr("data-wplng-post"),a=r("#wplng-modal-edit-post").attr("data-wplng-edit-template");a=a.replace("WPLNG_TRANSLATION_ID",t),r.ajax({url:wplngI18nTranslation.ajaxUrl,method:"POST",data:{action:"wplng_ajax_edit_modal",post_id:t},success:function(n){var e;n.success?(e=(n=>{let e=n;return e=(e=(e=(e=(e=e.replace(/&nbsp;/gi," ")).replace(/&amp;/gi,"&")).replace(/&quot;/gi,'"')).replace(/&lt;/gi,"<")).replace(/&gt;/gi,">")})((e=JSON.parse(n.data)).wplng_edit_html),o.html(e),r("#wplng-modal-edit-post").attr("href",a),r("#wplng-modal-edit-container").show(),r("#wplng-modal-container").hide(),r("#wplng-modal-edit-save").attr("data-wplng-post",t),1==o.find(".wplng-edit-language").length?r("#wplng-modal-edit-show-all").hide():r("#wplng-modal-edit-show-all").show(),l(),e=(e=".wplng-edit-language:not([wplng-lang=")+wplngI18nTranslation.currentLanguage+"])",o.find(e).hide()):(console.log("wpLingua - Error:"),console.log(n))},error:function(n){console.log("wpLingua - Error:"),console.log(n)},complete:function(){r("html, body").css("cursor","default")}})}function g(n,a){return r(r(n).toArray().sort(function(n,e){n=r(n).find(a).text(),e=r(e).find(a).text();let t=0;return n<e?t=-1:e<n&&(t=1),t}))}l(),r(".wplng-edit-link[data-wplng-post]").click(i),r("#wplng-modal-edit-return").click(function(){(t.onload==t.now||confirm(wplngI18nTranslation.message.exitEditorModal))&&d()}),r("#wplng-modal-edit-save").click(function(){r("#wplng-modal-edit-save").text(wplngI18nTranslation.message.buttonSaveInProgress);let a=r(this).text(),l=r(this).attr("data-wplng-post"),e={action:"wplng_ajax_save_modal",post_id:l,wplng_translation_meta_box_nonce:o.find("#wplng_translation_meta_box_nonce").val()},i=(o.find(".wplng-translation-textarea").each(function(){var n=r(this).attr("id");e[n]=r(this).val(),"wplng_translation_"+wplngI18nTranslation.currentLanguage==n&&(a=r(this).val())}),1==r("#wplng_mark_as_reviewed_"+wplngI18nTranslation.currentLanguage).prop("checked"));o.find(".wplng-mark-as-reviewed input[type=checkbox]").each(function(){e[r(this).attr("id")]=r(this).prop("checked")}),r.ajax({url:wplngI18nTranslation.ajaxUrl,method:"POST",data:e,success:function(n){var e,t;n.success?(e=r("body.wplingua-editor .wplng-edit-link[data-wplng-post="+l+"]"),t=r("body.wplingua-list .wplng-modal-item[data-wplng-post="+l+"]"),e.text(a),t.find(".wplng-item-translation").text(a),i?(e.addClass("wplng-is-review"),t.addClass("wplng-is-review")):(e.removeClass("wplng-is-review"),t.removeClass("wplng-is-review")),d()):(console.log("wpLingua - Error:"),console.log(n))},error:function(n){console.log("wpLingua - Error:"),console.log(n)}})}),r("#wplng-filter-search, #wplng-filter-status").on("input",function(){let i=r("#wplng-filter-status").val(),o=!1,s=r("#wplng-filter-search").val();s=s.trim().toLowerCase(),r(".wplng-modal-item").each(function(n){let e=r(this).find(".wplng-item-translation").html(),t=r(this).find(".wplng-item-source").html();var a,l;e=e.toLowerCase(),t=t.toLowerCase(),a=""==s||0<=e.indexOf(s)||0<=t.indexOf(s),l="all"==i||"reviewed"==i&&r(this).hasClass("wplng-is-review")||"unreviewed"==i&&!r(this).hasClass("wplng-is-review"),a&&l?(r(this).show(),o=!0):r(this).hide()}),o?r("#wplng-modal-no-item-found").hide():r("#wplng-modal-no-item-found").show()}),r("#wplng-filter-order").on("input",function(){let n=r("#wplng-filter-order").val(),e=[],t="";switch(n){case"alphabetical-sources":e=g(".wplng-modal-item",".wplng-item-source");break;case"alphabetical-translations":e=g(".wplng-modal-item",".wplng-item-translation");break;default:e=((n,t)=>r(r(n).toArray().sort(function(n,e){return parseInt(n.getAttribute(t))-parseInt(e.getAttribute(t))})))(".wplng-modal-item","data-wplng-order")}e.each(function(n){t+=r(this).prop("outerHTML")}),r("#wplng-modal-items").html(t),r("#wplng-modal-items").find(".wplng-edit-link[data-wplng-post]").click(i)})});//# sourceMappingURL=edit-translation.js.map
