var WPML_core=WPML_core||{};WPML_core.languageSwitcher=function(a,b){"use strict";var c,d,e,f,g,h="wpml-ls-inline-styles-additional-css",i="wpml-ls-inline-styles-dialog",j=function(){c=a("#wpml-ls-settings-form"),d=a("#wpml-ls-dialog"),e=c.add(d),l(),q(),x(),p(),k(),r(),a(document).trigger("wpml_ls_admin_loaded")},k=function(){m(),n(),o(),y(),z(),A(),D(),Z(),$(),Y(),ba(),E(),F(),G(),H()},l=function(){if(a("#"+h).length<1){var b=a("");a("#"+b).replaceWith(c)})},Z=function(){e.on("change",".js-wpml-ls-template-selector",function(){var c=a(this).val(),d=a(this).closest(".js-wpml-ls-subform"),e=b.templates[c].force_settings;d.find(".js-wpml-ls-to-include input").prop("disabled",!1),jQuery.each(e,function(a,b){1===b?d.find(".js-wpml-ls-setting-"+a).attr("checked","checked").prop("disabled",!0):d.find(".js-wpml-ls-setting-"+a).removeAttr("checked").prop("disabled",!0)})})},$=function(){e.on("change",".js-wpml-ls-menu-is-hierarchical",function(){var b=parseInt(a(this).val()),c=a(this).closest(".js-wpml-ls-subform"),d=c.find(".js-wpml-ls-setting-display_link_for_current_lang");d.prop("disabled",!1),1===b&&d.attr("checked","checked").prop("disabled",!0)})},aa=_.debounce(function(c){a(".js-wpml-ls-dialog-save").prop("disabled",!0);var d=c.find(".js-wpml-ls-preview");if(d.length>0){ea(d);var e=da(c);wp.ajax.send({data:{action:"wpml-ls-update-preview",nonce:b.nonce,slot_settings:e},success:function(a){d.empty(),ga(a.styles),ia(a.css),ja(a.js),fa(d,a.html)},error:function(a){fa(d,a,0,"error")}})}},500),ba=function(){c.on("click",".js-wpml-ls-save-settings",function(b){b.preventDefault(),ca(a(this))})},ca=_.debounce(function(a,d){var e=a.closest(".js-wpml-ls-option").find(".js-wpml-ls-messages"),f=da(c);0===e.length&&(e=a.closest(".js-wpml-ls-section").find(".js-wpml-ls-messages")),e.empty(),ea(e),wp.ajax.send({data:{action:"wpml-ls-save-settings",nonce:b.nonce,settings:f},success:function(a){fa(e,a,2500,"updated"),"function"==typeof d&&d()},error:function(a){fa(e,a,2500,"error")}})},500),da=function(a){var b=a.find(":input:disabled").removeAttr("disabled"),c=a.find("input, select, textarea").serialize();return b.attr("disabled","disabled"),c},ea=function(b){a(".js-wpml-ls-messages").removeClass("success error").hide().empty(),b.siblings(".spinner").addClass("is-active")},fa=function(b,c,d,e){b.siblings(".spinner").removeClass("is-active"),b.removeClass("updated notice error"),e&&b.addClass(e),b.html(c).fadeIn(),d&&b.delay(d).fadeOut(),a(".js-wpml-ls-dialog-save").prop("disabled",!1)},ga=function(b){if(a("#"+i).remove(),b){var c;c=b instanceof jQuery?b:a(a.parseHTML(b)).first(),c.attr("id",i),a("#"+h).before(c)}},ha=function(b,c){var d=a("#"+i).clone(),e="wpml-ls-inline-styles-"+b+"-"+c,f=a("#"+e);d.attr("id",e),f.length?f.replaceWith(d):a("#"+h).before(d)},ia=function(b){var c,d;if(void 0!==b&&null!==b)for(c=0;c"),d.attr("rel","stylesheet"),d.attr("type","text/css"),d.attr("media","all"),d.attr("href",b[c]),d.prependTo("head"))},ja=function(b){var c,d;if(void 0!==b&&null!==b)for(c=0;c"),d.attr("type","text/javascript"),d.attr("src",b[c]),d.prependTo("head"))};return{init:j}}(jQuery,wpml_language_switcher_admin),jQuery(document).ready(function(){"use strict";WPML_core.languageSwitcher.init()});