/*jshint devel:true */ /*global jQuery, ajaxurl */ var WPML_String_Translation = WPML_String_Translation || {}; WPML_String_Translation.ChangeDomainLanguage = function () { "use strict"; var privateData = {}; var init = function () { jQuery(document).ready(function () { privateData.summary_div = jQuery('#wpml-change-domain-language-dialog').find('.js-summary'); privateData.lang_select = jQuery(privateData.summary_div).find('select'); privateData.apply_button = jQuery('#wpml-change-domain-language-dialog-apply-button'); privateData.table_body = privateData.summary_div.find('table').find('tbody'); privateData.domain_select = jQuery('#wpml-domain-select'); privateData.check_all = jQuery(privateData.summary_div).find('.js-all-check'); privateData.lang_area = jQuery(privateData.summary_div).find('.js-lang-select-area'); setupDialog(); jQuery('#wpml-language-of-domains-link').on('click', showDialog); privateData.domain_select.on('change', showSummary); privateData.apply_button.prop('disabled', true).addClass('button-primary'); privateData.check_all.on('click', checkAllClick); privateData.lang_select.on('change', changeLanguage); jQuery(privateData.summary_div).find('.js-default').on('click', enableApplyButton); }); }; var setupDialog = function () { privateData.change_lang_dialog = jQuery('#wpml-change-domain-language-dialog'); privateData.change_lang_dialog.dialog({ autoOpen: false, resizable: false, modal: true, minWidth: 600, closeText: privateData.change_lang_dialog.data('cancel-text'), closeOnEscape: true, buttons: [ { id: 'wpml-change-domain-language-dialog-apply-button', text: privateData.change_lang_dialog.data('button-text'), click: applyChanges } ], close: function () { var languageSelector = jQuery('.js-simple-lang-selector-flags'); if (languageSelector) { languageSelector.select2("close"); } } }); privateData.apply_button = jQuery('#wpml-change-domain-language-dialog-apply-button'); privateData.spinner = privateData.change_lang_dialog.find('.spinner'); privateData.spinner.css( 'float', 'none' ).detach().insertBefore( privateData.apply_button ); enableApplyButton(); }; var showDialog = function () { privateData.change_lang_dialog.dialog('open'); }; var showSummary = function () { var domainLang; var languages; var domain = jQuery(this).val(); if (domain) { languages = jQuery(this).find('option:selected').data('langs'); buildTable(languages); domainLang = jQuery(this).find('option:selected').data('domain_lang'); jQuery(privateData.lang_select).select2('val', domainLang); privateData.summary_div.show(); } else { privateData.summary_div.hide(); } }; var buildTable = function (data) { var i; var tr; jQuery(privateData.summary_div).find('.js-lang').off('click'); privateData.table_body.empty(); for (i = 0; i < data.length; i++) { tr = ''; if (i % 2) { tr += '