const init_admin_button_preview = function () { const $ = jQuery const execute = () => { $("#api_key_private").blur(function() { var key = $(this).val(); if( key.length === 0){ $(".weglot-keyres").remove(); $("#api_key_private").after(''); $("#wrap-weglot #submit").prop("disabled", true); return; } function validApiKey(response){ $(".weglot-keyres").remove(); $("#api_key_private").after( '' ); $("#wrap-weglot #submit").prop( "disabled", false ); const evt = new CustomEvent("weglotCheckApi", { detail: response }); window.dispatchEvent(evt); } function unvalidApiKey(){ $(".weglot-keyres").remove(); $("#api_key_private").after('

Make sure you enter a valid Weglot API key. If the key is still not validating, you can contact your host provider and ask if it\'s possible to whitelist api.weglot.com and weglot.com

'); $("#wrap-weglot #submit").prop("disabled", true); } $(".weglot-keyres").remove(); $("#api_key_private").after(''); $.ajax( { method: 'POST', url: ajaxurl, data : { action: 'get_user_info', api_key: key, }, success: ({data, success}) => { $(".weglot-keyres").remove(); if (success ){ validApiKey(data) } else{ unvalidApiKey() } } } ).fail(function() { unvalidApiKey() }); }); $( ".toplevel_page_weglot-settings form" ).submit(function( event ) { $("#wrap-weglot #submit").prop("disabled", true); }); } document.addEventListener('DOMContentLoaded', () => { execute(); }) } export default init_admin_button_preview;