first commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
jQuery(function () {
|
||||
jQuery('#icl_affiliate_info_check').submit(iclAffiliateInfoCheck);
|
||||
});
|
||||
|
||||
function iclAffiliateInfoCheck(){
|
||||
var thisf = jQuery(this);
|
||||
thisf.find('.icl_cyan_box').hide();
|
||||
thisf.find(':submit').before(icl_ajxloaderimg);
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
dataType: 'json',
|
||||
data: "icl_ajx_action=affiliate_info_check&" + thisf.serialize(),
|
||||
success: function(msg){
|
||||
thisf.find(':submit').prev().hide(function(){
|
||||
if(msg.error){
|
||||
thisf.find('.icl_error_text').fadeIn();
|
||||
}else{
|
||||
thisf.find('.icl_valid_text').fadeIn();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
jQuery('#wpml_save_cloned_sites_report_type').click(function () {
|
||||
var reportType = jQuery('input[name*="ate_locked_option"]:checked').val();
|
||||
|
||||
if ( reportType !== undefined ) {
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpml_save_cloned_sites_report_type',
|
||||
nonce: jQuery('#icl_doc_translation_method_cloned_nonce').val(),
|
||||
reportType: reportType
|
||||
},
|
||||
success: function () {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
jQuery(function () {
|
||||
var buttonId = '#wpml_tm_ate_source_id_migration_btn';
|
||||
|
||||
jQuery(buttonId).click(function () {
|
||||
jQuery(this).prop('disabled', true);
|
||||
jQuery(this).after('<span class="wpml-fix-tp-id-spinner">' + icl_ajxloaderimg + '</span>');
|
||||
|
||||
jQuery.ajax({
|
||||
url : ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: jQuery(this).data('action'),
|
||||
nonce: jQuery(this).data('nonce'),
|
||||
},
|
||||
success: function () {
|
||||
jQuery(buttonId).prop('disabled', false);
|
||||
jQuery('.wpml-fix-tp-id-spinner').remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
$constructor = '';
|
||||
$isJs = false;
|
||||
|
||||
$factory = new WPML_TM_AMS_ATE_Console_Section_Factory();
|
||||
$ateConsoleSection = $factory->create();
|
||||
|
||||
$response = wp_remote_request( $ateConsoleSection->getWidgetScriptUrl(), [ 'timeout' => 20 ] );
|
||||
|
||||
$errors = [];
|
||||
if ( is_wp_error( $response ) ) {
|
||||
$errors[] = 'WP_Error response';
|
||||
$errors[] = $response->get_error_message();
|
||||
} else {
|
||||
$headerData = wp_remote_retrieve_headers( $response )->getAll();
|
||||
if ( ! $headerData ) {
|
||||
$errors[] = 'Empty headers when retrieving the ATE Widget App';
|
||||
} else {
|
||||
$isJs = $headerData && strpos( $headerData['content-type'], 'javascript' );
|
||||
}
|
||||
|
||||
header( $_SERVER['SERVER_PROTOCOL'] . ' ' . $response['response']['code'] . ' ' . $response['response']['message'] );
|
||||
header( 'content-type: ' . $headerData['content-type'] );
|
||||
|
||||
$app = wp_remote_retrieve_body( $response );
|
||||
|
||||
$constructor = wp_json_encode( $ateConsoleSection->get_widget_constructor() );
|
||||
if ( ! $app || ! trim( $app ) ) {
|
||||
$errors[] = 'Empty response when retrieving the ATE Widget App';
|
||||
}
|
||||
}
|
||||
|
||||
if ( WP_DEBUG ) {
|
||||
if ( count( $errors ) > 0 ) {
|
||||
$errors[] = ':: URL:' . PHP_EOL . PHP_EOL . $ateConsoleSection->getWidgetScriptUrl();
|
||||
if ( is_wp_error( $response ) ) {
|
||||
$errors[] = ':: Error:' . PHP_EOL . PHP_EOL . var_export( $response, true );
|
||||
} else {
|
||||
$errors[] = ':: Response:' . PHP_EOL . PHP_EOL . var_export( $response['response'], true );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $errors ) {
|
||||
|
||||
if ( $isJs ) {
|
||||
echo '/** ' . PHP_EOL;
|
||||
}
|
||||
|
||||
echo join( PHP_EOL . PHP_EOL, $errors );
|
||||
|
||||
if ( $isJs ) {
|
||||
echo '*/' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( ! $errors ) {
|
||||
echo <<<WIDGET_CONSTRUCTOR
|
||||
$app
|
||||
LoadEateWidget($constructor);
|
||||
|
||||
WIDGET_CONSTRUCTOR;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global _, jQuery, ajaxurl, wpml_clear_ts_strings */
|
||||
|
||||
/** @namespace wpml_clear_ts_strings.placeHolder */
|
||||
/** @namespace wpml_clear_ts_strings.action */
|
||||
/** @namespace wpml_clear_ts_strings.nonce */
|
||||
|
||||
var ClearPreferredTS = function () {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
self.init = function () {
|
||||
var box = jQuery('#' + wpml_clear_ts_strings.placeHolder);
|
||||
var button = box.find('.button-primary');
|
||||
var spinner = box.find('.spinner');
|
||||
|
||||
button.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': wpml_clear_ts_strings.action,
|
||||
'nonce': wpml_clear_ts_strings.nonce
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
document.location.reload(true);
|
||||
} else {
|
||||
alert(response.data);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, status, error) {
|
||||
var parsedResponse = jqXHR.statusText || status || error;
|
||||
alert(parsedResponse);
|
||||
},
|
||||
complete: function () {
|
||||
spinner.removeClass('is-active');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
jQuery(function () {
|
||||
clearPreferredTS.init();
|
||||
});
|
||||
};
|
||||
|
||||
var clearPreferredTS = new ClearPreferredTS();
|
||||
@@ -0,0 +1,154 @@
|
||||
/*global WPML_core */
|
||||
|
||||
var icl_language_pairs_updated = false;
|
||||
|
||||
addLoadEvent(function () {
|
||||
var iclLangPairTrForm = jQuery('.icl_language_pairs .icl_tr_from');
|
||||
iclLangPairTrForm.change(toggleTranslationPairsSub);
|
||||
iclLangPairTrForm.change(iclShowNextButtonStep1);
|
||||
jQuery('.icl_tr_to').change(iclShowNextButtonStep1);
|
||||
var iclMoreOptions = jQuery('form[name="icl_more_options"]');
|
||||
iclMoreOptions.submit(iclSaveForm);
|
||||
iclMoreOptions.submit(iclSaveMoreOptions);
|
||||
jQuery('form[name="icl_editor_account"]').submit(iclSaveForm);
|
||||
jQuery('#icl_enable_content_translation,#icl_disable_content_translation').click(iclToggleContentTranslation);
|
||||
jQuery('a[href="#icl-ct-advanced-options"]').click(iclToggleAdvancedOptions);
|
||||
jQuery('a[href="#icl-show_disabled_langs"]').click(iclToggleMoreLanguages);
|
||||
jQuery('input[name="icl_content_trans_setup_cancel"]').click(iclWizardCancel);
|
||||
|
||||
jQuery('.handlediv').click(function () {
|
||||
if (jQuery(this).parent().hasClass('closed')) {
|
||||
jQuery(this).parent().removeClass('closed');
|
||||
} else {
|
||||
jQuery(this).parent().addClass('closed');
|
||||
}
|
||||
});
|
||||
|
||||
if (jQuery('input[name="icl_content_trans_setup_next_1"]').length > 0) {
|
||||
iclShowNextButtonStep1();
|
||||
}
|
||||
|
||||
jQuery('#icl_save_language_pairs').click(function () {
|
||||
icl_language_pairs_updated = true
|
||||
});
|
||||
jQuery('.icl_cost_estimate_toggle').click(function () {
|
||||
jQuery('#icl_cost_estimate').slideToggle()
|
||||
});
|
||||
jQuery('.icl_account_setup_toggle').click(icl_toggle_account_setup);
|
||||
|
||||
if (location.href.indexOf("show_config=1") != -1) {
|
||||
icl_toggle_account_setup();
|
||||
|
||||
var url = WPML_core.sanitize(location.href)
|
||||
.replace("&show_config=1", "")
|
||||
.replace("?show_config=1&", "&")
|
||||
.replace("?show_config=1", "");
|
||||
|
||||
location.href = url + '#icl_account_setup';
|
||||
}
|
||||
});
|
||||
|
||||
function icl_toggle_account_setup() {
|
||||
var iclAcctStats = jQuery('#icl_languages_translators_stats');
|
||||
if (iclAcctStats.is(':visible')) {
|
||||
iclAcctStats.slideUp();
|
||||
} else {
|
||||
if (icl_language_pairs_updated) {
|
||||
iclAcctStats.html('<div align="left" style="margin-bottom:5px;">' + icl_ajxloaderimg + "</div>").fadeIn();
|
||||
location.href = WPML_core.sanitize(location.href).replace(/#(.*)$/g, '');
|
||||
} else {
|
||||
iclAcctStats.slideDown();
|
||||
}
|
||||
}
|
||||
jQuery('#icl_account_setup').slideToggle();
|
||||
jQuery('.icl_account_setup_toggle_main').toggle();
|
||||
return false;
|
||||
}
|
||||
|
||||
function iclSaveMoreOptions() {
|
||||
jQuery('input[name="icl_translator_choice"]:checked').each(function () {
|
||||
jQuery('#icl_own_translators_message').css("display", ( this.value == '1' ? "" : "none" ));
|
||||
});
|
||||
}
|
||||
|
||||
function iclWizardCancel() {
|
||||
if (!confirm(jQuery('#icl_toggle_ct_confirm_message').html())) {
|
||||
return false;
|
||||
}
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=toggle_content_translation&new_val=0",
|
||||
success: function (msg) {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function iclShowNextButtonStep1() {
|
||||
// See if we have a language pair selected and enable the button if we have.
|
||||
var found = false;
|
||||
|
||||
jQuery('.icl_tr_from:checked').each(function () {
|
||||
var from = this.id.substring(13);
|
||||
jQuery('.icl_tr_to:checked').each(function () {
|
||||
if (this.id.substr(13, 2) == from) {
|
||||
found = true;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
jQuery('input[name="icl_content_trans_setup_next_1"]').prop("disabled", !found);
|
||||
}
|
||||
|
||||
function toggleTranslationPairsSub() {
|
||||
var code = jQuery(this).attr('name').split('_').pop();
|
||||
if (jQuery(this).prop('checked')) {
|
||||
jQuery('#icl_tr_pair_sub_' + code).slideDown();
|
||||
} else {
|
||||
jQuery('#icl_tr_pair_sub_' + code).css("display", "none");
|
||||
}
|
||||
}
|
||||
|
||||
function iclToggleContentTranslation() {
|
||||
var val = jQuery(this).attr('id') == 'icl_enable_content_translation' ? 1 : 0;
|
||||
if (!val && !confirm(jQuery('#icl_toggle_ct_confirm_message').html())) {
|
||||
return false;
|
||||
}
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=toggle_content_translation&new_val=" + val,
|
||||
success: function (msg) {
|
||||
location.href = WPML_core.sanitize(location.href).replace(/#.*/, '');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function iclToggleAdvancedOptions() {
|
||||
var self = jQuery(this);
|
||||
var iclContentAdv = jQuery('#icl-content-translation-advanced-options');
|
||||
if (iclContentAdv.css('display') === 'none') {
|
||||
iclContentAdv.fadeIn('fast', function () {
|
||||
self.children().toggle();
|
||||
});
|
||||
} else {
|
||||
iclContentAdv.fadeOut('fast', function () {
|
||||
self.children().toggle();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function iclToggleMoreLanguages() {
|
||||
var self = jQuery(this);
|
||||
var iclLangsDisabled = jQuery('#icl_languages_disabled');
|
||||
if (iclLangsDisabled.css('display') === 'none') {
|
||||
iclLangsDisabled.fadeIn('fast', function () {
|
||||
self.children().toggle();
|
||||
});
|
||||
} else {
|
||||
iclLangsDisabled.css('display', 'none');
|
||||
self.children().toggle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
jQuery(function () {
|
||||
|
||||
var cookie_setting = wpml_cookie_setting,
|
||||
ajax_success_action = function (response, response_text) {
|
||||
|
||||
if (response.success) {
|
||||
response_text.text(icl_ajx_saved);
|
||||
} else {
|
||||
response_text.text(icl_ajx_error);
|
||||
}
|
||||
|
||||
response_text.show();
|
||||
|
||||
setTimeout(function () {
|
||||
response_text.fadeOut('slow');
|
||||
}, 2500);
|
||||
},
|
||||
openTooltip = function(triggerNode) {
|
||||
|
||||
var content = triggerNode.data('content');
|
||||
|
||||
jQuery('.js-wpml-cookie-active-tooltip').pointer('close');
|
||||
|
||||
if(triggerNode.length && content) {
|
||||
triggerNode.addClass('js-wpml-cookie-active-tooltip');
|
||||
triggerNode.pointer({
|
||||
pointerClass : 'js-wpml-cookie-tooltip wpml-ls-tooltip',
|
||||
content: content,
|
||||
position: {
|
||||
edge: 'bottom',
|
||||
align: 'left'
|
||||
},
|
||||
show: function(event, t){
|
||||
t.pointer.css('marginLeft', '-54px');
|
||||
},
|
||||
close: function(event, t){
|
||||
t.pointer.css('marginLeft', '0');
|
||||
},
|
||||
buttons: function( event, t ) {
|
||||
var button = jQuery('<a class="close" href="#"> </a>');
|
||||
|
||||
return button.on( 'click.pointer', function(e) {
|
||||
e.preventDefault();
|
||||
t.element.pointer('close');
|
||||
});
|
||||
}
|
||||
|
||||
}).pointer('open');
|
||||
}
|
||||
};
|
||||
|
||||
jQuery( '#' + cookie_setting.button_id ).click(function(){
|
||||
|
||||
var store_frontend_cookie = jQuery( 'input[name*="' + cookie_setting.field_name + '"]:checked' ).val(),
|
||||
response_text = jQuery( '#' + cookie_setting.ajax_response_id ),
|
||||
spinner = jQuery( '#js-store-frontend-cookie-spinner' );
|
||||
|
||||
spinner.addClass( 'is-active' );
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: cookie_setting.ajax_action,
|
||||
nonce: jQuery( '#' + cookie_setting.nonce ).val(),
|
||||
store_frontend_cookie: store_frontend_cookie
|
||||
},
|
||||
success: function ( response ) {
|
||||
spinner.removeClass( 'is-active' );
|
||||
ajax_success_action( response, response_text );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
jQuery( '.js-wpml-cookie-tooltip-open' ).click( function( e ) {
|
||||
e.preventDefault();
|
||||
openTooltip( jQuery( this ) );
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
jQuery(function () {
|
||||
jQuery.each(wpml_cookies, function (cookieName, cookieData) {
|
||||
document.cookie = cookieName + '=' + cookieData.value + ';expires=' + cookieData.expires + '; path=' + cookieData.path
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
/*globals jQuery, ajaxurl, wpml_notice_information*/
|
||||
|
||||
function wpml_dismiss_taxonomy_translation_notice(element) {
|
||||
"use strict";
|
||||
var notice = jQuery(element);
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'otgs-dismiss-notice',
|
||||
id: wpml_notice_information.notice_id,
|
||||
group: wpml_notice_information.notice_group,
|
||||
nonce: notice.data('nonce')
|
||||
},
|
||||
success: function () {
|
||||
notice.parents('.otgs-notice').remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
jQuery(function () {
|
||||
var before_message = jQuery('.wpml-default-lang-before-message');
|
||||
var save = jQuery('#icl_save_default_button');
|
||||
var gotIt = jQuery('.wpml-default-lang-before-message input');
|
||||
|
||||
jQuery('#icl_change_default_button').click(function () {
|
||||
before_message.show();
|
||||
save.prop('disabled', true);
|
||||
});
|
||||
|
||||
jQuery('#icl_cancel_default_button').click(function () {
|
||||
before_message.hide();
|
||||
});
|
||||
|
||||
jQuery(gotIt).click(function(){
|
||||
save.prop('disabled', !gotIt.is(':checked'));
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
jQuery(function () {
|
||||
jQuery('#wpml_fix_tables_collation').click(function () {
|
||||
jQuery(this).prop('disabled', true);
|
||||
jQuery(this).after('<span class="wpml-fix-tables-collation-spinner">' + icl_ajxloaderimg + '</span>');
|
||||
jQuery.ajax({
|
||||
url : ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'fix_tables_collation',
|
||||
nonce : WPML_core.sanitize( jQuery('#wpml-fix-tables-collation-nonce').val() ),
|
||||
},
|
||||
success: function () {
|
||||
jQuery('#wpml_fix_tables_collation').prop('disabled',false);
|
||||
jQuery('.wpml-fix-tables-collation-spinner').remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
jQuery(function () {
|
||||
jQuery('#wpml_fix_tp_id_btn').click(function () {
|
||||
jQuery(this).prop('disabled', true);
|
||||
jQuery(this).after('<span class="wpml-fix-tp-id-spinner">' + icl_ajxloaderimg + '</span>');
|
||||
jQuery.ajax({
|
||||
url : ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
job_ids: jQuery('#wpml_fix_tp_id_text').val(),
|
||||
action : 'wpml-fix-translation-jobs-tp-id',
|
||||
nonce : jQuery('#wpml-fix-tp-id-nonce').val(),
|
||||
},
|
||||
success: function () {
|
||||
jQuery('#wpml_fix_tp_id_btn').prop('disabled', false);
|
||||
jQuery('.wpml-fix-tp-id-spinner').remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
/* <![CDATA[*/
|
||||
jQuery(function () {
|
||||
jQuery('.icl-admin-message-hide').on('click', function (event) {
|
||||
|
||||
if (typeof (event.preventDefault) !== 'undefined') {
|
||||
event.preventDefault();
|
||||
} else {
|
||||
event.returnValue = false;
|
||||
}
|
||||
|
||||
var messageBox = jQuery(this).closest('.otgs-is-dismissible');
|
||||
if (messageBox) {
|
||||
var messageID = messageBox.attr('id');
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'icl-hide-admin-message',
|
||||
'icl-admin-message-id': messageID
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
|
||||
if (ret) {
|
||||
messageBox.fadeOut('slow', function () {
|
||||
messageBox.removeAttr('class');
|
||||
if (ret.type) {
|
||||
messageBox.addClass(ret.type);
|
||||
}
|
||||
messageBox.html(ret.text);
|
||||
messageBox.fadeIn();
|
||||
});
|
||||
} else {
|
||||
messageBox.fadeOut();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
jQuery('a.icl-admin-message-link').on('click', function (event) {
|
||||
|
||||
if (typeof(event.preventDefault) !== 'undefined' ) {
|
||||
event.preventDefault();
|
||||
} else {
|
||||
event.returnValue = false;
|
||||
}
|
||||
|
||||
jQuery.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'icl-hide-admin-message',
|
||||
'icl-admin-message-id': jQuery(this).parent().parent().attr('id')
|
||||
},
|
||||
function (response) {
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
/*]]>*/
|
||||
@@ -0,0 +1,73 @@
|
||||
jQuery(function () {
|
||||
|
||||
display_side_bar_if_required();
|
||||
show_help_links();
|
||||
|
||||
jQuery('#icl_sidebar_hide').click(icl_hide_sidebar);
|
||||
jQuery('#icl_sidebar_show').click(icl_show_sidebar);
|
||||
|
||||
});
|
||||
|
||||
function show_help_links() {
|
||||
var command = "icl_ajx_action=icl_help_links&_icl_nonce=" + WPML_core.sanitize( jQuery('#_icl_nonce_hl').val() );
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: command,
|
||||
cache: false,
|
||||
success: function(msg){
|
||||
spl = msg.split('|');
|
||||
if(spl[0] == '1'){
|
||||
jQuery('#icl_help_links').html(spl[1]);
|
||||
display_side_bar_if_required();
|
||||
} else {
|
||||
jQuery('.icl_sidebar').fadeOut();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function display_side_bar_if_required() {
|
||||
|
||||
if(jQuery('#icl_sidebar_full').css('display')=='none') {
|
||||
jQuery('#icl_sidebar').css({'width': '16px'});
|
||||
} else {
|
||||
jQuery('#icl_sidebar').css({'width': '207px'});
|
||||
}
|
||||
|
||||
jQuery('#icl_sidebar').fadeIn();
|
||||
|
||||
}
|
||||
|
||||
function icl_show_sidebar() {
|
||||
|
||||
jQuery('#icl_sidebar_hide_div').fadeOut();
|
||||
jQuery('#icl_sidebar_full').fadeIn(display_side_bar_if_required);
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=icl_show_sidebar&state=show&_icl_nonce="+ WPML_core.sanitize( jQuery('#_icl_nonce_ss').val() ),
|
||||
async: true,
|
||||
success: function(msg){
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
function icl_hide_sidebar() {
|
||||
|
||||
jQuery('#icl_sidebar_full').fadeOut(display_side_bar_if_required);
|
||||
jQuery('#icl_sidebar_hide_div').fadeIn();
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=icl_show_sidebar&state=hide&_icl_nonce="+ WPML_core.sanitize( jQuery('#_icl_nonce_ss').val() ),
|
||||
async: true,
|
||||
success: function(msg){
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
9
wp-content/plugins/sitepress-multilingual-cms/res/js/iframeResizer.min.js
vendored
Normal file
9
wp-content/plugins/sitepress-multilingual-cms/res/js/iframeResizer.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,95 @@
|
||||
/*!
|
||||
* jQuery Cookie Plugin v1.3.1
|
||||
* https://github.com/carhartl/jquery-cookie
|
||||
*
|
||||
* Copyright 2013 Klaus Hartl
|
||||
* Released under the MIT license
|
||||
*/
|
||||
(function (factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as anonymous module.
|
||||
define(['jquery'], factory);
|
||||
} else {
|
||||
// Browser globals.
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
|
||||
var pluses = /\+/g;
|
||||
|
||||
function raw(s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
function decoded(s) {
|
||||
return decodeURIComponent(s.replace(pluses, ' '));
|
||||
}
|
||||
|
||||
function converted(s) {
|
||||
if (s.indexOf('"') === 0) {
|
||||
// This is a quoted cookie as according to RFC2068, unescape
|
||||
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
||||
}
|
||||
try {
|
||||
return config.json ? JSON.parse(s) : s;
|
||||
} catch(er) {}
|
||||
}
|
||||
|
||||
var config = $.cookie = function (key, value, options) {
|
||||
|
||||
// write
|
||||
if (value !== undefined) {
|
||||
options = $.extend({}, config.defaults, options);
|
||||
|
||||
if (typeof options.expires === 'number') {
|
||||
var days = options.expires, t = options.expires = new Date();
|
||||
t.setDate(t.getDate() + days);
|
||||
}
|
||||
|
||||
value = config.json ? JSON.stringify(value) : String(value);
|
||||
|
||||
return (document.cookie = [
|
||||
config.raw ? key : encodeURIComponent(key),
|
||||
'=',
|
||||
config.raw ? value : encodeURIComponent(value),
|
||||
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
|
||||
options.path ? '; path=' + options.path : '',
|
||||
options.domain ? '; domain=' + options.domain : '',
|
||||
options.secure ? '; secure' : ''
|
||||
].join(''));
|
||||
}
|
||||
|
||||
// read
|
||||
var decode = config.raw ? raw : decoded;
|
||||
var cookies = document.cookie.split('; ');
|
||||
var result = key ? undefined : {};
|
||||
for (var i = 0, l = cookies.length; i < l; i++) {
|
||||
var parts = cookies[i].split('=');
|
||||
var name = decode(parts.shift());
|
||||
var cookie = decode(parts.join('='));
|
||||
|
||||
if (key && key === name) {
|
||||
result = converted(cookie);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!key) {
|
||||
result[name] = converted(cookie);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
config.defaults = {};
|
||||
|
||||
$.removeCookie = function (key, options) {
|
||||
if ($.cookie(key) !== undefined) {
|
||||
// Must not alter options, thus extending a fresh object...
|
||||
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
}));
|
||||
@@ -0,0 +1,908 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global jQuery, wp, document, wpml_language_switcher_admin, _, iclSaveForm_success_cb, iclSaveForm */
|
||||
var WPML_core = WPML_core || {};
|
||||
|
||||
WPML_core.languageSwitcher = (function( $, wpml_ls ) {
|
||||
"use strict";
|
||||
|
||||
/** @namespace wpml_ls.strings */
|
||||
/** @namespace wpml_ls.strings.confirmation_item_remove */
|
||||
/** @namespace wpml_ls.color_schemes */
|
||||
/** @namespace wpml_ls.strings.table_no_item */
|
||||
/** @namespace wpml_ls.templates */
|
||||
|
||||
var form,
|
||||
dialogBox,
|
||||
formAndDialogBox,
|
||||
additionalCssStyleId = 'wpml-ls-inline-styles-additional-css',
|
||||
dialogInlineStyleId = 'wpml-ls-inline-styles-dialog',
|
||||
currentItemSlug,
|
||||
slotInlineStylesBackup;
|
||||
|
||||
var init = function () {
|
||||
form = $('#wpml-ls-settings-form');
|
||||
dialogBox = $('#wpml-ls-dialog');
|
||||
formAndDialogBox = form.add(dialogBox);
|
||||
|
||||
maybeInitAdditionalCssStyle();
|
||||
initDialogNode();
|
||||
initColorPicker();
|
||||
initLanguageSortable();
|
||||
attachEvents();
|
||||
openDialogFromHash();
|
||||
$(document).trigger('wpml_ls_admin_loaded');
|
||||
};
|
||||
|
||||
var attachEvents = function () {
|
||||
attachAutoSaveEvents();
|
||||
attachToggleEvents();
|
||||
attachSubOptionsEvents();
|
||||
attachTooltipEvents();
|
||||
attachDialogEvents();
|
||||
attachRowActionEvents();
|
||||
attachSelectedSlotChangeEvents();
|
||||
attachPresetColorsEvent();
|
||||
attachTemplateChangeEvents();
|
||||
attachMenuHierarchicalEvents();
|
||||
attachUpdatePreviewEvents();
|
||||
attachSaveClickEvents();
|
||||
fixSelectedOption();
|
||||
forceRefreshOnBrowserBackButton();
|
||||
setupWizardNextEvent();
|
||||
preventClickOnPreviewLinks();
|
||||
};
|
||||
|
||||
var maybeInitAdditionalCssStyle = function() {
|
||||
if ($('#' + additionalCssStyleId).length < 1) {
|
||||
var style = $('<style>');
|
||||
style.attr('id', additionalCssStyleId);
|
||||
style.appendTo($('head'));
|
||||
}
|
||||
};
|
||||
|
||||
var attachAutoSaveEvents = function () {
|
||||
formAndDialogBox.on('change', '.js-wpml-ls-trigger-save', function () {
|
||||
updateSettings($(this));
|
||||
});
|
||||
|
||||
formAndDialogBox.on('keyup', '.js-wpml-ls-trigger-need-save', function () {
|
||||
var triggerNode = $(this),
|
||||
messageWrapper = triggerNode.closest('.js-wpml-ls-option').find('.js-wpml-ls-messages');
|
||||
|
||||
showUpdatedContent(messageWrapper, wpml_ls.strings.leave_text_box_to_save, 0, 'notice');
|
||||
});
|
||||
};
|
||||
|
||||
var attachSubOptionsEvents = function () {
|
||||
formAndDialogBox
|
||||
.on('click', '.js-wpml-ls-toggle-suboptions', function () {
|
||||
const triggerNode = $(this);
|
||||
const targetNode = $(triggerNode.data('target'));
|
||||
|
||||
// Use this with non-boolean inputs (e.g. radio buttons group).
|
||||
const showOnValue = !!triggerNode.data('show-on-value') && "" + triggerNode.val() === "" + triggerNode.data('show-on-value');
|
||||
// Use this with a checkbox.
|
||||
const showOnChecked = !!triggerNode.data('show-on-checked') && triggerNode.prop('checked');
|
||||
|
||||
if (showOnValue || showOnChecked) {
|
||||
targetNode.slideDown();
|
||||
} else {
|
||||
targetNode.slideUp();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var attachToggleEvents = function () {
|
||||
formAndDialogBox
|
||||
.on('click', '.js-wpml-ls-toggle-slot', function () {
|
||||
var triggerNode = $(this);
|
||||
var targetNode = $(triggerNode.data('target'));
|
||||
|
||||
targetNode.slideToggle({
|
||||
complete: function () {
|
||||
if (targetNode.is(':visible')) {
|
||||
triggerNode.addClass('open');
|
||||
targetNode.find('.js-wpml-ls-row-edit').trigger('click');
|
||||
} else {
|
||||
triggerNode.removeClass('open');
|
||||
}
|
||||
repositionDialog();
|
||||
|
||||
}
|
||||
});
|
||||
})
|
||||
.on('click', '.js-wpml-ls-toggle-once', function () {
|
||||
var targetNode = $(this).nextAll('.js-wpml-ls-toggle-target');
|
||||
$(this).find('label').unwrap().find('.js-arrow-toggle').remove();
|
||||
targetNode.slideToggle();
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
var attachTooltipEvents = function () {
|
||||
formAndDialogBox.on('click.tooltip', '.js-wpml-ls-tooltip-open', function (e) {
|
||||
e.preventDefault();
|
||||
openTooltip($(this));
|
||||
});
|
||||
};
|
||||
|
||||
var initLanguageSortable = function () {
|
||||
$('#wpml-ls-languages-order').sortable({
|
||||
stop: function () {
|
||||
updateSettings($(this));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var initDialogNode = function () {
|
||||
dialogBox.dialog({
|
||||
dialogClass: 'dialog-fixed otgs-ui-dialog wpml-ls-dialog',
|
||||
width : '90%',
|
||||
modal: true,
|
||||
autoOpen: false,
|
||||
draggable: true,
|
||||
resizable: false
|
||||
})
|
||||
.on('dialogopen', function () {
|
||||
$('body').css('overflow', 'hidden');
|
||||
$('.js-wpml-ls-active-tooltip').pointer('close');
|
||||
repositionDialog();
|
||||
attachDialogScrollEvent();
|
||||
})
|
||||
.on('dialogclose', function () {
|
||||
$('body').css('overflow', '');
|
||||
$('.js-wpml-ls-active-tooltip').pointer('close');
|
||||
updateDialogInlineStyle();
|
||||
});
|
||||
|
||||
$(window).resize(resizeWindowEvent);
|
||||
};
|
||||
|
||||
var openDialogFromHash = function() {
|
||||
var item = getItemFromHash();
|
||||
|
||||
if (item) {
|
||||
var section = $('#wpml-language-switcher-' + item.type),
|
||||
row = getItemRow(item);
|
||||
|
||||
$('html, body').animate({
|
||||
scrollTop: section.offset().top
|
||||
}, 1, function() {
|
||||
var subform;
|
||||
|
||||
if (row) {
|
||||
subform = row.find('.js-wpml-ls-subform');
|
||||
} else {
|
||||
var targetNode = $('#wpml-ls-new-' + item.type + '-template');
|
||||
subform = prepareTemplateSubform(targetNode);
|
||||
currentItemSlug = item.slug;
|
||||
}
|
||||
|
||||
cloneSubformIntoDialog(subform);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var getItemFromHash = function() {
|
||||
var hashParts = WPML_core.sanitize(window.location.hash).substring(1).split('/'),
|
||||
item = null,
|
||||
type = hashParts[0] || '',
|
||||
slug = hashParts[1] || '';
|
||||
|
||||
if (0 <= $.inArray(type, ['menus', 'sidebars', 'statics'])) {
|
||||
item = {
|
||||
'type': type,
|
||||
'slug': slug
|
||||
};
|
||||
|
||||
parent.location.hash = '';
|
||||
}
|
||||
|
||||
return item;
|
||||
};
|
||||
|
||||
var getItemRow = function(item) {
|
||||
var itemTypeSelector = '[data-item-type=' + item.type + ']',
|
||||
itemSlugSelector = item.slug ? '[data-item-slug=' + item.slug + ']' : '',
|
||||
row = $('tr' + itemTypeSelector + itemSlugSelector);
|
||||
|
||||
return 1 === row.length ? row : null;
|
||||
};
|
||||
|
||||
var resizeWindowEvent = _.debounce(function() {
|
||||
repositionDialog();
|
||||
attachDialogScrollEvent();
|
||||
}, 200);
|
||||
|
||||
var repositionDialog = function () {
|
||||
var winH = $(window).height() - 180;
|
||||
dialogBox.dialog("option", "maxHeight", winH);
|
||||
|
||||
dialogBox.dialog("option", "position", {
|
||||
my: "center",
|
||||
at: "center",
|
||||
of: window
|
||||
});
|
||||
};
|
||||
|
||||
var attachDialogScrollEvent = function() {
|
||||
var preview = dialogBox.find('.js-wpml-ls-preview-wrapper'),
|
||||
has_two_columns = dialogBox.width() > 900,
|
||||
has_minimal_height = (preview.height() + 200) < dialogBox.height();
|
||||
|
||||
has_minimal_height = has_minimal_height || (has_two_columns && preview.height() < dialogBox.height());
|
||||
|
||||
if (has_minimal_height) {
|
||||
dialogBox.on('scroll.preview', function(){
|
||||
dialogBox.find('.js-wpml-ls-preview-wrapper').css({
|
||||
position: 'relative',
|
||||
top: dialogBox.scrollTop()
|
||||
});
|
||||
});
|
||||
} else {
|
||||
dialogBox
|
||||
.off('scroll.preview')
|
||||
.find('.js-wpml-ls-preview-wrapper').css({
|
||||
position: 'relative',
|
||||
top: 0
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var initColorPicker = function(node) {
|
||||
node = node || form;
|
||||
node.find('.js-wpml-ls-colorpicker').wpColorPicker({
|
||||
change: function(e){
|
||||
var subform = $(e.target).parents('.js-wpml-ls-subform');
|
||||
updatePreview(subform);
|
||||
},
|
||||
clear: function(e){
|
||||
var subform = $(e.target).parents('.js-wpml-ls-subform');
|
||||
updatePreview(subform);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var attachDialogEvents = function() {
|
||||
$('.js-wpml-ls-dialog-close').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
restoreInlineStyles();
|
||||
dialogBox.dialog('close');
|
||||
});
|
||||
|
||||
$('.js-wpml-ls-dialog-save').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
$(this).prop('disabled', true);
|
||||
var subform = dialogBox.find('.js-wpml-ls-subform');
|
||||
replaceDialogSubformIntoOrigin(subform);
|
||||
});
|
||||
|
||||
$('.js-wpml-ls-open-dialog').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var subform,
|
||||
targetNode = $($(e.target).data('target'));
|
||||
|
||||
if (targetNode.hasClass('js-wpml-ls-template')) {
|
||||
subform = prepareTemplateSubform(targetNode);
|
||||
} else {
|
||||
subform = targetNode.find('.js-wpml-ls-subform');
|
||||
}
|
||||
|
||||
cloneSubformIntoDialog(subform);
|
||||
});
|
||||
};
|
||||
|
||||
var attachRowActionEvents = function() {
|
||||
$('.js-wpml-ls-slot-list')
|
||||
.on('click', '.js-wpml-ls-row-edit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var targetNode = $($(e.target).parents('tr.js-wpml-ls-row')),
|
||||
subform = targetNode.find('.js-wpml-ls-subform');
|
||||
|
||||
cloneSubformIntoDialog(subform);
|
||||
})
|
||||
.on('click', '.js-wpml-ls-row-remove', function(e) {
|
||||
e.preventDefault();
|
||||
if (confirm(wpml_ls.strings.confirmation_item_remove)) {
|
||||
var rowNode = $(this).parents('tr.js-wpml-ls-row'),
|
||||
itemType = rowNode.data('item-type');
|
||||
|
||||
rowNode.find('.js-wpml-ls-subform input, .js-wpml-ls-subform select').remove();
|
||||
|
||||
updateSettings(rowNode, function(){
|
||||
rowNode.fadeOut(800, function(){
|
||||
rowNode.remove();
|
||||
updateSlotSectionStatus(itemType);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var attachSelectedSlotChangeEvents = function() {
|
||||
formAndDialogBox.on('change', '.js-wpml-ls-available-slots', function(){
|
||||
var newSlug = WPML_core.sanitize( $(this).val() ),
|
||||
subform = $(this).closest('.js-wpml-ls-subform'),
|
||||
itemType = subform.data('item-type');
|
||||
|
||||
$(this).removeClass('wpml-ls-required');
|
||||
|
||||
if (isSlotAllowed(newSlug, itemType)) {
|
||||
replaceSubformElementsAttributes(subform, newSlug);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var resetColorpickers = function(node) {
|
||||
node.find('.js-wpml-ls-colorpicker').each( function() {
|
||||
var nodeClone = $(this).clone(),
|
||||
parentNode = $(this).parents('.js-wpml-ls-colorpicker-wrapper');
|
||||
|
||||
parentNode.empty().html(nodeClone);
|
||||
});
|
||||
|
||||
initColorPicker(node);
|
||||
};
|
||||
|
||||
var preselectSlot = function(subform) {
|
||||
if (currentItemSlug) {
|
||||
var selector = '.js-wpml-ls-available-slots option[value="' + currentItemSlug + '"]';
|
||||
subform.find(selector).prop('selected', true);
|
||||
subform.find(selector).attr('selected', 'selected');
|
||||
currentItemSlug = null;
|
||||
}
|
||||
};
|
||||
|
||||
var attachPresetColorsEvent = function() {
|
||||
formAndDialogBox.on('change', '.js-wpml-ls-colorpicker-preset', function(){
|
||||
var slug = WPML_core.sanitize( $(this).val() ),
|
||||
subform = $(this).parents('.js-wpml-ls-subform');
|
||||
|
||||
if (slug) {
|
||||
var pickerSets = $(this).parents('.js-wpml-ls-panel-colors'),
|
||||
colors = wpml_ls.color_schemes[ slug ].values;
|
||||
|
||||
$.each(colors, function(k, v){
|
||||
var inputTags = pickerSets.find('.js-wpml-ls-color-' + k);
|
||||
inputTags.attr('value', v);
|
||||
inputTags.parents('.wp-picker-container').find('.wp-color-result').css('background-color', v);
|
||||
});
|
||||
|
||||
updatePreview(subform);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var fixSelectedOption = function() {
|
||||
// Prevent loosing selected after replacing in original id
|
||||
formAndDialogBox.on('change', 'select', function () {
|
||||
var selectedVal = WPML_core.sanitize( $(this).val() );
|
||||
$('option', this).prop('selected', false);
|
||||
$('option', this).attr('selected', false);
|
||||
$('option[value="' + selectedVal + '"]', this).prop('selected', true);
|
||||
$('option[value="' + selectedVal + '"]', this).attr('selected', 'selected');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @see http://stackoverflow.com/a/19196020
|
||||
*/
|
||||
var forceRefreshOnBrowserBackButton = function() {
|
||||
var input = $('#wpml-ls-refresh-on-browser-back-button');
|
||||
|
||||
if(input.val() === 'yes') {
|
||||
location.reload(true);
|
||||
} else {
|
||||
input.val('yes');
|
||||
}
|
||||
};
|
||||
|
||||
var setupWizardNextEvent = function() {
|
||||
form.submit(function(e){
|
||||
e.preventDefault();
|
||||
|
||||
form.find('input[name="submit_setup_wizard"]').val(1);
|
||||
|
||||
updateSettings(form, function(){
|
||||
location.href = WPML_core.sanitize(location.href).replace(/#.*/,'');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var preventClickOnPreviewLinks = function () {
|
||||
$('.js-wpml-ls-preview').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
};
|
||||
|
||||
var openTooltip = function(triggerNode) {
|
||||
var content = triggerNode.data('content');
|
||||
var link_text = triggerNode.data('link-text');
|
||||
var link_url = triggerNode.data('link-url');
|
||||
var link_target = triggerNode.data('link-target');
|
||||
|
||||
if (link_text.length > 0) {
|
||||
if (link_url.length === 0) {
|
||||
link_url = '#';
|
||||
}
|
||||
var content_link_target = 'target="' + link_target + '"';
|
||||
content += '<br><br><a href="' + link_url + '" ' + content_link_target + '>';
|
||||
content += link_text;
|
||||
content += '</a>';
|
||||
}
|
||||
|
||||
$('.js-wpml-ls-active-tooltip').pointer('close');
|
||||
|
||||
if(triggerNode.length && content) {
|
||||
triggerNode.addClass('js-wpml-ls-active-tooltip');
|
||||
triggerNode.pointer({
|
||||
pointerClass : 'js-wpml-ls-tooltip wpml-ls-tooltip',
|
||||
content: content,
|
||||
position: {
|
||||
edge: 'bottom',
|
||||
align: 'left'
|
||||
},
|
||||
show: function(event, t){
|
||||
t.pointer.css('marginLeft', '-54px');
|
||||
},
|
||||
close: function(event, t){
|
||||
t.pointer.css('marginLeft', '0');
|
||||
},
|
||||
buttons: function( event, t ) {
|
||||
var button = $('<a class="close" href="#"> </a>');
|
||||
|
||||
return button.on( 'click.pointer', function(e) {
|
||||
e.preventDefault();
|
||||
t.element.pointer('close');
|
||||
});
|
||||
},
|
||||
|
||||
}).pointer('open');
|
||||
}
|
||||
};
|
||||
|
||||
var cloneSubformIntoDialog = function(subform) {
|
||||
var subformClone = subform.clone(true);
|
||||
|
||||
dialogBox.find('.js-wpml-ls-dialog-inner').empty().append(subformClone);
|
||||
|
||||
if('' === subformClone.find('.js-wpml-ls-preview').html()) {
|
||||
updatePreview(subformClone);
|
||||
}
|
||||
|
||||
prepareSlotInlineStyles(subform);
|
||||
updateAvailableSlotsSelector(subformClone);
|
||||
resetColorpickers(subformClone);
|
||||
preselectSlot(subformClone);
|
||||
|
||||
dialogBox.dialog('option', 'title', subformClone.data('title'))
|
||||
.dialog('open');
|
||||
};
|
||||
|
||||
var prepareSlotInlineStyles = function(subform) {
|
||||
var type = subform.data('item-type');
|
||||
var slug = subform.data('item-slug');
|
||||
|
||||
slug = '%id%' === slug ? '__id__' : slug;
|
||||
var inlineStyles = $('#wpml-ls-inline-styles-' + type + '-' + slug);
|
||||
slotInlineStylesBackup = inlineStyles.detach();
|
||||
updateDialogInlineStyle(slotInlineStylesBackup.clone());
|
||||
};
|
||||
|
||||
var restoreInlineStyles = function() {
|
||||
if ( slotInlineStylesBackup instanceof jQuery && slotInlineStylesBackup.length > 0) {
|
||||
$('#' + additionalCssStyleId).before(slotInlineStylesBackup);
|
||||
}
|
||||
};
|
||||
|
||||
var replaceDialogSubformIntoOrigin = function(subform) {
|
||||
var subformClone = subform.clone(true),
|
||||
itemType = subform.data('item-type');
|
||||
|
||||
subformClone.find('.js-wpml-ls-preview-wrapper').css('top', 0);
|
||||
|
||||
if(0 <= $.inArray(itemType, ["menus", "sidebars"] )) {
|
||||
var selectedSlot = subform.find('.js-wpml-ls-available-slots').val();
|
||||
|
||||
if (isSlotAllowed(selectedSlot, itemType)) {
|
||||
if (typeof subformClone.data('origin-id') === 'undefined') {
|
||||
appendNewRowAndSubform(subformClone);
|
||||
} else {
|
||||
updateRowAndSubform(subformClone);
|
||||
}
|
||||
|
||||
updateSlotSectionStatus(itemType);
|
||||
} else {
|
||||
missingSlotWarning(subform);
|
||||
}
|
||||
} else if(subformClone.data('item-type') === 'statics'){
|
||||
updateStaticSlot(subformClone);
|
||||
}
|
||||
};
|
||||
|
||||
var updateSlotSectionStatus = function(itemType) {
|
||||
var section = $('#wpml-language-switcher-' + itemType),
|
||||
numItems = section.find('.js-wpml-ls-row').length,
|
||||
numAllowed = $.map(wpml_ls[ itemType ], function(n, i) { return i; }).length;
|
||||
|
||||
if (numItems === 0) {
|
||||
section.find('.js-wpml-ls-slot-list').fadeOut();
|
||||
} else {
|
||||
section.find('.js-wpml-ls-slot-list').fadeIn();
|
||||
}
|
||||
|
||||
if (numItems === numAllowed) {
|
||||
section.find('button.js-wpml-ls-open-dialog').attr('disabled', 'disabled')
|
||||
.siblings('.js-wpml-ls-tooltip-wrapper').removeClass('hidden');
|
||||
} else {
|
||||
section.find('button.js-wpml-ls-open-dialog').prop('disabled', false)
|
||||
.siblings('.js-wpml-ls-tooltip-wrapper').addClass('hidden');
|
||||
}
|
||||
};
|
||||
|
||||
var updateStaticSlot = function(subform) {
|
||||
var wrapper = $('#' + subform.data('origin-id')),
|
||||
slug = subform.data('item-slug');
|
||||
|
||||
wrapper.find('.js-wpml-ls-subform').replaceWith(subform);
|
||||
|
||||
copyDialogInlineStyleToSlot('statics', slug);
|
||||
|
||||
updateSettings(wrapper, function() {
|
||||
dialogBox.find('.js-wpml-ls-dialog-inner').empty();
|
||||
dialogBox.dialog('close');
|
||||
});
|
||||
};
|
||||
|
||||
var updateRowAndSubform = function(subform) {
|
||||
var row = $('#' + subform.data('origin-id')),
|
||||
itemType = subform.data('item-type'),
|
||||
slug = WPML_core.sanitize( subform.find('.js-wpml-ls-available-slots').val() );
|
||||
|
||||
row.find('.js-wpml-ls-subform').replaceWith(subform);
|
||||
|
||||
if(row.attr('id') !== 'wpml-ls-' + itemType +'-row-' + slug){
|
||||
updateRowOnItemSlotChange(row, itemType, slug);
|
||||
}
|
||||
|
||||
copyDialogInlineStyleToSlot(itemType, slug);
|
||||
|
||||
updateSettings(row, function() {
|
||||
dialogBox.find('.js-wpml-ls-dialog-inner').empty();
|
||||
dialogBox.dialog('close');
|
||||
});
|
||||
};
|
||||
|
||||
var appendNewRowAndSubform = function(subform) {
|
||||
var itemType = subform.data('item-type'),
|
||||
slug = WPML_core.sanitize( subform.find('.js-wpml-ls-available-' + itemType).val() );
|
||||
|
||||
replaceSubformElementsAttributes(subform, slug);
|
||||
|
||||
var tplString = $.trim($('#wpml-ls-new-' + itemType + '-row-template').html()),
|
||||
newRow = $($.parseHTML(tplString));
|
||||
|
||||
newRow.find('.js-wpml-ls-subform').replaceWith(subform);
|
||||
updateRowOnItemSlotChange(newRow, itemType, slug);
|
||||
newRow.hide().appendTo(form.find('#wpml-ls-slot-list-' + itemType + ' > tbody')).show(800);
|
||||
|
||||
copyDialogInlineStyleToSlot(itemType, slug);
|
||||
|
||||
updateSettings(newRow, function() {
|
||||
dialogBox.find('.js-wpml-ls-dialog-inner').empty();
|
||||
dialogBox.dialog('close');
|
||||
});
|
||||
};
|
||||
|
||||
var missingSlotWarning = function(subform) {
|
||||
subform.find('.js-wpml-ls-available-slots').addClass('wpml-ls-required');
|
||||
dialogBox.animate({scrollTop:0}, 300);
|
||||
$('.js-wpml-ls-dialog-save').prop('disabled', false);
|
||||
};
|
||||
|
||||
var updateRowOnItemSlotChange = function(row, itemType, slug) {
|
||||
var newRowId = 'wpml-ls-' + itemType +'-row-' + slug,
|
||||
newTitle = wpml_ls[ itemType ][ slug ].name;
|
||||
|
||||
row.attr('id', newRowId);
|
||||
row.data('item-type', itemType);
|
||||
row.find('.js-wpml-ls-subform').addBack().data('item-slug', slug);
|
||||
row.find('.js-wpml-ls-subform').data('origin-id', newRowId);
|
||||
row.find('.js-wpml-ls-row-title').html(newTitle);
|
||||
};
|
||||
|
||||
var replaceSubformElementsAttributes = function(subform, newSlug) {
|
||||
var attr = '',
|
||||
itemType = subform.data('item-type'),
|
||||
oldSlug = subform.data('item-slug');
|
||||
|
||||
subform.find('input, select').each(function(i, el){
|
||||
attr = $(el).attr('name');
|
||||
if( typeof attr === 'string') {
|
||||
$(el).attr('name', attr.replace(itemType + '[' + oldSlug +']', itemType + '[' + newSlug +']') );
|
||||
}
|
||||
|
||||
attr = $(el).attr('id');
|
||||
if( typeof attr === 'string') {
|
||||
$(el).attr('id', attr.replace(oldSlug, newSlug) );
|
||||
}
|
||||
});
|
||||
|
||||
subform.find('label').each(function(i, el){
|
||||
attr = $(el).attr('for');
|
||||
if( typeof attr === 'string') {
|
||||
$(el).attr('for', attr.replace(oldSlug, newSlug) );
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var prepareTemplateSubform = function(targetNode) {
|
||||
var tplString = $.trim(targetNode.html()),
|
||||
subform = $($.parseHTML(tplString));
|
||||
|
||||
updateAvailableSlotsSelector(subform);
|
||||
|
||||
return subform;
|
||||
};
|
||||
|
||||
var getUsedSlots = function( type ) {
|
||||
var slotSlugs = [];
|
||||
$('#wpml-ls-slot-list-' + type + ' .js-wpml-ls-row').each( function() {
|
||||
slotSlugs.push($(this).data('item-slug'));
|
||||
});
|
||||
|
||||
return slotSlugs;
|
||||
};
|
||||
|
||||
var isSlotAllowed = function(slot, itemType) {
|
||||
var allowedSlots = $.map(wpml_ls[ itemType ], function(el) {
|
||||
return itemType === 'menus' ? el.term_id.toString() : el.id;
|
||||
});
|
||||
|
||||
return 0 <= $.inArray(slot, allowedSlots);
|
||||
};
|
||||
|
||||
var updateAvailableSlotsSelector = function(subform) {
|
||||
var itemType = subform.data('item-type'),
|
||||
alreadyUsed = getUsedSlots(itemType),
|
||||
selectedOption = subform.data('item-slug'),
|
||||
selectorOptionsNode = subform.find('.js-wpml-ls-available-slots option');
|
||||
|
||||
selectorOptionsNode.each(function(){
|
||||
var optionNode = $(this),
|
||||
usedOption = $.inArray(optionNode.val(), alreadyUsed) >= 0,
|
||||
currentOption = optionNode.val();
|
||||
|
||||
optionNode.prop('disabled', usedOption && selectedOption !== currentOption);
|
||||
});
|
||||
};
|
||||
|
||||
var attachUpdatePreviewEvents = function() {
|
||||
formAndDialogBox
|
||||
.on('change', '[type!="text"].js-wpml-ls-trigger-update', function(){
|
||||
var subform = $(this).parents('.js-wpml-ls-subform');
|
||||
updatePreview(subform);
|
||||
})
|
||||
.on('keyup', '[type="text"].js-wpml-ls-trigger-update', function(){
|
||||
var subform = $(this).parents('.js-wpml-ls-subform');
|
||||
updatePreview(subform);
|
||||
})
|
||||
.on('keyup', '.js-wpml-ls-additional-css', function(){
|
||||
var styleId = 'wpml-ls-inline-styles-additional-css',
|
||||
newStyleNode = $('<style id="' + styleId + '" type="text/css">' + WPML_core.sanitize( $(this).val() ) + '</style>');
|
||||
|
||||
$('#' + styleId).replaceWith(newStyleNode);
|
||||
});
|
||||
};
|
||||
|
||||
var attachTemplateChangeEvents = function() {
|
||||
formAndDialogBox.on('change', '.js-wpml-ls-template-selector', function() {
|
||||
var selected = $(this).val(),
|
||||
subform = $(this).closest('.js-wpml-ls-subform'),
|
||||
force = wpml_ls.templates[ selected ].force_settings;
|
||||
|
||||
subform.find('.js-wpml-ls-to-include input').prop('disabled', false);
|
||||
|
||||
jQuery.each(force, function(k, v){
|
||||
if(v === 1) {
|
||||
subform.find('.js-wpml-ls-setting-' + k).prop('checked', true).prop('disabled', true);
|
||||
} else {
|
||||
subform.find('.js-wpml-ls-setting-' + k).prop('checked', false).prop('disabled', true);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var attachMenuHierarchicalEvents = function() {
|
||||
formAndDialogBox.on('change', '.js-wpml-ls-menu-is-hierarchical', function() {
|
||||
var isHierarchical = parseInt($(this).val()),
|
||||
subform = $(this).closest('.js-wpml-ls-subform'),
|
||||
includeCurrentLangInput = subform.find('.js-wpml-ls-setting-display_link_for_current_lang');
|
||||
|
||||
includeCurrentLangInput.prop('disabled', false);
|
||||
|
||||
if(isHierarchical === 1) {
|
||||
includeCurrentLangInput.prop('checked', true).prop('disabled', true);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var updatePreview = _.debounce( function(subform) {
|
||||
$('.js-wpml-ls-dialog-save').prop('disabled', true);
|
||||
var preview = subform.find('.js-wpml-ls-preview');
|
||||
|
||||
if(preview.length > 0) {
|
||||
showSpinner(preview);
|
||||
var previewData = getSerializedSettings(subform);
|
||||
|
||||
wp.ajax.send({
|
||||
data: {
|
||||
action: 'wpml-ls-update-preview',
|
||||
nonce: wpml_ls.nonce,
|
||||
slot_settings: previewData
|
||||
},
|
||||
success: function (data) {
|
||||
preview.empty();
|
||||
updateDialogInlineStyle(data.styles);
|
||||
buildCSSLinks(data.css);
|
||||
buildJSScripts(data.js);
|
||||
showUpdatedContent(preview, data.html);
|
||||
},
|
||||
error: function (data) {
|
||||
showUpdatedContent(preview, data, 0, 'error');
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 500);
|
||||
|
||||
var attachSaveClickEvents = function() {
|
||||
form.on('click', '.js-wpml-ls-save-settings', function(e){
|
||||
e.preventDefault();
|
||||
updateSettings($(this));
|
||||
});
|
||||
};
|
||||
|
||||
var updateSettings = _.debounce(function (wrapper, successCallback) {
|
||||
var messageWrapper = wrapper.closest('.js-wpml-ls-option').find('.js-wpml-ls-messages'),
|
||||
settings = getSerializedSettings(form);
|
||||
|
||||
if(messageWrapper.length === 0) {
|
||||
messageWrapper = wrapper.closest('.js-wpml-ls-section').find('.js-wpml-ls-messages');
|
||||
}
|
||||
|
||||
messageWrapper.empty();
|
||||
showSpinner(messageWrapper);
|
||||
|
||||
wp.ajax.send({
|
||||
data: {
|
||||
action: 'wpml-ls-save-settings',
|
||||
nonce: wpml_ls.nonce,
|
||||
settings: settings
|
||||
},
|
||||
success: function (data) {
|
||||
showUpdatedContent(messageWrapper, data, 2500, 'updated');
|
||||
|
||||
if(typeof successCallback === 'function') {
|
||||
successCallback();
|
||||
}
|
||||
},
|
||||
error: function (data) {
|
||||
showUpdatedContent(messageWrapper, data, 2500, 'error');
|
||||
}
|
||||
});
|
||||
}, 500);
|
||||
|
||||
var getSerializedSettings = function(form) {
|
||||
var disabled = form.find(':input:disabled').prop('disabled', false),
|
||||
settings = form.find('input, select, textarea').serialize();
|
||||
|
||||
disabled.attr('disabled','disabled');
|
||||
|
||||
return settings;
|
||||
};
|
||||
|
||||
var showSpinner = function(wrapper) {
|
||||
$('.js-wpml-ls-messages').removeClass('success error').hide().empty();
|
||||
wrapper.siblings('.spinner').addClass('is-active');
|
||||
};
|
||||
|
||||
var showUpdatedContent = function(wrapper, content, delay, type) {
|
||||
wrapper.siblings('.spinner').removeClass('is-active');
|
||||
|
||||
wrapper.removeClass('updated notice error');
|
||||
|
||||
if(type) {
|
||||
wrapper.addClass(type);
|
||||
}
|
||||
|
||||
wrapper.html(content).fadeIn();
|
||||
|
||||
if(delay) {
|
||||
wrapper.delay(delay).fadeOut();
|
||||
}
|
||||
|
||||
$('.js-wpml-ls-dialog-save').prop('disabled', false);
|
||||
};
|
||||
|
||||
var updateDialogInlineStyle = function (styles) {
|
||||
$('#' + dialogInlineStyleId).remove();
|
||||
|
||||
if(styles) {
|
||||
var newDialogStyle;
|
||||
|
||||
if (styles instanceof jQuery) {
|
||||
newDialogStyle = styles;
|
||||
} else {
|
||||
newDialogStyle = $($.parseHTML(styles)).first();
|
||||
}
|
||||
|
||||
newDialogStyle.attr('id', dialogInlineStyleId);
|
||||
$('#' + additionalCssStyleId).before(newDialogStyle);
|
||||
}
|
||||
};
|
||||
|
||||
var copyDialogInlineStyleToSlot = function (itemType, slug) {
|
||||
var dialogStyleClone = $('#' + dialogInlineStyleId).clone(),
|
||||
targetId = 'wpml-ls-inline-styles-' + itemType + '-' + slug,
|
||||
targetStyle = $('#' + targetId);
|
||||
|
||||
dialogStyleClone.attr('id', targetId);
|
||||
|
||||
if (targetStyle.length) {
|
||||
targetStyle.replaceWith(dialogStyleClone);
|
||||
} else {
|
||||
$('#' + additionalCssStyleId).before(dialogStyleClone);
|
||||
}
|
||||
};
|
||||
|
||||
var buildCSSLinks = function (css) {
|
||||
var i,
|
||||
linkTag;
|
||||
|
||||
if (typeof css !== typeof undefined && null !== css) {
|
||||
for (i = 0; i < css.length; i++) {
|
||||
linkTag = $('link[href="' + css[i] + '"]');
|
||||
|
||||
if (0 === linkTag.length) {
|
||||
linkTag = $('<link>');
|
||||
linkTag.attr('rel', 'stylesheet');
|
||||
linkTag.attr('type', 'text/css');
|
||||
linkTag.attr('media', 'all');
|
||||
linkTag.attr('href', css[i]);
|
||||
linkTag.prependTo('head');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var buildJSScripts = function (js) {
|
||||
var i,
|
||||
jsTag;
|
||||
|
||||
if (typeof js !== typeof undefined && null !== js) {
|
||||
for (i = 0; i < js.length; i++) {
|
||||
jsTag = $('script[src="' + js[i] + '"]');
|
||||
|
||||
if (0 === jsTag.length) {
|
||||
jsTag = $('<script></script>');
|
||||
jsTag.attr('type', 'text/javascript');
|
||||
jsTag.attr('src', js[i]);
|
||||
jsTag.prependTo('head');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
'init': init
|
||||
};
|
||||
|
||||
})( jQuery, wpml_language_switcher_admin );
|
||||
|
||||
jQuery(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_core.languageSwitcher.init();
|
||||
});
|
||||
2
wp-content/plugins/sitepress-multilingual-cms/res/js/language-switchers-settings.min.js
vendored
Normal file
2
wp-content/plugins/sitepress-multilingual-cms/res/js/language-switchers-settings.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,504 @@
|
||||
/*jslint browser: true, nomen: true, laxbreak: true*/
|
||||
/*global WPML_core, ajaxurl, iclSaveForm, iclSaveForm_success_cb, jQuery, alert, confirm, icl_ajx_url, icl_ajx_saved, icl_ajxloaderimg, icl_default_mark, icl_ajx_error, fadeInAjxResp */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
jQuery(function () {
|
||||
var icl_hide_languages;
|
||||
|
||||
jQuery('.toggle:checkbox').click(iclHandleToggle);
|
||||
jQuery('#icl_change_default_button').click(editingDefaultLanguage);
|
||||
jQuery('#icl_save_default_button').click(saveDefaultLanguage);
|
||||
jQuery('#icl_cancel_default_button').click(doneEditingDefaultLanguage);
|
||||
jQuery('#icl_add_remove_button').click(showLanguagePicker);
|
||||
jQuery('#icl_cancel_language_selection').click(hideLanguagePicker);
|
||||
jQuery('#icl_save_language_selection').click(saveLanguageSelection);
|
||||
jQuery('#icl_enabled_languages').find('input').prop('disabled', true);
|
||||
jQuery('#icl_save_language_negotiation_type').submit(iclSaveLanguageNegotiationType);
|
||||
jQuery('#icl_admin_language_options').submit(iclSaveForm);
|
||||
jQuery('#icl_lang_more_options').submit(iclSaveForm);
|
||||
jQuery('#icl_blog_posts').submit(iclSaveForm);
|
||||
icl_hide_languages = jQuery('#icl_hide_languages');
|
||||
icl_hide_languages.submit(iclHideLanguagesCallback);
|
||||
icl_hide_languages.submit(iclSaveForm);
|
||||
jQuery('#icl_adjust_ids').submit(iclSaveForm);
|
||||
jQuery('#icl_automatic_redirect').submit(iclSaveForm);
|
||||
jQuery('#icl_automatic_redirect input[name="icl_automatic_redirect"]').on('click', function () {
|
||||
var $redirect_warn = jQuery(this).parents('#icl_automatic_redirect').find('.js-redirect-warning');
|
||||
if (0 != jQuery(this).val()) {
|
||||
$redirect_warn.fadeIn();
|
||||
} else {
|
||||
$redirect_warn.fadeOut();
|
||||
}
|
||||
});
|
||||
jQuery('input[name="icl_language_negotiation_type"]').change(iclLntDomains);
|
||||
jQuery('#icl_use_directory').change(iclUseDirectoryToggle);
|
||||
|
||||
jQuery('input[name="show_on_root"]').change(iclToggleShowOnRoot);
|
||||
jQuery('#wpml_show_page_on_root_details').find('a').click(function () {
|
||||
if (!jQuery('#wpml_show_on_root_page').hasClass('active')) {
|
||||
alert(jQuery('#wpml_show_page_on_root_x').html());
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
jQuery('#icl_seo_options').submit(iclSaveForm);
|
||||
jQuery('#icl_seo_head_langs').on('click', update_seo_head_langs_priority);
|
||||
|
||||
|
||||
jQuery('#icl_avail_languages_picker').find('li input:checkbox').click(function () {
|
||||
const checkedBoxes = jQuery('#icl_avail_languages_picker').find('li input:checkbox:checked').length;
|
||||
jQuery('#icl_setup_next_1').prop('disabled', checkedBoxes <= 1);
|
||||
});
|
||||
|
||||
jQuery('#icl_promote_form').submit(iclSaveForm);
|
||||
|
||||
jQuery(':radio[name=icl_translation_option]').change(function () {
|
||||
jQuery('#icl_enable_content_translation').prop('disabled', false);
|
||||
});
|
||||
jQuery('#icl_enable_content_translation, .icl_noenable_content_translation').click(iclEnableContentTranslation);
|
||||
|
||||
jQuery(document).on('click', '#installer_registration_form :submit', function () {
|
||||
jQuery('#installer_registration_form').find('input[name=button_action]').val(jQuery(this).attr('name'));
|
||||
});
|
||||
|
||||
jQuery(document).on('click', '#installer_recommendations_form :submit', function () {
|
||||
jQuery('#installer_recommendations_form').find('input[name=button_action]').val(jQuery(this).attr('name'));
|
||||
});
|
||||
|
||||
jQuery(document).on('click', '#sso_information', function (e) {
|
||||
e.preventDefault();
|
||||
jQuery('#language_per_domain_sso_description').dialog({
|
||||
modal: true,
|
||||
width: 'auto',
|
||||
height: 'auto'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function iclHandleToggle() {
|
||||
/* jshint validthis: true */
|
||||
var self = this;
|
||||
var toggleElement = jQuery(self);
|
||||
var toggle_value_name = toggleElement.data('toggle_value_name');
|
||||
var toggle_value_checked = toggleElement.data('toggle_checked_value');
|
||||
var toggle_value_unchecked = toggleElement.data('toggle_unchecked_value');
|
||||
var toggle_value = jQuery('[name="' + toggle_value_name + '"]');
|
||||
if (toggle_value.length === 0) {
|
||||
toggle_value = jQuery('<input type="hidden" name="' + toggle_value_name + '">');
|
||||
toggle_value.insertAfter(self);
|
||||
}
|
||||
if (toggleElement.is(':checked')) {
|
||||
toggle_value.val(toggle_value_checked);
|
||||
} else {
|
||||
toggle_value.val(toggle_value_unchecked);
|
||||
}
|
||||
}
|
||||
|
||||
function editingDefaultLanguage() {
|
||||
jQuery('#icl_change_default_button').hide();
|
||||
jQuery('#icl_save_default_button').show();
|
||||
jQuery('#icl_cancel_default_button').show();
|
||||
var enabled_languages = jQuery('#icl_enabled_languages').find('input');
|
||||
enabled_languages.show();
|
||||
enabled_languages.prop('disabled', false);
|
||||
jQuery('#icl_add_remove_button').hide();
|
||||
|
||||
}
|
||||
|
||||
function doneEditingDefaultLanguage() {
|
||||
jQuery('#icl_change_default_button').show();
|
||||
jQuery('#icl_save_default_button').hide();
|
||||
jQuery('#icl_cancel_default_button').hide();
|
||||
var enabled_languages = jQuery('#icl_enabled_languages').find('input');
|
||||
enabled_languages.hide();
|
||||
enabled_languages.prop('disabled', true);
|
||||
jQuery('#icl_add_remove_button').show();
|
||||
}
|
||||
|
||||
function saveDefaultLanguage() {
|
||||
var enabled_languages, arr, def_lang;
|
||||
enabled_languages = jQuery('#icl_enabled_languages');
|
||||
arr = enabled_languages.find('input[type="radio"]');
|
||||
def_lang = '';
|
||||
jQuery.each(arr, function () {
|
||||
if (this.checked) {
|
||||
def_lang = this.value;
|
||||
}
|
||||
});
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'wpml_set_default_language',
|
||||
'nonce': jQuery('#set_default_language_nonce').val(),
|
||||
'language': def_lang
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
var enabled_languages_items, spl, selected_language, avail_languages_picker, selected_language_item;
|
||||
selected_language = enabled_languages.find('li input[value="' + def_lang + '"]');
|
||||
|
||||
fadeInAjxResp(icl_ajx_saved);
|
||||
avail_languages_picker = jQuery('#icl_avail_languages_picker');
|
||||
avail_languages_picker.find('input[value="' + response.data.previousLanguage + '"]').prop('disabled', false);
|
||||
avail_languages_picker.find('input[value="' + def_lang + '"]').prop('disabled', true);
|
||||
enabled_languages_items = jQuery('#icl_enabled_languages').find('li');
|
||||
enabled_languages_items.removeClass('selected');
|
||||
selected_language_item = selected_language.closest('li');
|
||||
selected_language_item.addClass('selected');
|
||||
selected_language_item.find('label').append(' (' + icl_default_mark + ')');
|
||||
enabled_languages_items.find('input').prop('checked', false);
|
||||
selected_language.prop('checked', true);
|
||||
enabled_languages.find('input[value="' + response.data.previousLanguage + '"]').parent().html(enabled_languages.find('input[value="' + response.data.previousLanguage + '"]').parent().html().replace('(' + icl_default_mark + ')', ''));
|
||||
doneEditingDefaultLanguage();
|
||||
fadeInAjxResp('#icl_ajx_response', icl_ajx_saved);
|
||||
location.href = WPML_core.sanitize(location.href).replace(/#[\w\W]*/, '') + '&setup=2';
|
||||
} else {
|
||||
fadeInAjxResp('#icl_ajx_response', icl_ajx_error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showLanguagePicker() {
|
||||
jQuery('#icl_avail_languages_picker').slideDown();
|
||||
jQuery('#icl_add_remove_button').hide();
|
||||
jQuery('#icl_change_default_button').hide();
|
||||
}
|
||||
|
||||
function hideLanguagePicker() {
|
||||
jQuery('#icl_avail_languages_picker').slideUp();
|
||||
jQuery('#icl_add_remove_button').fadeIn();
|
||||
jQuery('#icl_change_default_button').fadeIn();
|
||||
}
|
||||
|
||||
function saveLanguageSelection() {
|
||||
fadeInAjxResp('#icl_ajx_response', icl_ajxloaderimg);
|
||||
var arr = jQuery('#icl_avail_languages_picker').find('ul input[type="checkbox"]'), sel_lang = [];
|
||||
jQuery.each(arr, function () {
|
||||
if (this.checked) {
|
||||
sel_lang.push(this.value);
|
||||
}
|
||||
});
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'wpml_set_active_languages',
|
||||
'nonce': jQuery('#set_active_languages_nonce').val(),
|
||||
'languages': sel_lang
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
if (!response.data.noLanguages) {
|
||||
fadeInAjxResp('#icl_ajx_response', icl_ajx_saved);
|
||||
jQuery('#icl_enabled_languages').html(response.data.enabledLanguages);
|
||||
location.href = WPML_core.sanitize(location.href).replace(/#[\w\W]*/, '');
|
||||
} else {
|
||||
location.href = WPML_core.sanitize(location.href).replace(/(#|&)[\w\W]*/, '');
|
||||
}
|
||||
} else {
|
||||
fadeInAjxResp('#icl_ajx_response', icl_ajx_error, true);
|
||||
location.href = WPML_core.sanitize(location.href).replace(/(#|&)[\w\W]*/, '');
|
||||
}
|
||||
}
|
||||
});
|
||||
hideLanguagePicker();
|
||||
}
|
||||
|
||||
function iclLntDomains() {
|
||||
var language_negotiation_type, icl_lnt_domains_box, icl_lnt_domains_options, icl_lnt_xdomain_options;
|
||||
icl_lnt_domains_box = jQuery('#icl_lnt_domains_box');
|
||||
icl_lnt_domains_options = jQuery('#icl_lnt_domains');
|
||||
icl_lnt_xdomain_options = jQuery('#language_domain_xdomain_options');
|
||||
|
||||
if (icl_lnt_domains_options.prop('checked')) {
|
||||
icl_lnt_domains_box.html(icl_ajxloaderimg);
|
||||
icl_lnt_domains_box.show();
|
||||
language_negotiation_type = jQuery('#icl_save_language_negotiation_type').find('input[type="submit"]');
|
||||
language_negotiation_type.prop('disabled', true);
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: 'icl_ajx_action=language_domains' + '&_icl_nonce=' + jQuery('#_icl_nonce_ldom').val(),
|
||||
success: function (resp) {
|
||||
icl_lnt_domains_box.html(resp);
|
||||
language_negotiation_type.prop('disabled', false);
|
||||
icl_lnt_xdomain_options.show();
|
||||
}
|
||||
});
|
||||
} else if (icl_lnt_domains_box.length) {
|
||||
icl_lnt_domains_box.fadeOut('fast');
|
||||
icl_lnt_xdomain_options.fadeOut('fast');
|
||||
}
|
||||
/*jshint validthis: true */
|
||||
if (jQuery(this).val() !== "1") {
|
||||
jQuery('#icl_use_directory_wrap').hide();
|
||||
} else {
|
||||
jQuery('#icl_use_directory_wrap').fadeIn();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function iclToggleShowOnRoot() {
|
||||
/*jshint validthis: true */
|
||||
if (jQuery(this).val() === 'page') {
|
||||
jQuery('#wpml_show_page_on_root_details').fadeIn();
|
||||
jQuery('#icl_hide_language_switchers').fadeIn();
|
||||
} else {
|
||||
jQuery('#wpml_show_page_on_root_details').fadeOut();
|
||||
jQuery('#icl_hide_language_switchers').fadeOut();
|
||||
}
|
||||
}
|
||||
|
||||
function iclUseDirectoryToggle() {
|
||||
if (jQuery(this).prop('checked')) {
|
||||
jQuery('#icl_use_directory_details').fadeIn();
|
||||
} else {
|
||||
jQuery('#icl_use_directory_details').fadeOut();
|
||||
}
|
||||
}
|
||||
|
||||
function iclSaveLanguageNegotiationType() {
|
||||
var validSettings = true;
|
||||
var ajaxResponse;
|
||||
var usedUrls;
|
||||
var formErrors;
|
||||
var formName;
|
||||
|
||||
var languageNegotiationType;
|
||||
var rootHtmlFile;
|
||||
var showOnRoot;
|
||||
var useDirectories;
|
||||
var validatedDomains;
|
||||
var domainsToValidateCount;
|
||||
var domainsToValidate;
|
||||
var validDomains;
|
||||
|
||||
var form = jQuery('#icl_save_language_negotiation_type');
|
||||
|
||||
var useDirectoryWrapper = jQuery('#icl_use_directory_wrap');
|
||||
languageNegotiationType = parseInt(form.find('input[name=icl_language_negotiation_type]:checked').val());
|
||||
useDirectoryWrapper.find('.icl_error_text').hide();
|
||||
|
||||
formName = form.attr('name');
|
||||
formErrors = false;
|
||||
usedUrls = [jQuery('#icl_ln_home').html()];
|
||||
jQuery('form[name="' + formName + '"] .icl_form_errors').html('').hide();
|
||||
ajaxResponse = jQuery('form[name="' + formName + '"] .icl_ajx_response').attr('id');
|
||||
fadeInAjxResp('#' + ajaxResponse, icl_ajxloaderimg);
|
||||
|
||||
if (1 === languageNegotiationType) {
|
||||
useDirectories = form.find('[name=use_directory]').is(':checked');
|
||||
showOnRoot = form.find('[name=show_on_root]:checked').val();
|
||||
rootHtmlFile = form.find('[name=root_html_file_path]').val();
|
||||
|
||||
if (useDirectories) {
|
||||
if ('html' === showOnRoot && !rootHtmlFile) {
|
||||
validSettings = false;
|
||||
useDirectoryWrapper.find('.icl_error_text.icl_error_1').fadeIn();
|
||||
}
|
||||
}
|
||||
|
||||
if (true === validSettings) {
|
||||
saveLanguageForm();
|
||||
}
|
||||
}
|
||||
|
||||
if (3 === languageNegotiationType) {
|
||||
saveLanguageForm();
|
||||
}
|
||||
|
||||
if (2 === languageNegotiationType) {
|
||||
domainsToValidate = jQuery('.validate_language_domain');
|
||||
domainsToValidateCount = domainsToValidate.length;
|
||||
validatedDomains = 0;
|
||||
validDomains = 0;
|
||||
|
||||
if (0 < domainsToValidateCount) {
|
||||
domainsToValidate.filter(':visible').each(function (index, element) {
|
||||
var languageDomainURL;
|
||||
var domainValidationCheckbox = jQuery(element);
|
||||
var langDomainInput, lang, languageDomain;
|
||||
lang = domainValidationCheckbox.attr('value');
|
||||
languageDomain = jQuery('.spinner.spinner-' + lang);
|
||||
langDomainInput = jQuery('#language_domain_' + lang);
|
||||
var validation = new WpmlDomainValidation(langDomainInput, domainValidationCheckbox);
|
||||
validation.run();
|
||||
var subdirMatches = langDomainInput.parent().html().match(/<code>\/(.+)<\/code>/);
|
||||
languageDomainURL = langDomainInput.parent().html().match(/<code>(.+)<\/code>/)[1] + langDomainInput.val() + '/' + (subdirMatches !== null ? subdirMatches[1] : '');
|
||||
if (domainValidationCheckbox.prop('checked')) {
|
||||
languageDomain.addClass('is-active');
|
||||
if (-1 !== usedUrls.indexOf(languageDomainURL)) {
|
||||
languageDomain.empty();
|
||||
formErrors = true;
|
||||
} else {
|
||||
usedUrls.push(languageDomainURL);
|
||||
langDomainInput.css('color', '#000');
|
||||
jQuery.ajax({
|
||||
method: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
url: languageDomainURL,
|
||||
action: 'validate_language_domain',
|
||||
nonce: jQuery('#validate_language_domain_nonce').val()
|
||||
},
|
||||
success: function (resp) {
|
||||
var ajaxLanguagePlaceholder = jQuery('#ajx_ld_' + lang);
|
||||
ajaxLanguagePlaceholder.html(resp.data);
|
||||
ajaxLanguagePlaceholder.removeClass('icl_error_text');
|
||||
ajaxLanguagePlaceholder.removeClass('icl_valid_text');
|
||||
if (resp.success) {
|
||||
ajaxLanguagePlaceholder.addClass('icl_valid_text');
|
||||
validDomains++;
|
||||
} else {
|
||||
ajaxLanguagePlaceholder.addClass('icl_error_text');
|
||||
}
|
||||
validatedDomains++;
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
jQuery('#ajx_ld_' + lang).html('');
|
||||
if ('0' === jqXHR) {
|
||||
fadeInAjxResp('#' + textStatus, icl_ajx_error, true);
|
||||
}
|
||||
},
|
||||
complete: function () {
|
||||
languageDomain.removeClass('is-active');
|
||||
if (domainsToValidateCount === validDomains) {
|
||||
saveLanguageForm();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
saveLanguageForm();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function saveLanguageForm() {
|
||||
var domains;
|
||||
var xdomain = 0;
|
||||
var useDirectory = false;
|
||||
var hideSwitcher = false;
|
||||
var data;
|
||||
var form = jQuery('#icl_save_language_negotiation_type');
|
||||
var formName = jQuery(form).attr('name');
|
||||
var ajxResponse = jQuery(form).find('.icl_ajx_response').attr('id');
|
||||
var sso_enabled = jQuery('#sso_enabled').is(':checked');
|
||||
var sso_notice = jQuery('#sso_enabled_notice');
|
||||
|
||||
if (form.find('input[name=use_directory]').is(':checked')) {
|
||||
useDirectory = 1;
|
||||
}
|
||||
if (form.find('input[name=hide_language_switchers]').is(':checked')) {
|
||||
hideSwitcher = 1;
|
||||
}
|
||||
if (form.find('input[name=icl_xdomain_data]:checked').val()) {
|
||||
xdomain = parseInt(form.find('input[name=icl_xdomain_data]:checked').val());
|
||||
}
|
||||
domains = {};
|
||||
form.find('input[name^=language_domains]').each(function () {
|
||||
var item = jQuery(this);
|
||||
domains[item.data('language')] = item.val();
|
||||
});
|
||||
|
||||
data = {
|
||||
action: 'save_language_negotiation_type',
|
||||
nonce: jQuery('#save_language_negotiation_type_nonce').val(),
|
||||
icl_language_negotiation_type: form.find('input[name=icl_language_negotiation_type]:checked').val(),
|
||||
language_domains: domains,
|
||||
use_directory: useDirectory,
|
||||
show_on_root: form.find('input[name=show_on_root]:checked').val(),
|
||||
root_html_file_path: form.find('input[name=root_html_file_path]').val(),
|
||||
hide_language_switchers: hideSwitcher,
|
||||
xdomain: xdomain,
|
||||
sso_enabled: sso_enabled
|
||||
};
|
||||
|
||||
jQuery.ajax({
|
||||
|
||||
method: "POST",
|
||||
url: ajaxurl,
|
||||
data: data,
|
||||
success: function (response) {
|
||||
var formErrors, rootHtmlFile, rootPage, spl;
|
||||
if (response.success) {
|
||||
fadeInAjxResp('#' + ajxResponse, icl_ajx_saved);
|
||||
if (sso_enabled) {
|
||||
sso_notice.addClass('updated').fadeIn();
|
||||
} else {
|
||||
sso_notice.removeClass('updated').fadeOut();
|
||||
}
|
||||
|
||||
if (response.data) {
|
||||
var formMessage = jQuery('form[name="' + formName + '"]').find('.wpml-form-message');
|
||||
formMessage.addClass('updated');
|
||||
formMessage.html(response.data);
|
||||
formMessage.fadeIn();
|
||||
}
|
||||
|
||||
if (jQuery('input[name=show_on_root]').length) {
|
||||
rootHtmlFile = jQuery('#wpml_show_on_root_html_file');
|
||||
rootPage = jQuery('#wpml_show_on_root_page');
|
||||
if (rootHtmlFile.prop('checked')) {
|
||||
rootHtmlFile.addClass('active');
|
||||
rootPage.removeClass('active');
|
||||
}
|
||||
if (rootPage.prop('checked')) {
|
||||
rootPage.addClass('active');
|
||||
rootHtmlFile.removeClass('active');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
formErrors = jQuery('form[name="' + formName + '"] .icl_form_errors');
|
||||
if (0 === formErrors.length) {
|
||||
formErrors = jQuery('form[name="' + formName + '"] .wpml-form-errors');
|
||||
}
|
||||
var errors = response.data.join('<br>');
|
||||
formErrors.html(errors);
|
||||
formErrors.fadeIn();
|
||||
fadeInAjxResp('#' + ajxResponse, icl_ajx_error, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function iclHideLanguagesCallback() {
|
||||
iclSaveForm_success_cb.push(function (frm, res) {
|
||||
jQuery('#icl_hidden_languages_status').html(res[1]);
|
||||
});
|
||||
}
|
||||
|
||||
function iclEnableContentTranslation() {
|
||||
var val = jQuery(':radio[name=icl_translation_option]:checked').val();
|
||||
/* jshint validthis:true */
|
||||
jQuery(this).prop('disabled', true);
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=toggle_content_translation&wizard=1&new_val=" + val,
|
||||
success: function (msg) {
|
||||
var spl = msg.split('|');
|
||||
if (spl[1]) {
|
||||
location.href = WPML_core.sanitize( spl[1] );
|
||||
} else {
|
||||
location.href = WPML_core.sanitize(location.href).replace(/#[\w\W]*/, '');
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function update_seo_head_langs_priority(event) {
|
||||
var element = jQuery(this);
|
||||
jQuery('#wpml-seo-head-langs-priority').prop('disabled', !element.prop('checked'));
|
||||
}
|
||||
}());
|
||||
@@ -0,0 +1,37 @@
|
||||
jQuery(function () {
|
||||
jQuery("#icl_edit_languages_add_language_button").click(function () {
|
||||
jQuery(this).fadeOut('fast', function () {
|
||||
jQuery("#icl_edit_languages_table tr:last, .icl_edit_languages_show").show();
|
||||
});
|
||||
jQuery('#icl_edit_languages_ignore_add').val('false');
|
||||
});
|
||||
jQuery("#icl_edit_languages_cancel_button").click(function () {
|
||||
jQuery(this).fadeOut('fast', function () {
|
||||
jQuery("#icl_edit_languages_add_language_button").show();
|
||||
jQuery(".icl_edit_languages_show").hide();
|
||||
jQuery("#icl_edit_languages_table").find("tr:last input").each(function () {
|
||||
jQuery(this).val('');
|
||||
});
|
||||
jQuery('#icl_edit_languages_ignore_add').val('true');
|
||||
jQuery('#icl_edit_languages_form').find(':submit').prop('disabled',true);
|
||||
});
|
||||
});
|
||||
jQuery('.icl_edit_languages_use_upload').click(function(){
|
||||
jQuery(this).closest('ul').find('.wpml-edit-languages-flag-wpml-wrapper').hide();
|
||||
jQuery(this).closest('ul').find('.wpml-edit-languages-flag-upload-wrapper').show();
|
||||
});
|
||||
jQuery('.icl_edit_languages_use_field').click(function(){
|
||||
jQuery(this).closest('ul').find('.wpml-edit-languages-flag-upload-wrapper').hide();
|
||||
jQuery(this).closest('ul').find('.wpml-edit-languages-flag-wpml-wrapper').show();
|
||||
});
|
||||
|
||||
jQuery('select.icl_edit_languages_mapping').change( function(event) {
|
||||
jQuery(this).parent().find('option[value="0"]').remove();
|
||||
|
||||
if (this.value == -1) {
|
||||
jQuery(this).parent().find('.notice-info').show();
|
||||
} else {
|
||||
jQuery(this).parent().find('.notice-info').hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
/*jshint devel:true */
|
||||
/*global jQuery */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.translateLinkTargets = function () {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
var init = function () {
|
||||
jQuery(function () {
|
||||
self.button = jQuery('#wpml-scan-link-targets');
|
||||
self.postCount = self.button.data('post-count');
|
||||
self.stringCount = self.button.data('string-count');
|
||||
self.button.on('click', function () {
|
||||
self.button.prop('disabled', true);
|
||||
self.button.parent().find('.spinner').css('visibility', 'visible');
|
||||
self.numberFixed = 0;
|
||||
showCompletePercent(self.postCount, 'post');
|
||||
wpmlScanLinkTargets(0, 10, true);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var wpmlScanLinkTargets = function ( start, count, isPosts ) {
|
||||
var message = self.button.data( isPosts ? 'post-message' : 'string-message' );
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
method: 'POST',
|
||||
data: {
|
||||
'last_processed': start,
|
||||
'number_to_process': count,
|
||||
'nonce': jQuery('[name=wpml-translate-link-targets]').val(),
|
||||
'action': isPosts ? 'WPML_Ajax_Update_Link_Targets_In_Posts' : 'WPML_Ajax_Update_Link_Targets_In_Strings'
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
self.numberFixed += response.data.links_fixed;
|
||||
if ( response.data.number_left > 0 ) {
|
||||
|
||||
showCompletePercent( response.data.number_left, isPosts ? 'post' : 'string' );
|
||||
wpmlScanLinkTargets( response.data.last_processed + 1, 10, isPosts );
|
||||
} else {
|
||||
showCompletePercent( self.stringCount, 'string' );
|
||||
if ( isPosts && self.stringCount ) {
|
||||
wpmlScanLinkTargets( 0, 10, false );
|
||||
} else {
|
||||
self.button.prop('disabled', false);
|
||||
self.button.parent().find('.spinner').css('visibility', 'hidden');
|
||||
self.button.parent().find( '.results' ).html( self.button.data( 'complete-message').replace( '%s', self.numberFixed ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var showCompletePercent = function( numberLeft, type ) {
|
||||
var total = type == 'post' ? self.postCount : self.stringCount,
|
||||
done = total - numberLeft,
|
||||
message = self.button.data( type + '-message' );
|
||||
|
||||
message = message.replace( '%1$s', done );
|
||||
message = message.replace( '%2$s', total );
|
||||
|
||||
self.button.parent().find( '.results' ).html( message );
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
};
|
||||
|
||||
var translateLinkTargets = new WPML_TM.translateLinkTargets();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
jQuery(function () {
|
||||
|
||||
var ajax_success_action = function (response, response_text) {
|
||||
if (response.success) {
|
||||
response_text.text(icl_ajx_saved);
|
||||
} else {
|
||||
response_text.text(icl_ajx_error);
|
||||
response_text.show();
|
||||
}
|
||||
setTimeout(function () {
|
||||
response_text.fadeOut('slow');
|
||||
}, 2500);
|
||||
};
|
||||
|
||||
jQuery( '#js-translated_document-options-btn' ).click(function(){
|
||||
|
||||
var document_status = jQuery( 'input[name*="icl_translated_document_status"]:checked' ).val(),
|
||||
page_url = jQuery( 'input[name*="icl_translated_document_page_url"]:checked' ).val(),
|
||||
response_text = jQuery( '#icl_ajx_response_tdo' ),
|
||||
spinner = '<span id="js-document-options-spinner" style="float: inherit; margin: 0" class="spinner is-active"></span>';
|
||||
|
||||
response_text.html( spinner );
|
||||
response_text.show();
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpml_translated_document_options',
|
||||
nonce: jQuery( '#wpml-translated-document-options-nonce' ).val(),
|
||||
document_status: document_status,
|
||||
page_url: page_url
|
||||
},
|
||||
success: function ( response ) {
|
||||
ajax_success_action( response, response_text );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
jQuery( '#translation-pickup-mode' ).click(function(){
|
||||
var pickup_mode = jQuery( 'input[name*="icl_translation_pickup_method"]:checked' ).val(),
|
||||
response_text = jQuery( '#icl_ajx_response_tpm' ),
|
||||
spinner = '<span id="js-document-options-spinner" style="float: inherit; margin: 0" class="spinner is-active"></span>';
|
||||
|
||||
response_text.html( spinner );
|
||||
response_text.show();
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpml_save_translation_pickup_mode',
|
||||
nonce: jQuery( '#wpml_save_translation_pickup_mode' ).val(),
|
||||
pickup_mode: pickup_mode
|
||||
},
|
||||
success: function ( response ) {
|
||||
ajax_success_action( response, response_text );
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,313 @@
|
||||
/*global jQuery, ajaxurl, addLoadEvent */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
addLoadEvent(
|
||||
function () {
|
||||
var form = jQuery('#wpml_media_options_form');
|
||||
var form_action = form.find('#wpml_media_options_action');
|
||||
var existingContent = form.find('.wpml-media-existing-content');
|
||||
var setLanguageInfo = form.find('input[name=set_language_info]');
|
||||
var submitButton = form.find(':submit');
|
||||
var primaryButton = form.find('.button-primary');
|
||||
|
||||
existingContent.find(':checkbox').change(
|
||||
function () {
|
||||
var set_language_required_missing = !setLanguageInfo.prop('disabled') && !setLanguageInfo.prop('checked');
|
||||
var checked = existingContent.find(':checkbox:checked');
|
||||
|
||||
if (!checked.length || set_language_required_missing) {
|
||||
primaryButton.addClass('disabled');
|
||||
} else {
|
||||
primaryButton.removeClass('disabled');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
submitButton.click(
|
||||
function () {
|
||||
form_action.val(jQuery(this).attr('name'));
|
||||
}
|
||||
);
|
||||
|
||||
form.submit(
|
||||
function () {
|
||||
|
||||
if (!submitButton.attr('disabled')) {
|
||||
|
||||
switch (form_action.val()) {
|
||||
case 'start':
|
||||
wpml_media_options_form_working();
|
||||
wpml_media_options_form_scan_prepare();
|
||||
break;
|
||||
case 'set_defaults':
|
||||
wpml_media_set_content_prepare();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
form_action.val(0);
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
function wpml_update_status(message) {
|
||||
jQuery(form).find('.status').html(message);
|
||||
if (message.length > 0) {
|
||||
jQuery(form).find('.status').show();
|
||||
} else {
|
||||
jQuery(form).find('.status').fadeOut();
|
||||
}
|
||||
}
|
||||
|
||||
function wpml_media_options_form_working() {
|
||||
wpml_update_status('');
|
||||
submitButton.prop('disabled', true);
|
||||
jQuery(form).find('.progress').fadeIn();
|
||||
}
|
||||
|
||||
function wpml_media_options_form_finished(status) {
|
||||
submitButton.prop('disabled', false);
|
||||
jQuery(form).find('.progress').fadeOut();
|
||||
wpml_update_status(status);
|
||||
window.setTimeout(
|
||||
function () {
|
||||
wpml_update_status('');
|
||||
}, 1000
|
||||
);
|
||||
}
|
||||
|
||||
function wpml_media_options_form_scan_prepare() {
|
||||
|
||||
jQuery.ajax(
|
||||
{
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {action: 'wpml_media_scan_prepare'},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
wpml_update_status(ret.message);
|
||||
if (jQuery('#wpml_media_options_form').find('input[name=no_lang_attachments]').val() > 0) {
|
||||
// step 1
|
||||
wpml_media_set_initial_language();
|
||||
} else {
|
||||
// step 2
|
||||
wpml_media_translate_media();
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
jQuery('#icl-migrate-progress').find('.message').html(textStatus);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function wpml_media_set_initial_language() {
|
||||
|
||||
if (jQuery('#set_language_info', form).is(':checked')) {
|
||||
jQuery.ajax(
|
||||
{
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {action: 'wpml_media_set_initial_language'},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
wpml_update_status(ret.message);
|
||||
if (ret.left > 0) {
|
||||
wpml_media_set_initial_language();
|
||||
} else {
|
||||
// step 2
|
||||
wpml_media_translate_media();
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
wpml_update_status('Set initial language: please try again (' + textStatus + ')');
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
} else {
|
||||
wpml_media_translate_media();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function wpml_media_translate_media() {
|
||||
if (jQuery('#translate_media', form).is(':checked')) {
|
||||
jQuery.ajax(
|
||||
{
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {action: 'wpml_media_translate_media'},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
wpml_update_status(ret.message);
|
||||
if (ret.left > 0) {
|
||||
wpml_media_translate_media();
|
||||
} else {
|
||||
// step 2
|
||||
wpml_media_duplicate_media();
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
wpml_update_status('Translate media: please try again (' + textStatus + ')');
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
} else {
|
||||
wpml_media_duplicate_media();
|
||||
}
|
||||
}
|
||||
|
||||
function wpml_media_duplicate_media() {
|
||||
|
||||
if (jQuery('#duplicate_media', form).is(':checked')) {
|
||||
jQuery.ajax(
|
||||
{
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {action: 'wpml_media_duplicate_media'},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
wpml_update_status(ret.message);
|
||||
if (ret.left > 0) {
|
||||
wpml_media_duplicate_media();
|
||||
} else {
|
||||
// step 3
|
||||
wpml_media_duplicate_featured_images();
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
wpml_update_status('Duplicate media: please try again (' + textStatus + ')');
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
} else {
|
||||
wpml_media_duplicate_featured_images();
|
||||
}
|
||||
}
|
||||
|
||||
function wpml_media_duplicate_featured_images( left = null ) {
|
||||
if (jQuery('#duplicate_featured', form).is(':checked')) {
|
||||
const nonce = document.getElementById( 'wpml_media_settings_nonce' );
|
||||
jQuery.ajax(
|
||||
{
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpml_media_duplicate_featured_images',
|
||||
nonce: nonce ? nonce.value : '',
|
||||
featured_images_left: left
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
wpml_update_status(ret.message);
|
||||
if (ret.left > 0) {
|
||||
wpml_media_duplicate_featured_images( ret.left );
|
||||
} else {
|
||||
wpml_media_mark_processed();
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
wpml_update_status('Duplicate featured images: Please try again (' + textStatus + ')');
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
} else {
|
||||
wpml_media_mark_processed();
|
||||
}
|
||||
}
|
||||
|
||||
function wpml_media_mark_processed() {
|
||||
|
||||
jQuery.ajax(
|
||||
{
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {action: 'wpml_media_mark_processed'},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
wpml_media_options_form_finished(ret.message);
|
||||
jQuery('#wpml_media_all_done').fadeIn();
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
wpml_update_status('Mark processed: Please try again (' + textStatus + ')');
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function wpml_media_set_content_prepare() {
|
||||
wpml_update_status('');
|
||||
submitButton.attr('disabled', 'disabled');
|
||||
jQuery(form).find('.content_default_progress').fadeIn();
|
||||
|
||||
jQuery.ajax(
|
||||
{
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpml_media_set_content_prepare'
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
jQuery(form).find('.content_default_status').html(ret.message);
|
||||
wpml_media_set_content_defaults();
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
wpml_update_status('Set Content Prepare: Please try again (' + textStatus + ')');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function wpml_media_set_content_defaults() {
|
||||
wpml_update_status('');
|
||||
submitButton.attr('disabled', 'disabled');
|
||||
jQuery(form).find('.content_default_progress').fadeIn();
|
||||
jQuery.ajax(
|
||||
{
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpml_media_set_content_defaults',
|
||||
always_translate_media: jQuery('input[name=content_default_always_translate_media]', form).is(':checked'),
|
||||
duplicate_media: jQuery('input[name=content_default_duplicate_media]', form).is(':checked'),
|
||||
duplicate_featured: jQuery('input[name=content_default_duplicate_featured]', form).is(':checked'),
|
||||
translate_media_library_texts: jQuery('input[name=translate_media_library_texts]', form).is(':checked')
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
jQuery(form).find('.content_default_status').html(ret.message);
|
||||
wpml_media_set_content_defaults_finished();
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
wpml_update_status('Set Content Defaults: Please try again (' + textStatus + ')');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function wpml_media_set_content_defaults_finished(status) {
|
||||
submitButton.prop('disabled', false);
|
||||
jQuery(form).find('.content_default_progress').fadeOut();
|
||||
jQuery(form).find('.content_default_status').html(status);
|
||||
window.setTimeout(
|
||||
function () {
|
||||
jQuery(form).find('.content_default_status').fadeOut();
|
||||
}, 1000
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}());
|
||||
@@ -0,0 +1,185 @@
|
||||
var WPML_core = WPML_core || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
jQuery(function () {
|
||||
|
||||
jQuery("#icl_msync_cancel").click(function () {
|
||||
location.href = WPML_core.sanitize(location.href).replace(/#(.)$/, '');
|
||||
});
|
||||
|
||||
var icl_msync_confirm = jQuery('#icl_msync_confirm');
|
||||
var check_all = icl_msync_confirm.find('thead :checkbox');
|
||||
|
||||
//Remove already assigned events: that's what makes that this slow!
|
||||
check_all.off('click');
|
||||
check_all.off('change');
|
||||
|
||||
check_all.on('change', function () {
|
||||
var on = jQuery(this).prop('checked');
|
||||
var checkboxes = icl_msync_confirm.find('tbody :checkbox');
|
||||
|
||||
if (on) {
|
||||
checkboxes.each( function( i, el ) {
|
||||
jQuery( el ).prop( 'checked', 'checked' );
|
||||
});
|
||||
jQuery( '#icl_msync_submit' ).prop( 'disabled', false );
|
||||
} else {
|
||||
checkboxes.each( function( i, el ) {
|
||||
jQuery( el ).removeProp( 'checked' );
|
||||
});
|
||||
jQuery( '#icl_msync_submit' ).prop( 'disabled', true );
|
||||
}
|
||||
});
|
||||
|
||||
icl_msync_confirm.find('tbody :checkbox').on('change', function () {
|
||||
|
||||
if (jQuery(this).attr('readonly') == 'readonly') {
|
||||
jQuery(this).prop('checked', !jQuery(this).prop('checked'));
|
||||
}
|
||||
|
||||
var checked_items = icl_msync_confirm.find('tbody :checkbox:checked');
|
||||
var checked_count = checked_items.length;
|
||||
|
||||
jQuery('#icl_msync_submit').prop('disabled', !checked_count);
|
||||
|
||||
if (checked_count && checked_items.length == icl_msync_confirm.find('tbody :checkbox').length) {
|
||||
jQuery('#icl_msync_confirm').find('thead :checkbox').prop('checked', true);
|
||||
} else {
|
||||
jQuery('#icl_msync').find('thead :checkbox').prop('checked', false);
|
||||
}
|
||||
|
||||
WPML_core.icl_msync_validation();
|
||||
|
||||
});
|
||||
|
||||
jQuery('#icl_msync_submit').on('click', function () {
|
||||
jQuery(this).prop('disabled', true);
|
||||
|
||||
var total_menus = jQuery('input[name^=sync]:checked').length;
|
||||
|
||||
var spinner = jQuery('<span class="spinner"></span>');
|
||||
jQuery('#icl_msync_message').before(spinner);
|
||||
spinner.css({display: 'inline-block',
|
||||
float: 'none',
|
||||
'visibility': 'visible'
|
||||
});
|
||||
|
||||
WPML_core.sync_menus(total_menus);
|
||||
|
||||
});
|
||||
|
||||
var max_vars_warning = jQuery('#icl_msync_max_input_vars');
|
||||
if (max_vars_warning.length) {
|
||||
var menu_sync_check_box_count = jQuery('input[name^=sync]').length;
|
||||
var max_vars_extra = 10; // Allow for a few other items as well. eg. nonce, etc
|
||||
if (menu_sync_check_box_count + max_vars_extra > max_vars_warning.data('max_input_vars')) {
|
||||
var warning_text = max_vars_warning.html();
|
||||
warning_text = warning_text.replace('!NUM!', menu_sync_check_box_count + max_vars_extra);
|
||||
max_vars_warning.html(warning_text);
|
||||
max_vars_warning.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
WPML_core.icl_msync_validation = function () {
|
||||
|
||||
jQuery('#icl_msync_confirm').find('tbody :checkbox').each(function () {
|
||||
var mnthis = jQuery(this);
|
||||
|
||||
mnthis.prop('readonly', false);
|
||||
|
||||
if (jQuery(this).attr('name') == 'menu_translation[]') {
|
||||
var spl = jQuery(this).val().split('#');
|
||||
var menu_id = spl[0];
|
||||
|
||||
jQuery('#icl_msync_confirm').find('tbody :checkbox').each(function () {
|
||||
|
||||
if (jQuery(this).val().search('newfrom-' + menu_id + '-') == 0 && jQuery(this).prop('checked')) {
|
||||
mnthis.prop('checked', true);
|
||||
mnthis.prop('readonly', true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
WPML_core.sync_menus = function (total_menus) {
|
||||
|
||||
var message;
|
||||
var data = 'action=icl_msync_confirm';
|
||||
data += '&_icl_nonce_menu_sync=' + jQuery('#_icl_nonce_menu_sync').val();
|
||||
|
||||
var number_to_send = 50;
|
||||
|
||||
var menus = jQuery('input[name^=sync]:checked:not(:disabled)');
|
||||
var icl_msync_message = jQuery('#icl_msync_message');
|
||||
if (menus.length) {
|
||||
|
||||
for (var i = 0; i < Math.min(number_to_send, menus.length); i++) {
|
||||
|
||||
data += '&' + jQuery(menus[i]).serialize();
|
||||
|
||||
jQuery(menus[i]).prop('disabled', true);
|
||||
}
|
||||
|
||||
message = jQuery('#icl_msync_submit').data('message');
|
||||
message = message.replace('%1', total_menus - menus.length);
|
||||
message = message.replace('%2', total_menus);
|
||||
|
||||
icl_msync_message.text(message);
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: data,
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
WPML_core.sync_menus(total_menus);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
icl_msync_message.hide();
|
||||
message = jQuery('#icl_msync_submit').data('message-complete');
|
||||
icl_msync_message.text(message);
|
||||
jQuery('.spinner').remove();
|
||||
jQuery('#icl_msync_cancel').fadeOut();
|
||||
icl_msync_message.fadeIn('slow');
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'wpml_get_links_for_menu_strings_translation'
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.success && response.data.items) {
|
||||
var element = jQuery('<p></p>');
|
||||
element.text(menus_sync.text1);
|
||||
element.append('<br>' + menus_sync.text2 + ' ' );
|
||||
var items = 0;
|
||||
|
||||
for (var key in response.data.items) {
|
||||
if (response.data.items.hasOwnProperty(key)) {
|
||||
if(items>0) {
|
||||
element.append(', ');
|
||||
}
|
||||
var link = jQuery('<a></a>');
|
||||
link.attr('href', response.data.items[key]);
|
||||
link.text(key);
|
||||
link.appendTo(element);
|
||||
items++;
|
||||
}
|
||||
}
|
||||
element.append( '<br>' + menus_sync.text3);
|
||||
|
||||
element.appendTo(jQuery('#icl_msync_confirm_form'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,103 @@
|
||||
/*jslint browser: true, nomen: true, laxbreak: true*/
|
||||
/*global ajaxurl */
|
||||
|
||||
"use strict";
|
||||
|
||||
jQuery(function ($) {
|
||||
|
||||
var deleted = 0;
|
||||
var deleting = false;
|
||||
var initial_orphans_count = 0;
|
||||
|
||||
var orphansCount = $('#wpml_orphans_count');
|
||||
var orphansCheckCount = orphansCount.find('.check-orphans');
|
||||
var orphansCountResults = orphansCount.find('.orphans-check-results');
|
||||
var orphansCountProgress = orphansCount.find('.count-in-progress');
|
||||
var deletingProgress = orphansCount.find('.delete-in-progress');
|
||||
var deletedOrphans = orphansCount.find('.deleted');
|
||||
var cleanOrphans = orphansCount.find('.clean-orphans');
|
||||
var noOrphans = orphansCount.find('.no_orphans');
|
||||
var orphansCheckLoader = orphansCount.find('.check_loader');
|
||||
|
||||
deletedOrphans.hide();
|
||||
noOrphans.hide();
|
||||
orphansCountProgress.hide();
|
||||
orphansCountResults.hide();
|
||||
orphansCheckLoader.hide();
|
||||
|
||||
orphansCount.show();
|
||||
|
||||
orphansCheckCount.on('click', count_orphans);
|
||||
cleanOrphans.on('click', delete_orphans);
|
||||
|
||||
var nonce = orphansCount.find('#wpml_orphan_comment_nonce').val();
|
||||
|
||||
function resetDeletion() {
|
||||
deletingProgress.fadeOut();
|
||||
deleted = 0;
|
||||
deleting = 0;
|
||||
}
|
||||
|
||||
function count_orphans() {
|
||||
if(!deleting) {
|
||||
orphansCheckCount.fadeOut();
|
||||
orphansCountProgress.fadeIn();
|
||||
}
|
||||
var data = {
|
||||
action : 'wpml_count_orphans',
|
||||
_icl_nonce: nonce
|
||||
};
|
||||
|
||||
$.post(
|
||||
ajaxurl, data, function (res) {
|
||||
orphansCountProgress.fadeOut();
|
||||
var orphansCountResult = parseInt(res.success ? res.data : 0);
|
||||
orphansCheckLoader.fadeOut();
|
||||
orphansCountResults.find('.count').html(orphansCountResult);
|
||||
if (orphansCountResult > 0) {
|
||||
if (initial_orphans_count == 0) {
|
||||
initial_orphans_count = orphansCountResult;
|
||||
cleanOrphans.fadeIn();
|
||||
}
|
||||
noOrphans.fadeOut();
|
||||
orphansCountResults.fadeIn();
|
||||
|
||||
if (deleting) {
|
||||
delete_orphans();
|
||||
} else {
|
||||
resetDeletion();
|
||||
}
|
||||
} else {
|
||||
resetDeletion();
|
||||
noOrphans.fadeIn();
|
||||
orphansCountResults.fadeOut();
|
||||
orphansCheckCount.fadeIn();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function delete_orphans() {
|
||||
|
||||
cleanOrphans.fadeOut();
|
||||
deletingProgress.fadeIn();
|
||||
deleting = true;
|
||||
|
||||
deletedOrphans.fadeIn();
|
||||
|
||||
var data = {
|
||||
'action' : 'wpml_delete_orphans',
|
||||
'data' : {how_many: Math.max(10, initial_orphans_count / 10)},
|
||||
_icl_nonce: nonce
|
||||
};
|
||||
$.post(
|
||||
ajaxurl, data, function (res) {
|
||||
var deletedComments = res.success ? res.data : 0;
|
||||
deleted += parseInt(deletedComments);
|
||||
deletedOrphans.html(deleted);
|
||||
count_orphans();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,127 @@
|
||||
/*globals jQuery, ajaxurl */
|
||||
|
||||
(function (jQuery, ajaxurl) {
|
||||
function bindEvents() {
|
||||
'use strict';
|
||||
|
||||
var otgsNotice = jQuery('.otgs-notice');
|
||||
var otgsCollapseText = '.otgs-notice-collapse-text';
|
||||
var otgsCollapsedText = '.otgs-notice-collapsed-text';
|
||||
|
||||
jQuery(otgsCollapsedText).hide();
|
||||
|
||||
var preventDefaultEvent = function (event) {
|
||||
if (typeof (event.preventDefault) !== 'undefined') {
|
||||
event.preventDefault();
|
||||
} else {
|
||||
event.returnValue = false;
|
||||
}
|
||||
};
|
||||
|
||||
var noticeAction = function (noticeBox, action) {
|
||||
if (noticeBox) {
|
||||
var ajaxAction = 'otgs-' + action + '-notice';
|
||||
var noticeId = _.escape(noticeBox.data('id'));
|
||||
var noticeGroup = noticeBox.data('group');
|
||||
var nonce = noticeBox.data('nonce');
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: ajaxAction,
|
||||
'id': noticeId,
|
||||
'group': noticeGroup,
|
||||
nonce: nonce
|
||||
},
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
if (action === 'dismiss') {
|
||||
noticeBox.remove();
|
||||
}
|
||||
|
||||
document.dispatchEvent(new CustomEvent('otgs-notice-' + action, {'detail': noticeBox}));
|
||||
}
|
||||
};
|
||||
|
||||
var toggleNotice = function (contentToMinimize, contentToMaximize) {
|
||||
contentToMinimize.toggle();
|
||||
contentToMaximize.toggle();
|
||||
};
|
||||
|
||||
otgsNotice.on('click', '.notice-dismiss, a.otgs-dismiss-link', function (event) {
|
||||
preventDefaultEvent(event);
|
||||
|
||||
var noticeBox = jQuery(this).closest('.is-dismissible');
|
||||
noticeAction(noticeBox, 'dismiss');
|
||||
});
|
||||
|
||||
otgsNotice.on('click', '.notice-hide, a.otgs-hide-link', function (event) {
|
||||
preventDefaultEvent(event);
|
||||
|
||||
var noticeBox = jQuery(this).closest('.is-dismissible');
|
||||
noticeAction(noticeBox, 'hide');
|
||||
});
|
||||
|
||||
otgsNotice.on('click', '.otgs-notice-collapse-hide', function (event) {
|
||||
preventDefaultEvent(event);
|
||||
|
||||
jQuery(this).toggle();
|
||||
var noticeCollapseText = jQuery(this).siblings(otgsCollapseText);
|
||||
var noticeCollapsedText = jQuery(this).siblings(otgsCollapsedText);
|
||||
toggleNotice(noticeCollapseText, noticeCollapsedText);
|
||||
});
|
||||
|
||||
otgsNotice.on('click', '.otgs-notice-collapse-show', function (event) {
|
||||
preventDefaultEvent(event);
|
||||
|
||||
jQuery(this).closest(otgsCollapsedText).siblings('.otgs-notice-collapse-hide').toggle();
|
||||
var noticeCollapseCollapseText = jQuery(this).closest(otgsCollapsedText).siblings(otgsCollapseText);
|
||||
var noticeCollapseCollapsedText = jQuery(this).closest(otgsCollapsedText);
|
||||
toggleNotice(noticeCollapseCollapseText, noticeCollapseCollapsedText);
|
||||
});
|
||||
|
||||
otgsNotice.on('click', '.notice-action.notice-action-link', function (event) {
|
||||
var groupToDismiss = jQuery(this).data('dismiss-group');
|
||||
var nonce = jQuery(this).data('nonce');
|
||||
var jsCallback = jQuery(this).data('js-callback');
|
||||
|
||||
if (groupToDismiss) {
|
||||
|
||||
if (jsCallback && typeof window[jsCallback] === 'function') {
|
||||
window[jsCallback](jQuery(this), function () {
|
||||
dismissGroup(groupToDismiss, nonce);
|
||||
});
|
||||
} else {
|
||||
dismissGroup(groupToDismiss, nonce);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var dismissGroup = function (groupToDismiss, nonce) {
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'otgs-dismiss-group',
|
||||
group : groupToDismiss,
|
||||
nonce : nonce
|
||||
},
|
||||
dataType: 'json',
|
||||
complete: function () {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
jQuery(function () {
|
||||
bindEvents();
|
||||
|
||||
});
|
||||
|
||||
jQuery(document).on('otgs-notices-added', function (event) {
|
||||
bindEvents();
|
||||
});
|
||||
})(jQuery, ajaxurl);
|
||||
@@ -0,0 +1,9 @@
|
||||
jQuery(function () {
|
||||
jQuery('.handlediv').click(function () {
|
||||
if (jQuery(this).parent().hasClass('closed')) {
|
||||
jQuery(this).parent().removeClass('closed');
|
||||
} else {
|
||||
jQuery(this).parent().addClass('closed');
|
||||
}
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
/* global jQuery, window */
|
||||
|
||||
(function($) {
|
||||
|
||||
$(function () {
|
||||
|
||||
var alert = $('.js-wpml-tm-post-edit-alert');
|
||||
|
||||
if (0 === alert.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
alert.dialog({
|
||||
dialogClass : 'otgs-ui-dialog',
|
||||
closeOnEscape: false,
|
||||
draggable: false,
|
||||
modal: true,
|
||||
minWidth: 520,
|
||||
open: function(e) {
|
||||
$(e.target).closest('.otgs-ui-dialog').find('.ui-widget-header').remove();
|
||||
}
|
||||
});
|
||||
|
||||
alert.on('click', '.js-wpml-tm-go-back', function(e) {
|
||||
e.preventDefault();
|
||||
dismiss_translation_editor_notice();
|
||||
window.history.go(-1);
|
||||
}).on('click', '.js-wpml-tm-continue', function(e) {
|
||||
e.preventDefault();
|
||||
dismiss_translation_editor_notice();
|
||||
alert.dialog('close');
|
||||
}).on( 'click', '.js-wpml-tm-open-in-te', function() {
|
||||
dismiss_translation_editor_notice();
|
||||
} );
|
||||
|
||||
function dismiss_translation_editor_notice() {
|
||||
|
||||
var show_again_checkbox = $( '.do-not-show-again' );
|
||||
|
||||
if ( show_again_checkbox.prop('checked') ) {
|
||||
|
||||
var action = show_again_checkbox.attr( 'data-action' );
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: action,
|
||||
nonce: $( '#'+action ).val()
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,91 @@
|
||||
/*globals jQuery, post_edit_languages_data, icl_ajx_url */
|
||||
|
||||
function build_language_links(data, $, container) {
|
||||
"use strict";
|
||||
|
||||
const getNewQueryString = function(sourceUrl, newQueryArgs) {
|
||||
const url = new URL(sourceUrl),
|
||||
search = url.searchParams;
|
||||
|
||||
for (let key in newQueryArgs) {
|
||||
if (Object.prototype.hasOwnProperty.call(newQueryArgs, key)) {
|
||||
search.set(key, newQueryArgs[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return search.toString();
|
||||
};
|
||||
|
||||
var urlData;
|
||||
if (data.hasOwnProperty('language_links')) {
|
||||
var languages_container = $('<ul></ul>');
|
||||
languages_container.prependTo(container);
|
||||
|
||||
/** @namespace data.language_links */
|
||||
/** @namespace data.statuses */
|
||||
for (var i = 0; i < data.language_links.length; i++) {
|
||||
var item = data.language_links[i];
|
||||
var is_current = item.current || false;
|
||||
var language_code = item.code;
|
||||
var language_count = item.count;
|
||||
var language_name = item.name;
|
||||
var statuses = item.statuses;
|
||||
var type = item.type;
|
||||
|
||||
var language_item = $('<li></li>');
|
||||
language_item.addClass('language_' + language_code);
|
||||
if (i > 0) {
|
||||
language_item.append(' | ');
|
||||
}
|
||||
|
||||
var language_summary = $('<span></span>');
|
||||
language_summary.addClass('count');
|
||||
language_summary.addClass(language_code);
|
||||
language_summary.text(' (' + ( language_count < 0 ? "0" : language_count ) + ')');
|
||||
|
||||
var current;
|
||||
if (is_current) {
|
||||
current = $('<strong></strong>');
|
||||
} else if (language_count >= 0) {
|
||||
current = $('<a></a>');
|
||||
urlData = {
|
||||
post_type: type,
|
||||
lang: language_code
|
||||
};
|
||||
|
||||
if (statuses && statuses.length) {
|
||||
urlData.post_status = statuses.join(',');
|
||||
}
|
||||
|
||||
current.attr('href', '?' + getNewQueryString(location.href, urlData));
|
||||
} else {
|
||||
current = $('<span></span>');
|
||||
}
|
||||
|
||||
current.append(language_name);
|
||||
current.appendTo(language_item);
|
||||
current.append(language_summary);
|
||||
|
||||
language_item.appendTo(languages_container);
|
||||
}
|
||||
|
||||
$(document).trigger('wpml_language_links_added', [languages_container]);
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(function ($) {
|
||||
"use strict";
|
||||
|
||||
var data = post_edit_languages_data;
|
||||
var subsubsub = $('.subsubsub');
|
||||
var container = subsubsub.next('.icl_subsubsub');
|
||||
|
||||
if (container.length === 0) {
|
||||
container = $('<div></div>');
|
||||
container.addClass('icl_subsubsub');
|
||||
|
||||
subsubsub.after(container);
|
||||
}
|
||||
|
||||
build_language_links(data, $, container);
|
||||
});
|
||||
@@ -0,0 +1,142 @@
|
||||
/*globals jQuery, WPML_core, ajaxurl, icl_post_edit_messages */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/** @namespace icl_post_edit_messages.switch_language_title */
|
||||
/** @namespace icl_post_edit_messages.switch_language_alert */
|
||||
/** @namespace icl_post_edit_messages.connection_loss_alert */
|
||||
/** @namespace icl_post_edit_messages.switch_language_message */
|
||||
/** @namespace icl_post_edit_messages.switch_language_confirm */
|
||||
/** @namespace icl_post_edit_messages._nonce */
|
||||
|
||||
jQuery(function () {
|
||||
var language_selector;
|
||||
/* Check if we have a language switcher present. */
|
||||
language_selector = jQuery('select[name="icl_post_language"]');
|
||||
if (jQuery('[name="_wpml_root_page"]').length !== 0) {
|
||||
jQuery('#edit-slug-box').hide();
|
||||
}
|
||||
|
||||
if (language_selector.length !== 0) {
|
||||
language_selector.on('change', iclPostLanguageAskConfirmation);
|
||||
iclSwitchPostLanguage();
|
||||
} else {
|
||||
// just add a hidden field with the information and the same id as the language switcher to the dom
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'wpml_get_default_lang'
|
||||
},
|
||||
success: function (response) {
|
||||
var hidden_language_field = jQuery('<input id="icl_post_language" type="hidden"/>');
|
||||
hidden_language_field.val(response.data);
|
||||
jQuery(".wrap").append(hidden_language_field);
|
||||
iclSwitchPostLanguage();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function iclGetSwitchLanguageConfirmation() {
|
||||
var lang_switch_confirm_html;
|
||||
var defer = jQuery.Deferred();
|
||||
|
||||
lang_switch_confirm_html = '<div id="icl_confirm_lang_switch">';
|
||||
lang_switch_confirm_html += '<h2>{switch_language_title}</h2>';
|
||||
lang_switch_confirm_html += '<p>{switch_language_message}</p>';
|
||||
lang_switch_confirm_html += '<p>{switch_language_confirm}</p>';
|
||||
lang_switch_confirm_html += '</div>';
|
||||
|
||||
// make sure the title is html entities encoded.
|
||||
var post_name = WPML_core.htmlentities(jQuery('#title').val());
|
||||
if (post_name.length == 0) {
|
||||
post_name = icl_post_edit_messages.empty_post_title;
|
||||
}
|
||||
|
||||
lang_switch_confirm_html = lang_switch_confirm_html.replace('{switch_language_title}', icl_post_edit_messages.switch_language_title);
|
||||
lang_switch_confirm_html = lang_switch_confirm_html.replace('{switch_language_message}', icl_post_edit_messages.switch_language_message);
|
||||
lang_switch_confirm_html = lang_switch_confirm_html.replace('{switch_language_confirm}', icl_post_edit_messages.switch_language_confirm);
|
||||
lang_switch_confirm_html = lang_switch_confirm_html.replace('{post_name}', '<i>' + post_name + '</i>');
|
||||
|
||||
jQuery(lang_switch_confirm_html).dialog({
|
||||
modal: true,
|
||||
width: 'auto',
|
||||
buttons: [
|
||||
{
|
||||
text : icl_post_edit_messages.ok_button_label,
|
||||
id : "ok",
|
||||
click: function () {
|
||||
defer.resolve();
|
||||
jQuery(this).dialog("close");
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
text : icl_post_edit_messages.cancel_button_label,
|
||||
id : "cancel",
|
||||
click: function () {
|
||||
defer.reject();
|
||||
jQuery(this).dialog("close");
|
||||
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
return defer.promise();
|
||||
}
|
||||
|
||||
function iclPostLanguageAskConfirmation() {
|
||||
|
||||
var post_language_switcher = jQuery('#icl_post_language');
|
||||
var previous_post_language = post_language_switcher.data('last_lang');
|
||||
|
||||
jQuery('#edit-slug-buttons').find('> .cancel').click();
|
||||
|
||||
iclGetSwitchLanguageConfirmation().done(function () {
|
||||
iclSwitchPostLanguage();
|
||||
}).fail(function () {
|
||||
post_language_switcher.val(previous_post_language);
|
||||
});
|
||||
}
|
||||
|
||||
function iclSwitchPostLanguage() {
|
||||
var post_language_switcher = jQuery('#icl_post_language');
|
||||
var parent = post_language_switcher.parent();
|
||||
var nonce = parent.find('[name="nonce"]').val();
|
||||
var new_post_language = post_language_switcher.val();
|
||||
var previous_post_language = post_language_switcher.data('last_lang');
|
||||
var post_id = jQuery('#post_ID').val();
|
||||
if (!previous_post_language) {
|
||||
post_language_switcher.data('last_lang', new_post_language);
|
||||
} else {
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
wpml_from: previous_post_language,
|
||||
action: 'wpml_switch_post_language',
|
||||
nonce: nonce,
|
||||
/** @todo: remove the following line as most likely obsolete */
|
||||
_icl_nonce: icl_post_edit_messages._nonce,
|
||||
wpml_to: new_post_language,
|
||||
wpml_post_id: post_id
|
||||
},
|
||||
success: function () {
|
||||
post_language_switcher.data('last_lang', new_post_language);
|
||||
var url = WPML_core.sanitize(jQuery(location).attr('href'));
|
||||
if (/lang=/.test(url)) {
|
||||
url = url.replace(/([\?&])(lang=)[^&#]*/, '$1$2' + new_post_language);
|
||||
} else {
|
||||
var sep = (url.indexOf('?') > -1) ? '&' : '?';
|
||||
url = url + sep + 'lang=' + new_post_language;
|
||||
}
|
||||
|
||||
window.location.replace(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,352 @@
|
||||
/*globals icl_ajx_url */
|
||||
|
||||
/**
|
||||
* Created by andrea.
|
||||
* Date: 23/01/14
|
||||
* Time: 17:28
|
||||
*/
|
||||
|
||||
jQuery(function ($) {
|
||||
|
||||
setupCopyButtons();
|
||||
|
||||
var postEdit = postEdit || {};
|
||||
|
||||
postEdit.$connect_translations_dialog = $('#connect_translations_dialog');
|
||||
postEdit.$no_posts_found_message = postEdit.$connect_translations_dialog.find('.js-no-posts-found');
|
||||
postEdit.$posts_found_container = postEdit.$connect_translations_dialog.find('.js-posts-found');
|
||||
postEdit.$ajax_loader = postEdit.$connect_translations_dialog.find('.js-ajax-loader');
|
||||
postEdit.$connect_translations_dialog_confirm = $("#connect_translations_dialog_confirm");
|
||||
|
||||
postEdit.connect_element_translations_open = function(event) {
|
||||
|
||||
if (typeof(event.preventDefault) !== 'undefined' ) {
|
||||
event.preventDefault();
|
||||
} else {
|
||||
event.returnValue = false;
|
||||
}
|
||||
|
||||
postEdit.$connect_translations_dialog.find('#post_search').val('');
|
||||
postEdit.$connect_translations_dialog.find('#assign_to_trid').val('');
|
||||
postEdit.$connect_translations_dialog.dialog('open');
|
||||
postEdit.connect_element_translations_data();
|
||||
|
||||
};
|
||||
|
||||
postEdit.connect_element_translations_data = function() {
|
||||
|
||||
var $connect_translations_dialog_selector = $('#post_search', postEdit.$connect_translations_dialog );
|
||||
|
||||
var trid = $('#icl_connect_translations_trid').val();
|
||||
var post_type = $('#icl_connect_translations_post_type').val();
|
||||
var source_language = $('#icl_connect_translations_language').val();
|
||||
var nonce = $('#_icl_nonce_get_orphan_posts').val();
|
||||
var data = 'icl_ajx_action=get_orphan_posts&source_language=' + source_language + '&trid=' + trid + '&post_type=' + post_type + '&_icl_nonce=' + nonce;
|
||||
|
||||
postEdit.$ajax_loader.show();
|
||||
|
||||
var request = $.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
dataType: 'json',
|
||||
data: data
|
||||
});
|
||||
|
||||
request.done(function( posts ) {
|
||||
|
||||
var $assignPostButton = $('.js-assign-button');
|
||||
|
||||
if ( posts.length > 0 ) {
|
||||
|
||||
postEdit.$posts_found_container.show();
|
||||
postEdit.$no_posts_found_message.hide();
|
||||
$assignPostButton.prop('disabled', false);
|
||||
|
||||
$connect_translations_dialog_selector.autocomplete({
|
||||
minLength: 0,
|
||||
source: posts,
|
||||
focus: function (event, ui) {
|
||||
$connect_translations_dialog_selector.val(ui.item.label);
|
||||
return false;
|
||||
},
|
||||
select: function (event, ui) {
|
||||
$connect_translations_dialog_selector.val(ui.item.label);
|
||||
$("#assign_to_trid").val(ui.item.value);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.focus()
|
||||
.data("ui-autocomplete")._renderItem = function (ul, item) {
|
||||
return $("<li>")
|
||||
.append(jQuery("<a></a>").text(item.label))
|
||||
.appendTo(ul);
|
||||
|
||||
};
|
||||
} else {
|
||||
postEdit.$posts_found_container.hide();
|
||||
postEdit.$no_posts_found_message.show();
|
||||
$assignPostButton.prop('disabled', true);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
request.always(function() {
|
||||
postEdit.$ajax_loader.hide(); // Hide ajax loader always, no matter if ajax succeed or not.
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
postEdit.connect_element_translations_init = function () {
|
||||
|
||||
postEdit.$connect_translations_dialog.dialog(
|
||||
{
|
||||
dialogClass : 'wpml-dialog otgs-ui-dialog',
|
||||
width : 'auto',
|
||||
modal : true,
|
||||
autoOpen : false,
|
||||
closeOnEscape: true,
|
||||
buttons : [
|
||||
{
|
||||
text : postEdit.$connect_translations_dialog.data('cancel-label'),
|
||||
'class': 'button button-secondary alignleft',
|
||||
click : function () {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}, {
|
||||
text : postEdit.$connect_translations_dialog.data('ok-label'),
|
||||
'class': 'button button-primary js-assign-button',
|
||||
click : function () {
|
||||
$(this).dialog("close");
|
||||
postEdit.connect_element_translations_do();
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
}(); // Auto executable function
|
||||
|
||||
postEdit.connect_element_translations_do = function() {
|
||||
|
||||
var trid = $("#assign_to_trid").val();
|
||||
var post_type = $('#icl_connect_translations_post_type').val();
|
||||
var post_id = $('#icl_connect_translations_post_id').val();
|
||||
var nonce = $('#_icl_nonce_get_posts_from_trid').val();
|
||||
|
||||
var data = 'icl_ajx_action=get_posts_from_trid&trid=' + trid + '&post_type=' + post_type + '&_icl_nonce=' + nonce;
|
||||
|
||||
var request = $.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
dataType: 'json',
|
||||
data: data
|
||||
});
|
||||
|
||||
request.done(function ( posts ) {
|
||||
|
||||
if ( posts.length > 0 ) {
|
||||
var $list = $('#connect_translations_dialog_confirm_list');
|
||||
$list.empty();
|
||||
var $ul = $('<ul />').appendTo( $list );
|
||||
|
||||
var translation_set_has_source_language = false;
|
||||
|
||||
$.each(posts, function () {
|
||||
var $li = $('<li>').append('<span></span>');
|
||||
$li.find('span').text('[' + this.language + '] ' + this.title);
|
||||
$li.appendTo ( $ul );
|
||||
if(this.source_language && !translation_set_has_source_language) {
|
||||
translation_set_has_source_language = true;
|
||||
}
|
||||
});
|
||||
|
||||
var alert = $('<p>').append(jQuery('<strong></strong>').html(postEdit.$connect_translations_dialog.data('alert-text')));
|
||||
alert.appendTo($list);
|
||||
|
||||
var set_as_source_checkbox = $('<input type="checkbox" value="1" name="set_as_source" />');
|
||||
|
||||
if(!translation_set_has_source_language) {
|
||||
set_as_source_checkbox.prop('checked', true);
|
||||
}
|
||||
var action = $('<label>').append(set_as_source_checkbox).append(postEdit.$connect_translations_dialog.data('set_as_source-text'));
|
||||
action.appendTo($list);
|
||||
|
||||
postEdit.$connect_translations_dialog_confirm.dialog(
|
||||
{
|
||||
dialogClass: 'wpml-dialog otgs-ui-dialog',
|
||||
resizable : false,
|
||||
width : 'auto',
|
||||
autoOpen : true,
|
||||
modal : true,
|
||||
buttons : [
|
||||
{
|
||||
text : postEdit.$connect_translations_dialog_confirm.data('cancel-label'),
|
||||
'class': 'button button-secondary alignleft',
|
||||
click : function () {
|
||||
$(this).dialog("close");
|
||||
postEdit.$connect_translations_dialog.dialog('open');
|
||||
}
|
||||
}, {
|
||||
text : postEdit.$connect_translations_dialog_confirm.data('assign-label'),
|
||||
'class': 'button button-primary js-confirm-connect-this-post',
|
||||
click : function () {
|
||||
|
||||
var $confirmButton = $('.js-confirm-connect-this-post');
|
||||
$confirmButton.prop('disabled', true).removeClass('button-primary').addClass('button-secondary');
|
||||
|
||||
$('<span class="spinner" />').appendTo($confirmButton);
|
||||
|
||||
var nonce = $('#_icl_nonce_connect_translations').val();
|
||||
|
||||
var data_object = {
|
||||
icl_ajx_action: 'connect_translations',
|
||||
post_id : post_id,
|
||||
post_type : post_type,
|
||||
new_trid : trid,
|
||||
_icl_nonce : nonce,
|
||||
set_as_source : (set_as_source_checkbox.is(':checked') ? 1 : 0)
|
||||
};
|
||||
|
||||
var request = $.ajax(
|
||||
{
|
||||
type : "POST",
|
||||
url : icl_ajx_url,
|
||||
dataType: 'json',
|
||||
data : data_object
|
||||
}
|
||||
);
|
||||
|
||||
request.done(
|
||||
function (result) {
|
||||
if (result) {
|
||||
postEdit.$connect_translations_dialog.dialog("close");
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
$('#icl_document_connect_translations_dropdown')
|
||||
.find('.js-set-post-as-source')
|
||||
.on('click', postEdit.connect_element_translations_open );
|
||||
|
||||
/**
|
||||
* HOTFIX DIALOG BOX
|
||||
* Remove when WooCommerce does not include jquery-ui smoothness anymore
|
||||
**/
|
||||
var jQueryUI = $( '#jquery-ui-style-css[href*="smoothness"]' ),
|
||||
jQuerySmoothnessHref;
|
||||
|
||||
// if jquery ui smoothness css is loaded
|
||||
if( jQueryUI.length ) {
|
||||
// click on Connect with translations
|
||||
$( 'body' ).on( 'click', '#icl_document_connect_translations_dropdown .js-set-post-as-source', function() {
|
||||
var connectDialog = $( '[aria-describedby="connect_translations_dialog"]'), intervalCheckDialog;
|
||||
|
||||
// abort if dialog does not exists
|
||||
if( ! connectDialog.length ) return false;
|
||||
|
||||
// backup href of jquery ui smoothness
|
||||
jQuerySmoothnessHref = jQueryUI.attr( 'href' );
|
||||
|
||||
// remove jquery ui smoothness css
|
||||
jQueryUI.attr( 'href', '' );
|
||||
|
||||
// check every 250ms if connect translations dialog is still open
|
||||
intervalCheckDialog = setInterval( function() {
|
||||
// if dialog is not open anymore
|
||||
if( ! connectDialog.is(':visible') ) {
|
||||
if( $( '.ui-widget-overlay' ).length == 0 ) {
|
||||
// reapply jquery ui smoothness css again
|
||||
jQueryUI.attr( 'href', jQuerySmoothnessHref );
|
||||
// stop interval
|
||||
clearInterval( intervalCheckDialog );
|
||||
}
|
||||
}
|
||||
}, 250 );
|
||||
} );
|
||||
}
|
||||
/* HOTFIX END */
|
||||
|
||||
var classic_wp_editor_form = $('#post');
|
||||
var is_duplicate_post = typeof icl_duplicate_data !== 'undefined' && icl_duplicate_data.duplicate_post;
|
||||
var classic_editor_duplicate_post_changed = classic_wp_editor_form.length && is_duplicate_post && icl_duplicate_data.wp_classic_editor_changed;
|
||||
|
||||
var post_form_callback = function (e) {
|
||||
if ( is_duplicate_post || classic_editor_duplicate_post_changed ) {
|
||||
e.preventDefault();
|
||||
var answer = window.confirm(icl_duplicate_data.icl_duplicate_message);
|
||||
var spinner = $('#publishing-action .spinner');
|
||||
if (answer) {
|
||||
spinner.toggleClass('is-active');
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: 'check_duplicate',
|
||||
post_id: icl_duplicate_data.duplicate_post,
|
||||
icl_duplciate_nonce: icl_duplicate_data.duplicate_post_nonce
|
||||
}
|
||||
})
|
||||
.success(function (res) {
|
||||
spinner.toggleClass('is-active');
|
||||
if (res.data) {
|
||||
is_duplicate_post = false;
|
||||
classic_wp_editor_form.submit();
|
||||
} else {
|
||||
alert(icl_duplicate_data.icl_duplicate_fail);
|
||||
}
|
||||
})
|
||||
.error(function () {
|
||||
spinner.toggleClass('is-active');
|
||||
alert(icl_duplicate_data.icl_duplicate_fail);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
classic_wp_editor_form.on('submit', post_form_callback);
|
||||
$(document).on('click', '.editor-post-publish-button', post_form_callback);
|
||||
|
||||
$(document).on('heartbeat-send', function (event, data) {
|
||||
data.icl_post_language = $('#icl_post_language').val();
|
||||
data.icl_trid = $('input[name="icl_trid"]').val();
|
||||
});
|
||||
});
|
||||
|
||||
function setupCopyButtons() {
|
||||
jQuery('#icl_translate_independent').click(function () {
|
||||
jQuery(this).attr('disabled', 'disabled').after(icl_ajxloaderimg);
|
||||
jQuery.ajax({
|
||||
type: "POST", url: icl_ajx_url,
|
||||
data: "icl_ajx_action=reset_duplication&post_id=" + jQuery('#post_ID').val() + '&_icl_nonce=' + jQuery('#_icl_nonce_rd').val(),
|
||||
success: function (msg) {
|
||||
location.reload(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
jQuery('#icl_set_duplicate').click(function () {
|
||||
if (confirm(jQuery(this).next().html())) {
|
||||
jQuery(this).attr('disabled', 'disabled').after(icl_ajxloaderimg);
|
||||
var icl_set_duplicate = jQuery('#icl_set_duplicate');
|
||||
var wpml_original_post_id = icl_set_duplicate.data('wpml_original_post_id');
|
||||
var post_lang = icl_set_duplicate.data('post_lang');
|
||||
jQuery.ajax({
|
||||
type: "POST", url: icl_ajx_url,
|
||||
data: "icl_ajx_action=set_duplication&wpml_original_post_id=" + wpml_original_post_id + '&_icl_nonce=' + jQuery('#_icl_nonce_sd').val() + '&post_lang=' + post_lang,
|
||||
success: function (msg) {
|
||||
location.replace(
|
||||
location.href.replace('post-new.php', 'post.php').replace(/&trid=([0-9]+)/, '') + '&post=' + msg.data.id + '&action=edit');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
jQuery(function () {
|
||||
"use strict";
|
||||
jQuery('.editinline').on(
|
||||
'click', function () {
|
||||
var lang, parentDiv, editButton, postLink;
|
||||
|
||||
parentDiv = jQuery(this).closest('div');
|
||||
editButton = parentDiv.find('.edit').find('a');
|
||||
postLink = editButton.attr('href');
|
||||
lang = postLink.match(/(?=lang=).*.$/).pop().replace('lang=', '');
|
||||
parseJSONTerms(lang);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* This is only used for hierarchical Taxonomies
|
||||
*
|
||||
* @param lang String
|
||||
*/
|
||||
|
||||
function parseJSONTerms(lang) {
|
||||
"use strict";
|
||||
var JSONString, allTerms, termsInCorrectLang, taxonomy;
|
||||
JSONString = jQuery('#icl-terms-by-lang').html();
|
||||
allTerms = JSON.parse(JSONString);
|
||||
if (allTerms.hasOwnProperty(lang)) {
|
||||
termsInCorrectLang = allTerms[lang];
|
||||
for (taxonomy in termsInCorrectLang) {
|
||||
if (termsInCorrectLang.hasOwnProperty(taxonomy)) {
|
||||
removeWrongLanguageTerms(termsInCorrectLang[taxonomy], taxonomy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function removeWrongLanguageTerms(termsList, taxonomy) {
|
||||
"use strict";
|
||||
var termsUL, termsListElements;
|
||||
|
||||
termsUL = jQuery('.' + taxonomy + '-checklist');
|
||||
termsListElements = termsUL.children('li[id^="' + taxonomy + '"]');
|
||||
|
||||
jQuery.each(
|
||||
termsListElements, function (index, liElement) {
|
||||
var termId, domElementID;
|
||||
domElementID = liElement.id;
|
||||
termId = domElementID.replace(taxonomy + '-', '');
|
||||
if (termsList.indexOf(termId) === -1) {
|
||||
jQuery(liElement).hide();
|
||||
} else {
|
||||
jQuery(liElement).show();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*globals jQuery, ajaxurl*/
|
||||
|
||||
jQuery(function () {
|
||||
"use strict";
|
||||
|
||||
jQuery('#wpml-tm-refresh-services').click(function () {
|
||||
var button = jQuery(this);
|
||||
|
||||
button.prop('disabled', true);
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url : ajaxurl,
|
||||
data: {
|
||||
'nonce': jQuery(this).data('nonce'),
|
||||
'action': 'wpml_tm_refresh_services'
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function ( res ) {
|
||||
button.prop( 'disabled', true );
|
||||
jQuery( '.wpml-tm-refresh-services-msg' ).html( res.data.message );
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
/*globals jQuery, ajaxurl */
|
||||
jQuery(function ($) {
|
||||
"use strict";
|
||||
|
||||
$('[data-js-callback="js-set-translation-editor"]').click(function () {
|
||||
|
||||
var enable_button = $(this);
|
||||
var notice = enable_button.closest('.otgs-notice');
|
||||
var nonce = notice.find('input[name="wpml_set_translation_editor_nonce"]').val();
|
||||
var success = notice.find('.js-done');
|
||||
var error = notice.find('.js-error');
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: {
|
||||
action: 'wpml_set_translation_editor',
|
||||
nonce: nonce
|
||||
},
|
||||
success: function (response) {
|
||||
error.hide();
|
||||
success.hide();
|
||||
notice.removeClass('notice-error error notice-info info');
|
||||
|
||||
if (response.success) {
|
||||
notice.addClass('notice-success');
|
||||
notice.addClass('success');
|
||||
|
||||
enable_button.hide();
|
||||
success.show();
|
||||
|
||||
setTimeout(function () {
|
||||
notice.fadeOut('slow');
|
||||
}, 2500);
|
||||
} else {
|
||||
notice.addClass('notice-error');
|
||||
notice.addClass('error');
|
||||
error.show();
|
||||
|
||||
if (null !== response.data) {
|
||||
error.find('strong').text(response.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
var ResetPreferredTS = function () {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
self.init = function () {
|
||||
var box = jQuery('#wpml_tm_reset_preferred_translation_service_btn');
|
||||
var button = box.find('.button-primary');
|
||||
var nonce = box.find('#wpml_tm_reset_preferred_translation_service_nonce').val();
|
||||
var spinner = box.find('.spinner');
|
||||
|
||||
button.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'wpml-tm-reset-preferred-translation-service',
|
||||
'nonce': box.find('#wpml_tm_reset_preferred_translation_service_nonce').val()
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
document.location.reload(true);
|
||||
} else {
|
||||
alert(response.data);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, status, error) {
|
||||
var parsedResponse = jqXHR.statusText || status || error;
|
||||
alert(parsedResponse);
|
||||
},
|
||||
complete: function () {
|
||||
spinner.removeClass('is-active');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
jQuery(function () {
|
||||
resetPreferredTS.init();
|
||||
});
|
||||
};
|
||||
|
||||
var resetPreferredTS = new ResetPreferredTS();
|
||||
@@ -0,0 +1,83 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global _, jQuery, ajaxurl, wpml_reset_pro_trans_config_strings */
|
||||
|
||||
/** @namespace wpml_reset_pro_trans_config_strings.placeHolder */
|
||||
/** @namespace wpml_reset_pro_trans_config_strings.confirmation */
|
||||
/** @namespace wpml_reset_pro_trans_config_strings.reset */
|
||||
/** @namespace wpml_reset_pro_trans_config_strings.action */
|
||||
/** @namespace wpml_reset_pro_trans_config_strings.nonce */
|
||||
|
||||
var ResetProTransConfig = function () {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
self.init = function () {
|
||||
var checkBox = jQuery('#icl_reset_pro_check');
|
||||
var button = jQuery('#icl_reset_pro_but');
|
||||
checkBox.on('change', function () {
|
||||
if (checkBox.is(":checked")) {
|
||||
button.removeClass('button-primary-disabled');
|
||||
} else {
|
||||
button.addClass('button-primary-disabled');
|
||||
}
|
||||
});
|
||||
button.on('click', function (event) {
|
||||
var spinner;
|
||||
var canReset;
|
||||
var result = false;
|
||||
var checkBoxChecked;
|
||||
var userConfirms;
|
||||
var buttonDisabled;
|
||||
|
||||
event.preventDefault();
|
||||
buttonDisabled = button.hasClass('button-primary-disabled');
|
||||
checkBoxChecked = checkBox.is(":checked");
|
||||
canReset = !buttonDisabled && checkBoxChecked;
|
||||
if (canReset) {
|
||||
userConfirms = confirm(wpml_reset_pro_trans_config_strings.confirmation);
|
||||
result = userConfirms;
|
||||
}
|
||||
|
||||
if (result) {
|
||||
spinner = jQuery('#' + wpml_reset_pro_trans_config_strings.placeHolder).find('.spinner');
|
||||
button.prop('disabled', true);
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': wpml_reset_pro_trans_config_strings.action,
|
||||
'nonce': wpml_reset_pro_trans_config_strings.nonce
|
||||
},
|
||||
dataType: 'json',
|
||||
success : function (response) {
|
||||
if (response.success) {
|
||||
alert(response.data);
|
||||
document.location.reload(true);
|
||||
} else {
|
||||
alert(response.data);
|
||||
}
|
||||
},
|
||||
error : function (jqXHR, status, error) {
|
||||
var parsedResponse = jqXHR.statusText || status || error;
|
||||
alert(parsedResponse);
|
||||
},
|
||||
complete: function () {
|
||||
button.prop('disabled', false);
|
||||
button.next().fadeOut();
|
||||
spinner.removeClass('is-active');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
jQuery(function () {
|
||||
resetProTransConfig.init();
|
||||
});
|
||||
};
|
||||
|
||||
var resetProTransConfig = new ResetProTransConfig();
|
||||
@@ -0,0 +1,346 @@
|
||||
/*global jQuery*/
|
||||
/*localization global: wpml_tm_strings*/
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
jQuery(function () {
|
||||
|
||||
|
||||
jQuery(document).on('change', '.icl_tj_select_translator select', icl_tm_assign_translator);
|
||||
|
||||
|
||||
jQuery('#icl_side_by_site').find('a[href="#cancel"]').click(function () {
|
||||
var anchor = jQuery(this);
|
||||
jQuery.ajax({
|
||||
type : "POST", url: ajaxurl, data: 'action=dismiss_icl_side_by_site',
|
||||
success: function () {
|
||||
anchor.parent().parent().fadeOut();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
// Translator notes - translation dashboard - start
|
||||
jQuery('.icl_tn_link').click(function () {
|
||||
jQuery('.icl_post_note:visible').slideUp();
|
||||
var anchor = jQuery(this);
|
||||
var spl = anchor.attr('id').split('_');
|
||||
var doc_id = spl[3];
|
||||
var icl_post_note_doc_id = jQuery('#icl_post_note_' + doc_id);
|
||||
if (icl_post_note_doc_id.css('display') !== 'none') {
|
||||
icl_post_note_doc_id.slideUp();
|
||||
} else {
|
||||
icl_post_note_doc_id.slideDown();
|
||||
var text_area = icl_post_note_doc_id.find('textarea');
|
||||
text_area.focus();
|
||||
text_area.data('original_value', text_area.val());
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.icl_tn_cancel').click(function () {
|
||||
var note_div = jQuery(this).closest('.icl_post_note'),
|
||||
text_area = note_div.find('textarea');
|
||||
|
||||
text_area.val( text_area.data('original_value' ) );
|
||||
note_div.slideUp();
|
||||
});
|
||||
|
||||
jQuery('.icl_tn_save').click(function () {
|
||||
var anchor = jQuery(this);
|
||||
anchor.closest('table').find('input').prop('disabled', true);
|
||||
var tn_post_id = anchor.closest('table').find('.icl_tn_post_id').val();
|
||||
var note = jQuery('#post_note_' + tn_post_id).val();
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=save_translator_note¬e=" + note + '&post_id=' + tn_post_id + '&_icl_nonce=' + jQuery('#_icl_nonce_stn_').val(),
|
||||
success: function () {
|
||||
anchor.closest('table').find('input').prop('disabled', false);
|
||||
anchor.closest('table').parent().slideUp();
|
||||
var note_icon = jQuery('#icl_tn_link_' + tn_post_id).find('i');
|
||||
if (anchor.closest('table').prev().val()) {
|
||||
note_icon.removeClass('otgs-ico-note-add-o').addClass('otgs-ico-note-edit-o');
|
||||
} else {
|
||||
note_icon.removeClass('otgs-ico-note-edit-o').addClass('otgs-ico-note-add-o');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
// Translator notes - translation dashboard - end
|
||||
|
||||
// MC Setup
|
||||
jQuery('#icl_doc_translation_method').submit(iclSaveForm);
|
||||
jQuery('#icl_page_sync_options').submit(iclSaveForm);
|
||||
jQuery('form[name="icl_custom_tax_sync_options"]').submit(iclSaveForm);
|
||||
jQuery('form[name="icl_custom_posts_sync_options"]').submit(iclSaveForm);
|
||||
jQuery('form[name="icl_cf_translation"]').submit(iclSaveForm);
|
||||
jQuery('form[name="icl_tcf_translation"]').submit(iclSaveForm);
|
||||
jQuery('form[name="wpml-old-jobs-editor"]').submit(iclSaveForm);
|
||||
|
||||
var icl_translation_jobs_basket = jQuery('#icl-translation-jobs-basket');
|
||||
icl_translation_jobs_basket.find('th :checkbox').change(iclTmSelectAllJobsBasket);
|
||||
icl_translation_jobs_basket.find('td :checkbox').change(iclTmUpdateJobsSelectionBasket);
|
||||
var icl_translation_jobs = jQuery('#icl-translation-jobs');
|
||||
icl_translation_jobs.find('td.js-check-all :checkbox').change(iclTmSelectAllJobsSelection);
|
||||
icl_translation_jobs.find('td :checkbox').change(update_translation_job_checkboxes);
|
||||
|
||||
jQuery('#icl_tm_jobs_dup_submit').click(function () {
|
||||
return confirm(jQuery(this).next().html());
|
||||
});
|
||||
|
||||
jQuery('#icl_hide_promo').click(function () {
|
||||
jQuery.ajax({type: "POST", url: ajaxurl, data: 'action=icl_tm_toggle_promo&value=1', success: function () {
|
||||
jQuery('.icl-translation-services').slideUp(function () {
|
||||
jQuery('#icl_show_promo').fadeIn();
|
||||
});
|
||||
}});
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('#icl_show_promo').click(function () {
|
||||
jQuery.ajax({type: "POST", url: ajaxurl, data: 'action=icl_tm_toggle_promo&value=0', success: function () {
|
||||
jQuery('#icl_show_promo').hide();
|
||||
jQuery('.icl-translation-services').slideDown();
|
||||
}});
|
||||
return false;
|
||||
});
|
||||
|
||||
// --- Start: XLIFF form handler ---
|
||||
var icl_xliff_options_form = jQuery('#icl_xliff_options_form');
|
||||
if (icl_xliff_options_form !== undefined) {
|
||||
jQuery("#icl_xliff_options_form").off();
|
||||
jQuery(document).on('submit', '#icl_xliff_options_form', icl_xliff_set_newlines);
|
||||
}
|
||||
|
||||
// --- End: XLIFF form handler ---
|
||||
|
||||
// Make the number in the translation basket tab flash.
|
||||
var translation_basket_flash = function (count) {
|
||||
|
||||
var basket_count = jQuery('#wpml-basket-items');
|
||||
var basket_tab = basket_count.parent();
|
||||
|
||||
if (basket_count.length && count) {
|
||||
count--;
|
||||
|
||||
var originalBackgroundColor = basket_tab.css('background-color');
|
||||
var originalColor = basket_tab.css('color');
|
||||
|
||||
flash_animate_element(basket_tab, '#0085ba', '#ffffff');
|
||||
if (count) {
|
||||
flash_animate_element(basket_tab, originalBackgroundColor, originalColor);
|
||||
}
|
||||
|
||||
translation_basket_flash(count);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
var flash_animate_element = function (element, backgroundColor, color) {
|
||||
element.animate({opacity: 1}, 500, function () {
|
||||
element.css({backgroundColor: backgroundColor, color: color});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
if (location.href.indexOf("main.php&sm=basket") == -1 ) {
|
||||
translation_basket_flash (3);
|
||||
}
|
||||
});
|
||||
|
||||
function icl_xliff_set_newlines(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var form = jQuery(this);
|
||||
var submitButton = form.find(':submit');
|
||||
|
||||
submitButton.prop('disabled', true);
|
||||
var ajaxLoader = jQuery(icl_ajxloaderimg).insertBefore(submitButton);
|
||||
var icl_xliff_newlines = jQuery("input[name=icl_xliff_newlines]:checked").val();
|
||||
var icl_xliff_version = jQuery("select[name=icl_xliff_version]").val();
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'set_xliff_options',
|
||||
security: wpml_xliff_ajax_nonce,
|
||||
icl_xliff_newlines: icl_xliff_newlines,
|
||||
icl_xliff_version: icl_xliff_version
|
||||
},
|
||||
success: function (msg) {
|
||||
if (!msg.error) {
|
||||
fadeInAjxResp('#icl_ajx_response', icl_ajx_saved);
|
||||
}
|
||||
else {
|
||||
alert(msg.error);
|
||||
}
|
||||
},
|
||||
error: function (msg) {
|
||||
fadeInAjxResp('#icl_ajx_response', icl_ajx_error);
|
||||
},
|
||||
complete: function () {
|
||||
ajaxLoader.remove();
|
||||
submitButton.prop('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function icl_tm_assign_translator() {
|
||||
var this_translator = jQuery(this);
|
||||
var translator_id = this_translator.val();
|
||||
var icl_tj_select_translator = this_translator.closest('.icl_tj_select_translator');
|
||||
var translation_controls = icl_tj_select_translator.find('.icl_tj_select_translator_controls');
|
||||
var job_id = translation_controls.attr('id').replace(/^icl_tj_tc_/, '');
|
||||
translation_controls.show();
|
||||
translation_controls.find('.icl_tj_cancel').click(function () {
|
||||
this_translator.val(jQuery('#icl_tj_ov_' + job_id).val());
|
||||
translation_controls.hide();
|
||||
});
|
||||
var jobType = jQuery('#icl_tj_ty_' + job_id).val();
|
||||
translation_controls.find('.icl_tj_ok').off().click(function () {
|
||||
icl_tm_assign_translator_request(job_id, translator_id, this_translator, jobType);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function icl_tm_assign_translator_request(job_id, translator_id, select, jobType) {
|
||||
var translation_controls = select.closest('.icl_tj_select_translator').find('.icl_tj_select_translator_controls');
|
||||
select.prop('disabled', true);
|
||||
translation_controls.find('.icl_tj_cancel, .icl_tj_ok').prop('disabled', true);
|
||||
var td_wrapper = select.parent().parent();
|
||||
|
||||
var ajaxLoader = jQuery( icl_ajxloaderimg ).insertBefore( translation_controls.find( '.icl_tj_ok' ) );
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
dataType: 'json',
|
||||
data: 'icl_ajx_action=assign_translator&job_id=' + job_id + '&translator_id=' + translator_id + '&job_type=' + jobType + '&_icl_nonce=' + jQuery('#_icl_nonce_at').val(),
|
||||
success: function (msg) {
|
||||
if (!msg.error) {
|
||||
translation_controls.hide();
|
||||
/** @namespace msg.service */
|
||||
if (msg.service !== 'local') {
|
||||
td_wrapper.html(msg.message);
|
||||
}
|
||||
}
|
||||
select.prop('disabled', false);
|
||||
translation_controls.find('.icl_tj_cancel, .icl_tj_ok').prop('disabled', false);
|
||||
ajaxLoader.remove();
|
||||
translation_controls.hide();
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function icl_tm_set_pickup_method(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var form = jQuery(this);
|
||||
var submitButton = form.find(':submit');
|
||||
|
||||
submitButton.prop('disabled', true);
|
||||
var ajaxLoader = jQuery(icl_ajxloaderimg).insertBefore(submitButton);
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
dataType: 'json',
|
||||
data: 'icl_ajx_action=set_pickup_mode&' + form.serialize(),
|
||||
success: function (msg) {
|
||||
if ( msg.success ) {
|
||||
icl_translations_pickup_box_populate();
|
||||
} else {
|
||||
fadeInAjxResp( '#icl_ajx_response_tpm', msg.data.message, true );
|
||||
}
|
||||
},
|
||||
complete: function () {
|
||||
ajaxLoader.remove();
|
||||
submitButton.prop('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function iclTmSelectAllJobsBasket(caller) {
|
||||
jQuery('#icl-translation-jobs-basket').find(':checkbox').prop('checked', jQuery(caller).prop('checked'));
|
||||
jQuery('#icl-tm-jobs-cancel-but').prop('disabled', !jQuery(caller).prop('checked'));
|
||||
}
|
||||
|
||||
function updateTMSelectAllCheckbox(tableSelector) {
|
||||
jQuery(tableSelector).find('td.js-check-all :checkbox').prop(
|
||||
'checked',
|
||||
!jQuery(tableSelector).find('.js-wpml-job-row :checkbox:not(:checked)').length
|
||||
);
|
||||
}
|
||||
|
||||
function update_translation_job_checkboxes() {
|
||||
updateJobCheckboxes('#icl-translation-jobs');
|
||||
updateTMSelectAllCheckbox('#icl-translation-jobs');
|
||||
}
|
||||
function updateJobCheckboxes(table_selector) {
|
||||
var job_parent = jQuery(table_selector);
|
||||
|
||||
jQuery('#icl-tm-jobs-cancel-but').prop('disabled', job_parent.find(':checkbox:checked').length === 0);
|
||||
if (job_parent.find(':checkbox:checked').length > 0) {
|
||||
var checked_items = job_parent.find('th :checkbox');
|
||||
if (job_parent.find('td :checkbox:checked').length === job_parent.find('td :checkbox').length) {
|
||||
checked_items.prop('checked', true);
|
||||
} else {
|
||||
checked_items.prop('checked', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function iclTmUpdateJobsSelectionBasket() {
|
||||
iclTmSelectAllJobsBasket(this);
|
||||
updateJobCheckboxes('#icl-translation-jobs-basket');
|
||||
}
|
||||
|
||||
function iclTmSelectAllJobsSelection() {
|
||||
jQuery('#icl-translation-jobs').find(':checkbox').prop(
|
||||
'checked',
|
||||
jQuery('#icl-translation-jobs td.js-check-all :checkbox').prop('checked')
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof String.prototype.startsWith !== 'function') {
|
||||
// see below for better implementation!
|
||||
String.prototype.startsWith = function (str){
|
||||
return this.slice(0, str.length) === str;
|
||||
};
|
||||
}
|
||||
if (typeof String.prototype.endsWith !== 'function') {
|
||||
String.prototype.endsWith = function (str){
|
||||
return this.slice(-str.length) === str;
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
(function($) {
|
||||
$(function () {
|
||||
$('#translation-notifications').on('change', 'input', function (e) {
|
||||
var input = $(e.target);
|
||||
var child = $('[name="' + input.data('child') + '"]');
|
||||
|
||||
if (child.length) {
|
||||
child.prop('disabled', !input.is(":checked"));
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
581
wp-content/plugins/sitepress-multilingual-cms/res/js/scripts.js
Normal file
581
wp-content/plugins/sitepress-multilingual-cms/res/js/scripts.js
Normal file
@@ -0,0 +1,581 @@
|
||||
/*global jQuery, icl_ajx_url, icl_ajx_saved, icl_ajx_error, icl_ajxloaderimg_src, wpml_core_strings */
|
||||
|
||||
var WPML_core = WPML_core || {};
|
||||
|
||||
WPML_core.htmlentities = function( s ) {
|
||||
return jQuery("<div/>").text( s ).html()
|
||||
};
|
||||
|
||||
WPML_core.sanitize = function(s) {
|
||||
if (typeof s === 'string' || s instanceof String) {
|
||||
return s.replace(/<script[^>]*?>.*?<\/script>/gi, '').
|
||||
replace(/<[\/\!]*?[^<>]*?>/gi, '').
|
||||
replace(/<style[^>]*?>.*?<\/style>/gi, '').
|
||||
replace(/<![\s\S]*?--[ \t\n\r]*>/gi, '').
|
||||
replace(/ /g, '');
|
||||
}
|
||||
|
||||
return s;
|
||||
};
|
||||
|
||||
jQuery(function ($) {
|
||||
// Predefine closeText of JQuery UI diaog
|
||||
jQuery.extend(jQuery.ui.dialog.prototype.options, { closeText: wpml_core_strings.dialogCloseText });
|
||||
|
||||
|
||||
var catAdder = jQuery('#category-adder');
|
||||
if (catAdder.html()) {
|
||||
catAdder.prepend('<p>' + icl_cat_adder_msg + '</p>');
|
||||
}
|
||||
jQuery('select[name="icl_translation_of"]').change(function () {
|
||||
jQuery('#icl_translate_options').fadeOut();
|
||||
});
|
||||
jQuery('#icl_dismiss_help').click(iclDismissHelp);
|
||||
jQuery('#icl_dismiss_upgrade_notice').click(iclDismissUpgradeNotice);
|
||||
jQuery(document).on('click', 'a.icl_toggle_show_translations', iclToggleShowTranslations);
|
||||
|
||||
/* needed for tagcloud */
|
||||
oldajaxurl = false;
|
||||
|
||||
jQuery(document).on('click', "#icl_make_translatable_submit", icl_make_translatable);
|
||||
|
||||
jQuery('a.icl_user_notice_hide').click(icl_hide_user_notice);
|
||||
|
||||
var slugTranslation = jQuery('#icl_slug_translation');
|
||||
if (slugTranslation.length) {
|
||||
iclSaveForm_success_cb.push(function (form, response) {
|
||||
if (form.attr('name') === 'icl_slug_translation') {
|
||||
if (response[1] === 1) {
|
||||
jQuery('.icl_slug_translation_choice').show();
|
||||
} else {
|
||||
jQuery('.icl_slug_translation_choice').hide();
|
||||
}
|
||||
} else if (form.attr('name') === 'icl_custom_posts_sync_options') {
|
||||
jQuery('.icl_st_slug_tr_warn').hide();
|
||||
}
|
||||
});
|
||||
|
||||
slugTranslation.submit(iclSaveForm);
|
||||
jQuery('.icl_slug_translation_choice input[type=checkbox]').change(function () {
|
||||
var table_row = jQuery(this).closest('tr');
|
||||
var cpt_slugs = jQuery(table_row).find('.js-cpt-slugs');
|
||||
|
||||
if (jQuery(this).prop('checked')) {
|
||||
cpt_slugs.show();
|
||||
}
|
||||
else {
|
||||
cpt_slugs.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
jQuery('#login_page_translation').click(function() {
|
||||
jQuery('#show_login_page_language_switcher_sub_section').toggle();
|
||||
})
|
||||
|
||||
if (jQuery('#icl_login_page_translation').length) {
|
||||
jQuery('#icl_login_page_translation').submit(iclSaveForm);
|
||||
}
|
||||
|
||||
jQuery('.icl_sync_custom_posts').change(function(){
|
||||
var val = WPML_core.sanitize( jQuery(this).val() );
|
||||
var table_row = jQuery(this).closest('tr');
|
||||
var cpt_slugs = jQuery(table_row).find('.js-cpt-slugs');
|
||||
var icl_slug_translation = jQuery(table_row).find(':checkbox');
|
||||
if (val === 1) {
|
||||
icl_slug_translation.closest('.icl_slug_translation_choice').show();
|
||||
if( icl_slug_translation.prop('checked') && cpt_slugs) {
|
||||
cpt_slugs.show();
|
||||
}
|
||||
} else if(cpt_slugs) {
|
||||
icl_slug_translation.closest('.icl_slug_translation_choice').hide();
|
||||
cpt_slugs.hide();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('.js-custom-post-mode').on('change', function () {
|
||||
var radio = $(this),
|
||||
slug = radio.data('slug')
|
||||
toggle = jQuery('input[name="automatic_post_type[' + slug + ']"]').closest('.otgs-toggle-group');
|
||||
|
||||
if (radio.val() === '1') {
|
||||
toggle.show();
|
||||
} else {
|
||||
toggle.hide();
|
||||
}
|
||||
});
|
||||
|
||||
$(function () {
|
||||
$('.js-type-translation-row').each(function () {
|
||||
if ($(this).find('.js-disabled-externally').length === 3) {
|
||||
$(this).hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
jQuery(document).on('focus', '.icl_error_input', function () {
|
||||
jQuery(this).removeClass('icl_error_input');
|
||||
});
|
||||
|
||||
$('.js-toggle-colors-edit').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $target = $( $(this).attr('href') );
|
||||
var $caret = $(this).find('.js-arrow-toggle');
|
||||
|
||||
if ( $target.is(':visible') ) {
|
||||
$target.slideUp();
|
||||
$caret.removeClass('dashicons-arrow-up').addClass('dashicons-arrow-down');
|
||||
}
|
||||
else {
|
||||
$target.slideDown();
|
||||
$caret.removeClass('dashicons-arrow-down').addClass('dashicons-arrow-up');
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#js-post-availability').on('change', function(e) {
|
||||
|
||||
var $target = $( $(this).data('target') );
|
||||
|
||||
if ( $(this).prop('checked') ) {
|
||||
$target.show();
|
||||
}
|
||||
else {
|
||||
$target.hide();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('.js-wpml-navigation-links a').on('click', function(e) { // prevent default scrolling for navigation links
|
||||
e.preventDefault();
|
||||
|
||||
var $target = $( $(this).attr('href') );
|
||||
|
||||
if ( $target.length !== 0 ) {
|
||||
var offset = 0;
|
||||
var wpAdminBar = jQuery('#wpadminbar');
|
||||
if ( wpAdminBar.length !== 0 ) {
|
||||
offset = wpAdminBar.height();
|
||||
}
|
||||
|
||||
$('html, body').animate({
|
||||
scrollTop: $target.offset().top - offset
|
||||
}, 300, function() {
|
||||
var $header = $target.find('.wpml-section-header h3');
|
||||
$header.addClass('active');
|
||||
setTimeout(function(){
|
||||
$header.removeClass('active');
|
||||
}, 700);
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
var icl_untranslated_blog_posts = $("input[name=icl_untranslated_blog_posts]");
|
||||
var icl_untranslated_blog_posts_help = $('#icl_untranslated_blog_posts_help');
|
||||
|
||||
var update_icl_untranslated_blog_posts = function () {
|
||||
//Get the value of currently selected radio option
|
||||
var value = WPML_core.sanitize( icl_untranslated_blog_posts.filter(':checked').val() );
|
||||
|
||||
if (value == 0) {
|
||||
icl_untranslated_blog_posts_help.fadeOut('slow');
|
||||
} else {
|
||||
icl_untranslated_blog_posts_help.fadeIn('slow');
|
||||
}
|
||||
};
|
||||
|
||||
update_icl_untranslated_blog_posts();
|
||||
icl_untranslated_blog_posts.on('click', update_icl_untranslated_blog_posts);
|
||||
|
||||
var last_form_id = localStorage.getItem( 'wpml-mlcs-last-form-id' );
|
||||
if ( last_form_id ) {
|
||||
var last_form = jQuery( "#" + last_form_id );
|
||||
if ( last_form.length ) {
|
||||
jQuery( 'html, body' ).animate( {
|
||||
scrollTop: last_form.offset().top
|
||||
}, 1000 );
|
||||
}
|
||||
localStorage.removeItem( 'wpml-mlcs-last-form-id' );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
(function($){
|
||||
function click_on_lock() {
|
||||
var radio_name = $( this ).data( 'radio-name' ),
|
||||
radio = $( 'input[name="' + radio_name + '"]' ),
|
||||
unlocked_name = $( this ).data( 'unlocked-name' ),
|
||||
slug = radio.data( 'slug' );
|
||||
|
||||
$( this ).fadeOut();
|
||||
radio.prop( 'disabled', false );
|
||||
$( 'input[name="' + unlocked_name + '"]' ).prop( 'value', '1' );
|
||||
$( 'input[name="automatic_post_type[' + slug + ']"]' ).prop( 'disabled', false );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function sync_lock_on_custom_fields_and_terms( form_id ) {
|
||||
var locks = $( '#' + form_id ).find( '.js-wpml-sync-lock' );
|
||||
locks.on( 'click', click_on_lock );
|
||||
}
|
||||
|
||||
$(document).on('icl-bind-locks', function (e) {
|
||||
sync_lock_on_custom_fields_and_terms(e.detail);
|
||||
});
|
||||
|
||||
$(document).ready( function() {
|
||||
$('#icl_custom_posts_sync_options .js-wpml-sync-lock, #icl_custom_tax_sync_options .js-wpml-sync-lock').on(
|
||||
'click',
|
||||
click_on_lock
|
||||
);
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
|
||||
function fadeInAjxResp(spot, msg, err){
|
||||
if(err != undefined){
|
||||
col = jQuery(spot).css('color');
|
||||
jQuery(spot).css('color','red');
|
||||
}
|
||||
jQuery(spot).html(WPML_core.purify(msg));
|
||||
jQuery(spot).fadeIn();
|
||||
window.setTimeout(fadeOutAjxResp, 3000, spot);
|
||||
if(err != undefined){
|
||||
jQuery(spot).css('color',col);
|
||||
}
|
||||
}
|
||||
|
||||
function fadeOutAjxResp(spot){
|
||||
jQuery(spot).fadeOut();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create custom event
|
||||
* A kind of simple "polyfill" to support IE11
|
||||
*
|
||||
* @param eventName
|
||||
* @param eventDetail
|
||||
*/
|
||||
function wpmlCustomEvent( eventName, eventDetail ) {
|
||||
if ( !!window.MSInputMethodContext && !!document.documentMode ) {
|
||||
// Internet Explorer 11
|
||||
const event = document.createEvent( 'CustomEvent' );
|
||||
event.initCustomEvent(
|
||||
eventName,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
document.dispatchEvent(event);
|
||||
} else {
|
||||
document.dispatchEvent( new CustomEvent( eventName, eventDetail ) );
|
||||
}
|
||||
}
|
||||
|
||||
var icl_ajxloaderimg = '<img src="'+icl_ajxloaderimg_src+'" alt="loading" width="16" height="16" />';
|
||||
|
||||
var iclHaltSave = false; // use this for multiple 'submit events'
|
||||
var iclSaveForm_success_cb = [];
|
||||
function iclSaveForm() {
|
||||
|
||||
if (iclHaltSave) {
|
||||
return false;
|
||||
}
|
||||
var form_name = jQuery(this).attr('name');
|
||||
jQuery('form[name="' + form_name + '"] .icl_form_errors').html('').hide();
|
||||
var ajx_resp = jQuery('form[name="' + form_name + '"] .icl_ajx_response').attr('id');
|
||||
fadeInAjxResp('#' + ajx_resp, icl_ajxloaderimg);
|
||||
var serialized_form_data = jQuery(this).serialize();
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=" + jQuery(this).attr('name') + "&" + serialized_form_data,
|
||||
success: function (msg) {
|
||||
var spl = msg.split('|');
|
||||
if (parseInt(spl[0]) == 1) {
|
||||
fadeInAjxResp('#' + ajx_resp, icl_ajx_saved);
|
||||
for (var i = 0; i < iclSaveForm_success_cb.length; i++) {
|
||||
iclSaveForm_success_cb[i](jQuery('form[name="' + form_name + '"]'), spl);
|
||||
}
|
||||
if (form_name == 'icl_slug_translation' ||
|
||||
form_name == 'wpml_ls_settings_form' ||
|
||||
form_name == 'icl_custom_posts_sync_options' ||
|
||||
form_name == 'icl_custom_tax_sync_options'
|
||||
) {
|
||||
localStorage.setItem( 'wpml-mlcs-last-form-id', form_name );
|
||||
location.reload( true );
|
||||
}
|
||||
var action = this.data.split( '&' )[0];
|
||||
action = action.split( '=' )[1];
|
||||
wpmlCustomEvent('icl-save-form-' + action );
|
||||
} else {
|
||||
var icl_form_errors = jQuery('form[name="' + form_name + '"] .icl_form_errors');
|
||||
var error_html = (typeof spl[1] != 'undefined') ? spl[1] : spl[0];
|
||||
icl_form_errors.html(WPML_core.purify(error_html));
|
||||
icl_form_errors.fadeIn();
|
||||
fadeInAjxResp('#' + ajx_resp, icl_ajx_error, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function iclDismissHelp(){
|
||||
var thisa = jQuery(this);
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=dismiss_help&_icl_nonce=" + WPML_core.sanitize( jQuery('#icl_dismiss_help_nonce').val() ),
|
||||
success: function(msg){
|
||||
thisa.closest('#message').fadeOut();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function iclDismissUpgradeNotice(){
|
||||
var thisa = jQuery(this);
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=dismiss_upgrade_notice&_icl_nonce=" + WPML_core.sanitize( jQuery('#_icl_nonce_dun').val() ),
|
||||
success: function(msg){
|
||||
thisa.parent().parent().fadeOut();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function iclToggleShowTranslations(){
|
||||
jQuery('a.icl_toggle_show_translations').toggle();
|
||||
jQuery('#icl_translations_table').toggle();
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=toggle_show_translations&_icl_nonce=" + WPML_core.sanitize( jQuery('#_icl_nonce_tst').val() )
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function icl_copy_from_original(lang, trid){
|
||||
jQuery('#icl_cfo').after(icl_ajxloaderimg).prop('disabled', true);
|
||||
|
||||
//has visual = set to normal non-html editing mode
|
||||
var ed;
|
||||
var content_type = (typeof tinyMCE !== 'undefined' && ( ed = tinyMCE.get('content') ) && !ed.isHidden() && ed.hasVisual === true) ? 'rich' : 'html';
|
||||
var excerpt_type = (typeof tinyMCE !== 'undefined' && ( ed = tinyMCE.get('excerpt') ) && !ed.isHidden() && ed.hasVisual === true) ? 'rich' : 'html';
|
||||
|
||||
// figure out all available editors and their types
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=copy_from_original&lang=" + lang + '&trid=' + trid + '&content_type=' + content_type + '&excerpt_type='
|
||||
+ excerpt_type + '&_icl_nonce=' + WPML_core.sanitize( jQuery('#_icl_nonce_cfo_' + trid).val() ),
|
||||
success: function (msg) {
|
||||
if (msg.error) {
|
||||
alert(msg.error);
|
||||
} else {
|
||||
try {
|
||||
if (msg.content) {
|
||||
if (typeof tinyMCE !== 'undefined' && (ed = tinyMCE.get('content')) && !ed.isHidden()) {
|
||||
ed.focus();
|
||||
if (tinymce.isIE) {
|
||||
ed.selection.moveToBookmark(tinymce.EditorManager.activeEditor.windowManager.bookmark);
|
||||
}
|
||||
ed.execCommand('mceInsertContent', false, msg.content);
|
||||
} else if (wpml_get_block_editor()) {
|
||||
wp.data.dispatch('core/editor').resetBlocks(wp.blocks.parse(msg.content));
|
||||
} else {
|
||||
wpActiveEditor = 'content';
|
||||
edInsertContent(edCanvas, msg.content);
|
||||
}
|
||||
|
||||
}
|
||||
if (typeof msg.title !== "undefined") {
|
||||
if (wpml_get_block_editor()) {
|
||||
wp.data.dispatch('core/editor').editPost({title: msg.title});
|
||||
} else {
|
||||
jQuery('#title-prompt-text').hide();
|
||||
jQuery('#title').val(msg.title);
|
||||
}
|
||||
}
|
||||
//handling of custom fields
|
||||
//these have to be of array type with the indexes editor_type editor_name and value
|
||||
//possible types are editor or text
|
||||
//in case of text te prompt to be removed might have to be provided
|
||||
for (var element in msg.builtin_custom_fields) {
|
||||
if (msg.builtin_custom_fields.hasOwnProperty(element) && msg.builtin_custom_fields[element].editor_type === 'editor') {
|
||||
if (typeof tinyMCE !== 'undefined' && ( ed = tinyMCE.get(msg.builtin_custom_fields[element].editor_name) ) && !ed.isHidden()) {
|
||||
ed.focus();
|
||||
if (tinymce.isIE) {
|
||||
ed.selection.moveToBookmark(tinymce.EditorManager.activeEditor.windowManager.bookmark);
|
||||
}
|
||||
ed.execCommand('mceInsertContent', false, msg.builtin_custom_fields[element].value);
|
||||
} else {
|
||||
wpActiveEditor = msg.builtin_custom_fields[element].editor_name;
|
||||
edInsertContent(edCanvas, msg.builtin_custom_fields[element].value);
|
||||
}
|
||||
} else {
|
||||
jQuery('#' + msg.builtin_custom_fields[element].editor_name).val(msg.builtin_custom_fields[element].value);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof msg.external_custom_fields !== "undefined") {
|
||||
wpml_copy_external_custom_fields_from_original(msg.external_custom_fields);
|
||||
}
|
||||
} catch (err) {
|
||||
}
|
||||
}
|
||||
jQuery('#icl_cfo').next().fadeOut();
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function wpml_get_block_editor() {
|
||||
return window._wpLoadBlockEditor || window._wpLoadGutenbergEditor;
|
||||
}
|
||||
|
||||
function wpml_copy_external_custom_fields_from_original(custom_fields) {
|
||||
var translation_already_contains_custom_fields = jQuery("#postcustomstuff #the-list tr input").length > 0;
|
||||
if (translation_already_contains_custom_fields) {
|
||||
return;
|
||||
}
|
||||
|
||||
var container = jQuery("#newmeta");
|
||||
var meta_key_field = container.find("#metakeyselect");
|
||||
var meta_value_field = container.find("#metavalue");
|
||||
var add_button = container.find("#newmeta-submit");
|
||||
|
||||
custom_fields.forEach(function(item) {
|
||||
meta_key_field.val(item.name);
|
||||
meta_value_field.val(item.value);
|
||||
add_button.click();
|
||||
});
|
||||
}
|
||||
|
||||
function icl_make_translatable(){
|
||||
var that = jQuery(this);
|
||||
jQuery(this).prop('disabled', true);
|
||||
jQuery('#icl_div_config').find('.icl_form_success').hide();
|
||||
var iclMakeTranslatable = jQuery('[name=icl_make_translatable]:checked');
|
||||
var translate_input = WPML_core.sanitize( iclMakeTranslatable.val() ).split(',');
|
||||
var translate = parseInt(translate_input[1]);
|
||||
var custom_post = translate_input[0];
|
||||
var custom_taxs_on = [];
|
||||
var custom_taxs_off = [];
|
||||
jQuery(".icl_mcs_custom_taxs").each(function(){
|
||||
if(jQuery(this).prop('checked')){
|
||||
custom_taxs_on.push(WPML_core.sanitize( jQuery(this).val() ));
|
||||
}else{
|
||||
custom_taxs_off.push(WPML_core.sanitize( jQuery(this).val() ));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var cfnames = [];
|
||||
var cfvals = [];
|
||||
jQuery('.icl_mcs_cfs:checked').each(function(){
|
||||
if(!jQuery(this).prop('disabled')){
|
||||
cfnames.push(jQuery(this).attr('name').replace(/^icl_mcs_cf_/,''));
|
||||
cfvals.push(WPML_core.sanitize( jQuery(this).val() ));
|
||||
}
|
||||
});
|
||||
|
||||
jQuery.post(location.href,
|
||||
{
|
||||
'post_id' : WPML_core.sanitize( jQuery('#post_ID').val() ),
|
||||
'icl_action' : 'icl_mcs_inline',
|
||||
'custom_post' : custom_post,
|
||||
'translate' : translate,
|
||||
'custom_taxs_on[]' : custom_taxs_on,
|
||||
'custom_taxs_off[]' : custom_taxs_off,
|
||||
'cfnames[]' : cfnames,
|
||||
'cfvals[]' : cfvals,
|
||||
'_icl_nonce' : WPML_core.sanitize( jQuery('#_icl_nonce_imi').val() )
|
||||
|
||||
},
|
||||
function(data) {
|
||||
that.prop('disabled', false);
|
||||
if(translate){
|
||||
var iclDiv = jQuery('#icl_div');
|
||||
if (iclDiv.length > 0) {
|
||||
iclDiv.remove();
|
||||
}
|
||||
var prependTo = jQuery('#side-sortables');
|
||||
prependTo = prependTo.html() ? prependTo : jQuery('#normal-sortables');
|
||||
prependTo.prepend(
|
||||
'<div id="icl_div" class="postbox">' + jQuery(data).find('#icl_div').html() + '</div>'
|
||||
);
|
||||
jQuery('#icl_mcs_details').html(jQuery(data).find('#icl_mcs_details').html());
|
||||
}else{
|
||||
jQuery('#icl_div').hide();
|
||||
jQuery('#icl_mcs_details').html('');
|
||||
}
|
||||
jQuery('#icl_div_config').find('.icl_form_success').fadeIn();
|
||||
|
||||
WPMLMetaBox.refresh.refreshMetaBox();
|
||||
}
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function icl_hide_user_notice(){
|
||||
var notice = jQuery(this).attr('href').replace(/^#/, '');
|
||||
var thisa = jQuery(this);
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=save_user_preferences&user_preferences[notices]["+notice+"]=1&_icl_nonce="+WPML_core.sanitize(jQuery('#_icl_nonce_sup').val()),
|
||||
success: function(msg){
|
||||
thisa.parent().parent().fadeOut();
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function icl_cf_translation_preferences_submit(cf, obj) {
|
||||
jQuery.ajax({
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: 'action=wpml_ajax&icl_ajx_action=wpml_cf_translation_preferences&translate_action='+
|
||||
WPML_core.sanitize(obj.parent().children('input:[name="wpml_cf_translation_preferences['+cf+']"]:checked').val())+'&'+
|
||||
WPML_core.sanitize(obj.parent().children('input:[name="wpml_cf_translation_preferences_data_'+cf+'"]').val()) +
|
||||
'&_icl_nonce = ' + WPML_core.sanitize(jQuery('#_icl_nonce_cftpn').val()),
|
||||
cache: false,
|
||||
error: function(html){
|
||||
jQuery('#wpml_cf_translation_preferences_ajax_response_'+cf).html('Error occured');
|
||||
},
|
||||
beforeSend: function(html){
|
||||
jQuery('#wpml_cf_translation_preferences_ajax_response_'+cf).html(icl_ajxloaderimg);
|
||||
},
|
||||
success: function(html){
|
||||
jQuery('#wpml_cf_translation_preferences_ajax_response_'+cf).html(WPML_core.purify(html));
|
||||
},
|
||||
dataType: 'html'
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
WPML_core.redirectUploadsOnLangParam = function() {
|
||||
var path = WPML_core.sanitize(window.location.pathname),
|
||||
upload_screen_file = 'upload.php',
|
||||
has_lang_param = 1 === window.location.search.search('lang');
|
||||
|
||||
if (path.slice(upload_screen_file.length * -1) === upload_screen_file && has_lang_param) {
|
||||
window.location = path;
|
||||
}
|
||||
};
|
||||
jQuery('ready', WPML_core.redirectUploadsOnLangParam() );
|
||||
@@ -0,0 +1,214 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global _, jQuery, ajaxurl, wpml_tm_service_activation_strings */
|
||||
|
||||
/** @namespace wpml_tm_service_activation_strings.alertTitle */
|
||||
/** @namespace wpml_tm_service_activation_strings.cancelledJobs */
|
||||
/** @namespace wpml_tm_service_activation_strings.openJobs */
|
||||
/** @namespace wpml_tm_service_activation_strings.keepLocalJobs */
|
||||
/** @namespace wpml_tm_service_activation_strings.errorCancellingJobs */
|
||||
/** @namespace wpml_tm_service_activation_strings.errorGeneric */
|
||||
/** @namespace wpml_tm_service_activation_strings.confirm */
|
||||
/** @namespace wpml_tm_service_activation_strings.yes */
|
||||
/** @namespace wpml_tm_service_activation_strings.no */
|
||||
/** @namespace data.opens */
|
||||
/** @namespace data.cancelled */
|
||||
|
||||
var ServiceActivation = function () {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
self.initClickAction = function (item, ajaxAction) {
|
||||
var elementName;
|
||||
elementName = item.attr('name');
|
||||
jQuery.ajax(
|
||||
{
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': ajaxAction,
|
||||
'nonce': elementName + '_nonce'
|
||||
},
|
||||
success: function (response) {
|
||||
var callback = ajaxAction + '_success';
|
||||
self[callback](response);
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
var callback = ajaxAction + '_error';
|
||||
self[callback](xhr, ajaxOptions, thrownError);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
self.displayResponseDialog = function (message) {
|
||||
self.responseDialog.find('p').empty();
|
||||
self.responseDialog.find('p').append(message);
|
||||
|
||||
self.responseDialog.dialog('open');
|
||||
};
|
||||
|
||||
self.displayConfirmationDialog = function (callback) {
|
||||
var message = wpml_tm_service_activation_strings.confirm;
|
||||
self.confirmationDialog.find('p').empty();
|
||||
self.confirmationDialog.find('p').append(message);
|
||||
|
||||
self.confirmationDialog.dialog(
|
||||
'option', 'buttons', [
|
||||
{
|
||||
text: wpml_tm_service_activation_strings.yes,
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
callback(true);
|
||||
}
|
||||
}, {
|
||||
text: wpml_tm_service_activation_strings.no,
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
callback(false);
|
||||
}
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
self.confirmationDialog.dialog('open');
|
||||
};
|
||||
|
||||
self.wpml_cancel_open_local_translators_jobs_error = function (xhr, ajaxOptions, thrownError) {
|
||||
var message = wpml_tm_service_activation_strings.errorCancellingJobs;
|
||||
alert(message);
|
||||
console.log(xhr);
|
||||
console.log(ajaxOptions);
|
||||
console.log(thrownError);
|
||||
};
|
||||
|
||||
self.wpml_keep_open_local_translators_jobs_error = function (xhr, ajaxOptions, thrownError) {
|
||||
var message = wpml_tm_service_activation_strings.errorGeneric;
|
||||
alert(message);
|
||||
console.log(xhr);
|
||||
console.log(ajaxOptions);
|
||||
console.log(thrownError);
|
||||
};
|
||||
|
||||
self.wpml_keep_open_local_translators_jobs_success = function (response) {
|
||||
var message;
|
||||
var success = response.success;
|
||||
if (success) {
|
||||
message = wpml_tm_service_activation_strings.keepLocalJobs;
|
||||
} else {
|
||||
message = wpml_tm_service_activation_strings.errorGeneric;
|
||||
}
|
||||
self.displayResponseDialog(message);
|
||||
};
|
||||
|
||||
self.wpml_cancel_open_local_translators_jobs_success = function (response) {
|
||||
var data = response.data;
|
||||
var success = response.success;
|
||||
|
||||
var message;
|
||||
if (success) {
|
||||
message = wpml_tm_service_activation_strings.cancelledJobs + ' ' + data.cancelled + '<br>';
|
||||
if (data.open) {
|
||||
message += wpml_tm_service_activation_strings.errorCancellingJobs + '<br>';
|
||||
message += wpml_tm_service_activation_strings.openJobs + ' ' + data.opens;
|
||||
}
|
||||
} else {
|
||||
message = wpml_tm_service_activation_strings.errorCancellingJobs;
|
||||
}
|
||||
self.displayResponseDialog(message);
|
||||
};
|
||||
|
||||
self.init = function () {
|
||||
var dialogHtml;
|
||||
|
||||
self.notice = jQuery('.wpml-service-activation-notice').first();
|
||||
self.actions = self.notice.find('.wpml-action');
|
||||
|
||||
dialogHtml = '<div title="' + wpml_tm_service_activation_strings.alertTitle + '">';
|
||||
dialogHtml += '<p></p>';
|
||||
dialogHtml += '</div>';
|
||||
|
||||
self.confirmationDialog = jQuery(dialogHtml);
|
||||
self.responseDialog = jQuery(dialogHtml);
|
||||
|
||||
self.confirmationDialog.dialog(
|
||||
{
|
||||
autoOpen: false,
|
||||
resizable: false,
|
||||
modal: true,
|
||||
width: 'auto',
|
||||
closeOnEscape: false,
|
||||
buttons: [
|
||||
{
|
||||
text: wpml_tm_service_activation_strings.yes,
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
}
|
||||
}, {
|
||||
text: wpml_tm_service_activation_strings.no,
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
self.responseDialog.dialog(
|
||||
{
|
||||
autoOpen: false,
|
||||
resizable: false,
|
||||
modal: true,
|
||||
width: 'auto',
|
||||
closeText: wpml_tm_service_activation_strings.closeButton,
|
||||
closeOnEscape: true,
|
||||
buttons: [
|
||||
{
|
||||
text: wpml_tm_service_activation_strings.closeButton,
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
}
|
||||
}
|
||||
],
|
||||
close: function () {
|
||||
window.location.reload(true);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
self.initElements();
|
||||
};
|
||||
self.initClick = function (item) {
|
||||
var ajaxAction = item.data('action');
|
||||
if (ajaxAction) {
|
||||
item.on(
|
||||
'click', function (event) {
|
||||
var callback;
|
||||
event.preventDefault();
|
||||
callback = function (proceed) {
|
||||
if (true === proceed) {
|
||||
self.initClickAction(item, ajaxAction);
|
||||
}
|
||||
};
|
||||
self.displayConfirmationDialog(callback);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
self.initElements = function () {
|
||||
if (self.notice) {
|
||||
_.each(
|
||||
self.actions, function (value) {
|
||||
var element = jQuery(value);
|
||||
self.initClick(element);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
jQuery(
|
||||
function () {
|
||||
serviceActivation.init();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var serviceActivation = new ServiceActivation();
|
||||
@@ -0,0 +1,90 @@
|
||||
/*jshint devel:true */
|
||||
/*global ajaxurl, _ */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.setTranslationRole = function ( $, content, nonce, role, validStateCallback ) {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
var init = function () {
|
||||
if ( content ) {
|
||||
self.newUserInputs = content.find( '.js-first-name, .js-last-name, .js-email, .js-user-name' );
|
||||
self.wpRoleSelect = content.find( '.js-role' );
|
||||
|
||||
self.newUserInputs.on( 'input', inputChange );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var setTranslationRole = function ( data, success, error ) {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: _.extend( data, {
|
||||
action: 'wpml_add_translation_' + role,
|
||||
nonce: nonce
|
||||
} ),
|
||||
success: function ( response ) {
|
||||
if ( response.success ) {
|
||||
success( response.data );
|
||||
} else {
|
||||
error( response.data );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
};
|
||||
|
||||
var inputChange = function( e ) {
|
||||
validStateCallback( self.isValid() );
|
||||
};
|
||||
|
||||
self.setExisting = function ( userId, success, error, extraData ) {
|
||||
setTranslationRole(
|
||||
_.extend( extraData, { user_id : userId } ),
|
||||
success,
|
||||
error
|
||||
);
|
||||
};
|
||||
|
||||
self.addNew = function ( success, error, extraData ) {
|
||||
setTranslationRole( _.extend( extraData, {
|
||||
first: $( self.newUserInputs[ 0 ] ).val(),
|
||||
last: $( self.newUserInputs[ 1 ] ).val(),
|
||||
email: $( self.newUserInputs[ 2 ] ).val(),
|
||||
user: $( self.newUserInputs[ 3 ] ).val(),
|
||||
role: self.wpRoleSelect.val()
|
||||
} ),
|
||||
success,
|
||||
error
|
||||
);
|
||||
};
|
||||
|
||||
self.isValid = function () {
|
||||
return self.getUserName() && self.isEmailValid( self.getEmail() );
|
||||
};
|
||||
|
||||
self.isEmailValid = function ( email ) {
|
||||
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return re.test( email );
|
||||
};
|
||||
|
||||
self.resetInputs = function() {
|
||||
self.newUserInputs.val( '' );
|
||||
};
|
||||
|
||||
self.getUserName = function() {
|
||||
return $( self.newUserInputs[ 3 ] ).val();
|
||||
};
|
||||
|
||||
self.getEmail = function() {
|
||||
return $( self.newUserInputs[ 2 ] ).val();
|
||||
};
|
||||
|
||||
init();
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Used on the language settings page, validates the text content of one row
|
||||
* of the language domains settings form and potentially sanitizes the contents
|
||||
* of the row's text field.
|
||||
* Un-checks the text fields validation checkbox in case the field contains an
|
||||
* empty string after sanitization.
|
||||
*
|
||||
* @param domainInput Object
|
||||
* @param domainCheckBox Object
|
||||
* @returns {{run: run}}
|
||||
* @constructor
|
||||
*/
|
||||
var WpmlDomainValidation = function (domainInput, domainCheckBox) {
|
||||
|
||||
return {
|
||||
run: function () {
|
||||
var textInput = domainInput.val().match(/^(?:.+\/\/)?([\w\.\-\:]*)/)[1];
|
||||
if (!textInput) {
|
||||
domainCheckBox.prop('checked', false)
|
||||
}
|
||||
domainInput.val(textInput ? textInput : '');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
*
|
||||
* @param usInstance Object an instance of underscore
|
||||
* @param templates Object a hash containing templates as arrays of html strings
|
||||
* @returns {{getTemplate: getTemplate}}
|
||||
* @constructor
|
||||
*/
|
||||
var WpmlTemplateCompiler = function (usInstance, templates) {
|
||||
var compiledTemplates = {};
|
||||
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @param {string} temp
|
||||
* @returns {*|false} compiled underscore template if a template for the given
|
||||
* index was found, false if no such template exists
|
||||
*/
|
||||
getTemplate: function (temp) {
|
||||
if (!templates.hasOwnProperty(temp)) {
|
||||
throw 'No such template: ' + temp;
|
||||
}
|
||||
if (compiledTemplates[temp] === undefined) {
|
||||
var template = templates[temp];
|
||||
if (template instanceof Array) {
|
||||
template = template.join("\n");
|
||||
}
|
||||
compiledTemplates[temp] = usInstance.template(template);
|
||||
}
|
||||
return compiledTemplates[temp];
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
if ( icl_vars.loadLanguageJs ) {
|
||||
var icl_lang = icl_vars.current_language;
|
||||
var icl_home = icl_vars.icl_home;
|
||||
|
||||
window.addLoadEvent = function(func) {
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', func);
|
||||
} else {
|
||||
func();
|
||||
}
|
||||
}
|
||||
}
|
||||
190
wp-content/plugins/sitepress-multilingual-cms/res/js/tags.js
Normal file
190
wp-content/plugins/sitepress-multilingual-cms/res/js/tags.js
Normal file
@@ -0,0 +1,190 @@
|
||||
jQuery(function () {
|
||||
if (jQuery('form input[name="action"]').attr('value') === 'add-tag') {
|
||||
jQuery('.form-wrap p[class="submit"]').before(jQuery('#icl_tax_menu').html());
|
||||
} else {
|
||||
var new_row = jQuery('#edittag table[class="form-table"] tr.term-description-wrap').clone()
|
||||
.removeClass('term-description-wrap').addClass('wpml-term-languages-wrap');
|
||||
jQuery('#edittag table[class="form-table"]:first').append(new_row);
|
||||
jQuery('#edittag table[class="form-table"]:first tr:last th:first').html(' ');
|
||||
jQuery('#edittag table[class="form-table"]:first tr:last td:last').html(jQuery('#icl_tax_menu').html());
|
||||
}
|
||||
jQuery('#icl_tax_menu').remove();
|
||||
|
||||
jQuery('select[name="icl_tag_language"]').change(function(){
|
||||
var lang = WPML_core.sanitize(jQuery(this).val());
|
||||
var ajx = WPML_core.sanitize(location.href).replace(/#(.*)$/,'');
|
||||
ajx = ajx.replace(/pagenum=([0-9]+)/,'');
|
||||
if(-1 == WPML_core.sanitize(location.href).indexOf('?')){
|
||||
url_glue='?';
|
||||
}else{
|
||||
url_glue='&';
|
||||
}
|
||||
|
||||
if(icl_this_lang != lang){
|
||||
jQuery('#icl_translate_options').fadeOut();
|
||||
}else{
|
||||
jQuery('#icl_translate_options').fadeIn();
|
||||
}
|
||||
|
||||
jQuery('#posts-filter').parent().load(ajx+url_glue+'lang='+lang + ' #posts-filter', {}, function(resp){
|
||||
strt = resp.indexOf('<span id="icl_subsubsub" class="icl_subsubsub">');
|
||||
endd = resp.indexOf('</span>\'', strt);
|
||||
lsubsub = resp.substr(strt,endd-strt+7);
|
||||
jQuery('table.widefat').before(lsubsub);
|
||||
tag_start = resp.indexOf('<div class="tagcloud">');
|
||||
tag_end = resp.indexOf('</div>', tag_start);
|
||||
tag_cloud = resp.substr(tag_start+22,tag_end-tag_start-22);
|
||||
jQuery('.tagcloud').html(tag_cloud);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
* This section reads the hidden div containing the JSON encoded array of categories for which no checkbox is to be displayed.
|
||||
* This is done to ensure that they cannot be deleted
|
||||
*/
|
||||
var defaultCategoryJSON, defaultCategoryJSONDiv, defaultCategoryIDs, key, id;
|
||||
|
||||
defaultCategoryJSONDiv = jQuery('#icl-default-category-ids');
|
||||
if (defaultCategoryJSONDiv.length !== 0) {
|
||||
defaultCategoryJSON = defaultCategoryJSONDiv.html();
|
||||
defaultCategoryIDs = JSON.parse(defaultCategoryJSON);
|
||||
|
||||
for (key in defaultCategoryIDs) {
|
||||
if (defaultCategoryIDs.hasOwnProperty(key)) {
|
||||
id = defaultCategoryIDs[key];
|
||||
removeDefaultCatCheckBox(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iclTagLangSelectBar.init();
|
||||
});
|
||||
|
||||
/**
|
||||
* Removes the checkbox for a given category from the DOM.
|
||||
* @param catID
|
||||
*/
|
||||
function removeDefaultCatCheckBox(catID) {
|
||||
var defaultCatCheckBox;
|
||||
|
||||
defaultCatCheckBox = jQuery('#cb-select-' + catID);
|
||||
|
||||
if (defaultCatCheckBox.length !== 0) {
|
||||
defaultCatCheckBox.remove();
|
||||
}
|
||||
}
|
||||
|
||||
var iclTagLangSelectBar = {
|
||||
bar: false,
|
||||
taxonomy: false,
|
||||
addTagForm: false,
|
||||
formBlocked: false,
|
||||
init: function () {
|
||||
"use strict";
|
||||
var self = this;
|
||||
self.addTagForm = jQuery('#addtag');
|
||||
self.bar = jQuery('#icl_subsubsub');
|
||||
self.taxonomy = WPML_core.sanitize( self.addTagForm.find('[name="taxonomy"]').val() );
|
||||
self.displayBar();
|
||||
self.addHiddenSearchField();
|
||||
|
||||
self.addTagForm.off('submit', 'preventSubmit');
|
||||
|
||||
self.addTagForm.on('blur', function(){
|
||||
self.formBlocked = false;
|
||||
});
|
||||
|
||||
jQuery(document).on('keydown', function(e){
|
||||
if(self.formBlocked){
|
||||
e.preventDefault();
|
||||
}
|
||||
if(e.keyCode == 13 && self.addTagForm.find('input:focus').length !== 0){
|
||||
self.formBlocked = true;
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(document).ajaxSuccess(function(evt, request, settings) {
|
||||
if(typeof settings === 'undefined' || typeof settings.data === 'undefined' || typeof settings.data.search === 'undefined') return;
|
||||
self.updateCountDisplay(settings);
|
||||
self.formBlocked = false;
|
||||
|
||||
if(settings.data.search('action=add-tag') != -1 && (settings.data.search('source_lang%3D') != -1 || settings.data.search('icl_translation_of') != -1) ) {
|
||||
|
||||
var taxonomy = '';
|
||||
var vars = settings.data.split("&");
|
||||
for (var i=0; i<vars.length; i++) {
|
||||
var pair = vars[i].split("=");
|
||||
if (pair[0] == 'taxonomy') {
|
||||
taxonomy = pair[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
jQuery('#icl_tax_'+taxonomy+'_lang .inside').html(icl_ajxloaderimg);
|
||||
jQuery.ajax({
|
||||
type:'GET',
|
||||
url : WPML_core.sanitize(location.href).replace(/&trid=([0-9]+)/, ''),
|
||||
data: '', // wpmlcore-5061
|
||||
success: function(msg){
|
||||
jQuery('#icl_tax_adding_notice').fadeOut();
|
||||
jQuery('#icl_tax_'+taxonomy+'_lang .inside').html(jQuery(msg).find('#icl_tax_'+taxonomy+'_lang .inside').html());
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
return self;
|
||||
},
|
||||
getCurrentLang: function () {
|
||||
"use strict";
|
||||
var self = this;
|
||||
|
||||
return WPML_core.sanitize( self.addTagForm.find('[name="icl_tax_' + self.taxonomy + '_language"]').val() );
|
||||
},
|
||||
addHiddenSearchField: function () {
|
||||
"use strict";
|
||||
var self = this;
|
||||
|
||||
var currentLang = self.bar.find('strong').find('span').attr('class');
|
||||
var hiddenField = jQuery('<input type="hidden" name="lang"/>');
|
||||
hiddenField.val(currentLang);
|
||||
jQuery('.search-form').append(hiddenField);
|
||||
|
||||
return self;
|
||||
},
|
||||
displayBar: function () {
|
||||
"use strict";
|
||||
var langBar = jQuery('#icl_subsubsub');
|
||||
jQuery('table.widefat').before(langBar);
|
||||
langBar.show();
|
||||
},
|
||||
updateCountDisplay: function (settings) {
|
||||
"use strict";
|
||||
var self = this;
|
||||
if (settings.data.search('action=add-tag') != -1 || settings.data.search('action=delete-tag') != -1) {
|
||||
var change = settings.data.search('action=add-tag') !== -1 ? 1 : -1;
|
||||
var currentLangCount = self.updateCountSpan(change);
|
||||
var numDisplayTop = jQuery('.top').find('.displaying-num');
|
||||
var displayNumTxt = numDisplayTop.text().replace(currentLangCount, currentLangCount + change);
|
||||
jQuery('.displaying-num').text(displayNumTxt)
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
updateCountSpan: function (change) {
|
||||
var self = this;
|
||||
var currentLangCount = 0;
|
||||
|
||||
[self.getCurrentLang(), 'all'].forEach(function (lang) {
|
||||
"use strict";
|
||||
var countElement = self.bar.find('.' + lang);
|
||||
var count = parseInt(countElement.text());
|
||||
var newCount = count + change;
|
||||
countElement.text(newCount);
|
||||
currentLangCount = countElement.closest('strong').length !== 0 ? count : currentLangCount;
|
||||
});
|
||||
|
||||
return currentLangCount;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
/*globals jQuery, document */
|
||||
|
||||
var WPML_Core = WPML_Core || {};
|
||||
WPML_Core.taxonomy_sync_complete_reload = function () {
|
||||
"use strict";
|
||||
location.reload();
|
||||
}
|
||||
|
||||
WPML_Core.taxonomy_sync_complete = function ( event, xhr, settings ) {
|
||||
"use strict";
|
||||
|
||||
if ( settings.data && typeof settings.data === 'string' ) {
|
||||
if ( settings.data.search( 'action=wpml_tt_sync_hierarchy_save' ) !== -1 ) {
|
||||
WPML_Core.taxonomy_sync_complete_reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(function () {
|
||||
"use strict";
|
||||
|
||||
jQuery(document).ajaxComplete(WPML_Core.taxonomy_sync_complete);
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
TaxonomyTranslation.collections.TermRows = Backbone.Collection.extend({
|
||||
model: TaxonomyTranslation.models.TermRow
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,101 @@
|
||||
/*globals ajaxurl, jQuery, document, window, WPML_core, wpml_taxonomies */
|
||||
|
||||
var TaxonomyTranslation = TaxonomyTranslation || {};
|
||||
TaxonomyTranslation.classes = {
|
||||
instantiatedTermModels : {}
|
||||
};
|
||||
TaxonomyTranslation.models = {};
|
||||
TaxonomyTranslation.collections = {};
|
||||
TaxonomyTranslation.views = {};
|
||||
TaxonomyTranslation.mainView = {};
|
||||
TaxonomyTranslation.mainView.filterView = {};
|
||||
TaxonomyTranslation.data = {};
|
||||
TaxonomyTranslation.data.translatedTaxonomyLabels = {};
|
||||
TaxonomyTranslation.data.compiledTemplates = {};
|
||||
TaxonomyTranslation.data.syncData = {};
|
||||
|
||||
/* WCML compatibility */
|
||||
WPML_Translate_taxonomy = {};
|
||||
WPML_Translate_taxonomy.callbacks = jQuery.Callbacks();
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
jQuery(function () {
|
||||
|
||||
var loading = jQuery('.wpml_taxonomy_loading .spinner');
|
||||
if (loading.length) {
|
||||
loading.css({
|
||||
'visibility': 'visible',
|
||||
'float' : 'left'
|
||||
});
|
||||
loading.show();
|
||||
}
|
||||
jQuery('.icl_tt_main_bottom').hide();
|
||||
|
||||
TaxonomyTranslation.data.activeLanguages = wpml_taxonomies.activeLanguages;
|
||||
TaxonomyTranslation.data.allLanguages = wpml_taxonomies.allLanguages;
|
||||
TaxonomyTranslation.data.taxonomies = wpml_taxonomies.taxonomies;
|
||||
TaxonomyTranslation.util.init();
|
||||
|
||||
var headerHTML = WPML_core[ 'templates/taxonomy-translation/main.html' ]({taxonomies: TaxonomyTranslation.data.taxonomies});
|
||||
jQuery("#wpml_tt_taxonomy_translation_wrap").html(headerHTML);
|
||||
|
||||
// WCML compatibility
|
||||
var taxonomySwitcher = jQuery("#icl_tt_tax_switch");
|
||||
var potentialHiddenSelectInput = jQuery('#tax-selector-hidden');
|
||||
var potentialHiddenTaxInput = jQuery('#tax-preselected');
|
||||
var taxonomy;
|
||||
|
||||
if (potentialHiddenSelectInput.length !== 0 && potentialHiddenSelectInput.val() && potentialHiddenTaxInput.length !== 0 && potentialHiddenTaxInput.val()) {
|
||||
taxonomy = potentialHiddenTaxInput.val();
|
||||
taxonomySwitcher.closest('label').hide();
|
||||
jQuery('[id="term-table-header"]').hide();
|
||||
jQuery('[id="term-table-summary"]').hide();
|
||||
taxonomySwitcher.val(taxonomy);
|
||||
loadModelAndView(taxonomy);
|
||||
TaxonomyTranslation.mainView.showLoadingSpinner();
|
||||
} else if ((taxonomy = taxonomyFromLocation()) !== false) {
|
||||
taxonomySwitcher.val(taxonomy);
|
||||
switchToTaxonomy(taxonomy);
|
||||
} else {
|
||||
taxonomySwitcher.one("change", function () {
|
||||
switchToTaxonomy(jQuery(this).val());
|
||||
});
|
||||
}
|
||||
|
||||
function switchToTaxonomy(taxonomy){
|
||||
|
||||
loadModelAndView(taxonomy);
|
||||
TaxonomyTranslation.mainView.showLoadingSpinner();
|
||||
|
||||
jQuery("#icl_tt_tax_switch").on("change", function () {
|
||||
TaxonomyTranslation.mainView.showLoadingSpinner();
|
||||
jQuery('.icl_tt_main_bottom').hide();
|
||||
jQuery('#taxonomy-translation').html('');
|
||||
TaxonomyTranslation.mainView.selectTaxonomy();
|
||||
});
|
||||
}
|
||||
|
||||
function isSyncTab(){
|
||||
return window.location.search.substring(1).indexOf('&sync=1') > -1;
|
||||
}
|
||||
|
||||
function loadModelAndView(taxonomy){
|
||||
TaxonomyTranslation.classes.taxonomy = new TaxonomyTranslation.models.Taxonomy({taxonomy: taxonomy});
|
||||
TaxonomyTranslation.mainView = new TaxonomyTranslation.views.TaxonomyView({model: TaxonomyTranslation.classes.taxonomy}, {sync: isSyncTab()});
|
||||
}
|
||||
|
||||
function taxonomyFromLocation() {
|
||||
var queryString = window.location.search.substring(1);
|
||||
var taxonomy = false;
|
||||
Object.getOwnPropertyNames(TaxonomyTranslation.data.taxonomies).forEach(function (tax) {
|
||||
if (queryString.indexOf('taxonomy=' + tax) > -1) {
|
||||
taxonomy = tax;
|
||||
}
|
||||
});
|
||||
|
||||
return taxonomy;
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,257 @@
|
||||
/*globals labels, ajaxurl, TaxonomyTranslation, Backbone, jQuery, _, WPML_Translate_taxonomy */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
TaxonomyTranslation.models.Taxonomy = Backbone.Model.extend({
|
||||
|
||||
defaults: function () {
|
||||
return {
|
||||
name: false,
|
||||
taxonomy: false,
|
||||
terms: {},
|
||||
parents: {},
|
||||
termNames: {},
|
||||
showSlugTranslationField: true
|
||||
};
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
TaxonomyTranslation.data.termRowsCollection = new TaxonomyTranslation.collections.TermRows();
|
||||
this.setTaxonomy(this.get("taxonomy"));
|
||||
},
|
||||
|
||||
setTaxonomy: function (taxonomy) {
|
||||
this.set("taxonomy", taxonomy, {silent: true});
|
||||
TaxonomyTranslation.data.termRowsCollection.reset();
|
||||
|
||||
if (taxonomy !== undefined) {
|
||||
this.getTaxonomyTerms(taxonomy);
|
||||
} else {
|
||||
this.trigger('newTaxonomySet');
|
||||
}
|
||||
},
|
||||
|
||||
getTaxonomyTerms: function (taxonomy) {
|
||||
var self = this;
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: {
|
||||
action: 'wpml_get_terms_and_labels_for_taxonomy_table',
|
||||
nonce: labels.wpml_taxonomy_translation_nonce,
|
||||
taxonomy: taxonomy
|
||||
},
|
||||
success: function (response) {
|
||||
var termsData = response.terms;
|
||||
var labelsData = response.taxLabelTranslations;
|
||||
|
||||
if (response.defaultLanguage) {
|
||||
self.set('defaultLang', response.defaultLanguage);
|
||||
}
|
||||
|
||||
if (labelsData) {
|
||||
TaxonomyTranslation.data.translatedTaxonomyLabels = labelsData;
|
||||
TaxonomyTranslation.data.langSelector = response.taxLangSelector;
|
||||
if (labelsData.st_default_lang) {
|
||||
self.set('stDefaultLang', labelsData.st_default_lang);
|
||||
self.set('showSlugTranslationField', labelsData[ labelsData.st_default_lang ]['showSlugTranslationField']);
|
||||
}
|
||||
} else {
|
||||
TaxonomyTranslation.data.translatedTaxonomyLabels = false;
|
||||
}
|
||||
|
||||
if (response.bottomContent) {
|
||||
self.set('bottomContent', response.bottomContent);
|
||||
}
|
||||
|
||||
TaxonomyTranslation.data.resultsTruncated = response.resultsTruncated;
|
||||
|
||||
if (termsData) {
|
||||
self.processData(termsData);
|
||||
} else {
|
||||
self.trigger('newTaxonomySet');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
processData: function (termsData) {
|
||||
|
||||
var parentTermIDs = [],
|
||||
parents = {},
|
||||
termNames = {};
|
||||
|
||||
_.each(termsData, function (tridGroup) {
|
||||
var termsObject = {};
|
||||
_.each(TaxonomyTranslation.data.activeLanguages, function (lang, code) {
|
||||
var term;
|
||||
if (tridGroup[code] !== undefined && tridGroup[code].term_taxonomy_id) {
|
||||
term = new TaxonomyTranslation.models.Term(tridGroup[code]);
|
||||
var parent = term.get("parent");
|
||||
if (parent > 0) {
|
||||
parentTermIDs.push(parent);
|
||||
}
|
||||
termsObject[code] = term;
|
||||
termNames[tridGroup[code].term_taxonomy_id] = tridGroup[code].name;
|
||||
}
|
||||
});
|
||||
TaxonomyTranslation.data.termRowsCollection.add(new TaxonomyTranslation.models.TermRow({
|
||||
trid: tridGroup.trid,
|
||||
terms: termsObject
|
||||
}));
|
||||
});
|
||||
|
||||
_.each(termsData, function (tridGroup) {
|
||||
_.each(TaxonomyTranslation.data.activeLanguages, function (lang, code) {
|
||||
if (tridGroup[code] !== undefined && parentTermIDs.indexOf(tridGroup[code].term_id) !== -1) {
|
||||
parents[tridGroup[code].term_id] = tridGroup[code].name;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
this.set("parents", parents, {silent: true});
|
||||
this.set("termNames", termNames, {silent: true});
|
||||
|
||||
this.trigger('newTaxonomySet');
|
||||
},
|
||||
|
||||
getOriginalTerm: function ( trid ) {
|
||||
var row = TaxonomyTranslation.data.termRowsCollection.get(trid);
|
||||
var originalTerm = null;
|
||||
var terms = row.get("terms");
|
||||
_.each( terms, function ( term ) {
|
||||
if ( term.get( "source_language_code") === null ) {
|
||||
originalTerm = term;
|
||||
}
|
||||
});
|
||||
return originalTerm;
|
||||
},
|
||||
getOriginalTermMeta: function( trid ) {
|
||||
var originalTerm = this.getOriginalTerm(trid),
|
||||
term_metas = [],
|
||||
original_meta_data;
|
||||
|
||||
original_meta_data = originalTerm.get('meta_data');
|
||||
_.each( original_meta_data, function ( meta_data, meta_key ) {
|
||||
term_metas.push({
|
||||
'meta_key': meta_key,
|
||||
'meta_value': meta_data
|
||||
});
|
||||
});
|
||||
|
||||
return term_metas;
|
||||
},
|
||||
getTermName: function (termID) {
|
||||
|
||||
var res = "";
|
||||
if (termID > 0) {
|
||||
var termNames = this.get("termNames");
|
||||
res = termID in termNames ? termNames[termID] : "";
|
||||
}
|
||||
|
||||
return res;
|
||||
},
|
||||
saveLabel: function (singular, plural, slug, lang) {
|
||||
var self = this;
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: {
|
||||
action: 'wpml_tt_save_labels_translation',
|
||||
nonce: labels.wpml_taxonomy_translation_nonce,
|
||||
singular: singular,
|
||||
plural: plural,
|
||||
slug: slug,
|
||||
taxonomy_language_code: lang,
|
||||
taxonomy: self.get('taxonomy')
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.data) {
|
||||
var newLabelData = response.data;
|
||||
if (newLabelData.singular && newLabelData.general && newLabelData.lang) {
|
||||
TaxonomyTranslation.data.translatedTaxonomyLabels[newLabelData.lang] = {
|
||||
singular: newLabelData.singular,
|
||||
general: newLabelData.general,
|
||||
slug: newLabelData.slug
|
||||
};
|
||||
WPML_Translate_taxonomy.callbacks.fire('wpml_tt_save_term_translation', self.get('taxonomy'));
|
||||
self.trigger("labelTranslationSaved");
|
||||
|
||||
return self;
|
||||
}
|
||||
}
|
||||
self.trigger("saveFailed");
|
||||
return self;
|
||||
},
|
||||
error: function () {
|
||||
self.trigger("saveFailed");
|
||||
return self;
|
||||
}
|
||||
});
|
||||
},
|
||||
isHierarchical: function(){
|
||||
var self = this;
|
||||
|
||||
return TaxonomyTranslation.data.taxonomies[self.get("taxonomy")].hierarchical;
|
||||
},
|
||||
loadSyncData: function (lang) {
|
||||
var self = this;
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: {
|
||||
action: 'wpml_tt_sync_hierarchy_preview',
|
||||
_icl_nonce: labels.wpml_tt_sync_hierarchy_nonce,
|
||||
taxonomy: self.get('taxonomy'),
|
||||
ref_lang: lang
|
||||
},
|
||||
success: function (response) {
|
||||
TaxonomyTranslation.data.syncData = response.data;
|
||||
self.trigger('syncDataLoaded');
|
||||
}
|
||||
});
|
||||
},
|
||||
doSync: function (lang) {
|
||||
var self = this;
|
||||
var tax = self.get('taxonomy');
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: {
|
||||
action: 'wpml_tt_sync_hierarchy_save',
|
||||
_icl_nonce: labels.wpml_tt_sync_hierarchy_nonce,
|
||||
taxonomy: tax,
|
||||
ref_lang: lang
|
||||
},
|
||||
success: function (response) {
|
||||
TaxonomyTranslation.data.syncData = response.data;
|
||||
self.setTaxonomy(tax);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
changeTaxStringsLanguage: function(sourceLang) {
|
||||
var self = this;
|
||||
var tax = self.get('taxonomy');
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: {
|
||||
action: 'wpml_tt_change_tax_strings_language',
|
||||
nonce: labels.wpml_taxonomy_translation_nonce,
|
||||
taxonomy: tax,
|
||||
source_lang: sourceLang
|
||||
},
|
||||
success: function () {
|
||||
self.setTaxonomy(tax);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,124 @@
|
||||
/*globals TaxonomyTranslation, _, Backbone */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
TaxonomyTranslation.models.TermRow = Backbone.Model.extend({
|
||||
|
||||
defaults: function () {
|
||||
return {
|
||||
terms: {},
|
||||
trid: false,
|
||||
allTranslated: false,
|
||||
parents: {}
|
||||
};
|
||||
},
|
||||
|
||||
idAttribute: "trid",
|
||||
|
||||
initialize: function (data, options) {
|
||||
var self = this;
|
||||
self.updateAllTranslated();
|
||||
var parents = {};
|
||||
_.each(data.terms, function (term, lang) {
|
||||
parents[lang] = term.get("parent");
|
||||
});
|
||||
|
||||
self.set("parents", parents);
|
||||
},
|
||||
|
||||
parentOf: function (parentID) {
|
||||
var self = this;
|
||||
var parents = self.get("parents");
|
||||
var res = false;
|
||||
_.each(parents, function (parent, lang) {
|
||||
if (parent == parentID) {
|
||||
res = true;
|
||||
return res;
|
||||
}
|
||||
});
|
||||
|
||||
return res;
|
||||
},
|
||||
|
||||
add: function (term) {
|
||||
|
||||
if (!this.get("trid") && term.get("trid")) {
|
||||
this.set("trid", term.get("trid"), {silent: true});
|
||||
}
|
||||
|
||||
if (term.get("trid") == this.get("trid") && term.get("language_code") && term.get("name")) {
|
||||
var terms = this.get("terms");
|
||||
terms[term.get("language_code")] = term;
|
||||
this.set("terms", terms, {silent: true});
|
||||
}
|
||||
this.updateAllTranslated();
|
||||
},
|
||||
|
||||
updateAllTranslated: function () {
|
||||
var self = this;
|
||||
var terms = self.get("terms");
|
||||
self.set("allTranslated", true, {silent: true});
|
||||
_.each(TaxonomyTranslation.util.langCodes, function (lang) {
|
||||
if (terms === undefined || terms[lang] === undefined || !terms[lang].get("name")) {
|
||||
self.set("allTranslated", false, {silent: true});
|
||||
}
|
||||
});
|
||||
return self;
|
||||
},
|
||||
|
||||
allTermsTranslated: function () {
|
||||
this.updateAllTranslated();
|
||||
return this.get("allTranslated");
|
||||
},
|
||||
translatedIn: function (lang) {
|
||||
var self = this;
|
||||
var terms = self.get("terms");
|
||||
var res = true;
|
||||
if (terms === undefined || terms[lang] === undefined || !terms[lang].get("name")) {
|
||||
res = false;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
matches: function (search) {
|
||||
var self = this;
|
||||
var res = false;
|
||||
_.each(TaxonomyTranslation.util.langCodes, function (lang) {
|
||||
if (self.matchesInLang(search, lang) === true) {
|
||||
res = true;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return res;
|
||||
},
|
||||
matchesInLang: function (search, lang) {
|
||||
var self = this;
|
||||
var terms = self.get("terms");
|
||||
var res = false;
|
||||
if (
|
||||
terms !== undefined &&
|
||||
terms[lang] !== undefined &&
|
||||
terms[lang].get("name") &&
|
||||
terms[lang].get("name").toLowerCase().indexOf(search.toLowerCase()) > -1
|
||||
) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
unSyncFilter: function () {
|
||||
var self = this;
|
||||
var syncData = TaxonomyTranslation.data.syncData;
|
||||
var terms = self.get("terms");
|
||||
var res = false;
|
||||
_.each(syncData, function (correction) {
|
||||
_.each(TaxonomyTranslation.util.langCodes, function (lang) {
|
||||
if (terms[lang] !== undefined && correction.translated_id == terms[lang].get('term_taxonomy_id')) {
|
||||
res = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,97 @@
|
||||
(function () {
|
||||
TaxonomyTranslation.models.Term = Backbone.Model.extend({
|
||||
|
||||
idAttribute: "term_taxonomy_id",
|
||||
|
||||
defaults: function () {
|
||||
return {
|
||||
name: false,
|
||||
trid: false,
|
||||
term_taxonomy_id: false,
|
||||
language_code: false,
|
||||
slug: false,
|
||||
parent: false,
|
||||
correctedParent: false,
|
||||
description: false,
|
||||
level: 0,
|
||||
correctedLevel: 0,
|
||||
source_language_code: false,
|
||||
meta_data: false
|
||||
};
|
||||
},
|
||||
|
||||
save: function (name, slug, description, meta_data) {
|
||||
var self = this;
|
||||
slug = slug ? slug : '';
|
||||
description = description ? description : '';
|
||||
|
||||
if (name) {
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: {
|
||||
action: 'wpml_save_term',
|
||||
name: name,
|
||||
slug: slug,
|
||||
_icl_nonce: labels.wpml_save_term_nonce,
|
||||
description: description,
|
||||
trid: self.get("trid"),
|
||||
term_language_code: self.get("language_code"),
|
||||
taxonomy: TaxonomyTranslation.classes.taxonomy.get("taxonomy"),
|
||||
meta_data: meta_data,
|
||||
force_hierarchical_sync: true
|
||||
},
|
||||
success: function (response) {
|
||||
var newTermData = response.data;
|
||||
|
||||
if (newTermData.language_code && newTermData.trid && newTermData.slug && newTermData.term_taxonomy_id) {
|
||||
self.set(newTermData);
|
||||
self.trigger("translationSaved");
|
||||
WPML_Translate_taxonomy.callbacks.fire('wpml_tt_save_term_translation', TaxonomyTranslation.classes.taxonomy.get("taxonomy"));
|
||||
} else {
|
||||
self.trigger("saveFailed");
|
||||
}
|
||||
return self;
|
||||
},
|
||||
error: function(){
|
||||
self.trigger("saveFailed");
|
||||
return self;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
isOriginal: function() {
|
||||
return this.get( 'source_language_code' ) === null;
|
||||
},
|
||||
getNameSlugAndDescription: function () {
|
||||
var self = this;
|
||||
var term = {};
|
||||
term.slug = self.getSlug();
|
||||
|
||||
term.description = self.get("description");
|
||||
if ( ! term.description ) {
|
||||
term.description = "";
|
||||
}
|
||||
term.name = self.get("name");
|
||||
if ( ! term.name) {
|
||||
term.name = "";
|
||||
}
|
||||
return term;
|
||||
},
|
||||
getSlug: function () {
|
||||
var self = this;
|
||||
|
||||
var slug = self.get("slug");
|
||||
if (!slug) {
|
||||
slug = "";
|
||||
}
|
||||
slug = decodeURIComponent(slug);
|
||||
|
||||
return slug;
|
||||
},
|
||||
getMetaData: function() {
|
||||
return this.get('meta_data');
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,706 @@
|
||||
this["WPML_core"] = this["WPML_core"] || {};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/copy-all-popup.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<div class="icl_tt_form wpml-dialog" id="icl_tt_form_' +
|
||||
((__t = ( trid + '_' + lang )) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( labels.copyToAllLanguages )) == null ? '' : __t) +
|
||||
'">\n\t<div class="wpml-dialog-body wpml-dialog-translate ">\n\n\t\t<p class="wpml-dialog-cols-icon">\n\t\t\t<i class="otgs-ico-copy wpml-dialog-icon-xl"></i>\n\t\t</p>\n\n\t\t<div class="wpml-dialog-cols-content">\n\t\t\t<p>\n\t\t\t\t' +
|
||||
((__t = ( copyMessage )) == null ? '' : __t) +
|
||||
'\n\t\t\t</p>\n\t\t\t<label><input type="checkbox" name="overwrite"> ' +
|
||||
((__t = ( labels.copyAllOverwrite )) == null ? '' : __t) +
|
||||
'</label>\n\t\t</div>\n\t\t<div class="wpml-dialog-footer ">\n\t\t\t<span class="errors icl_error_text"></span>\n\t\t\t<input class="cancel wpml-dialog-close-button alignleft" value="' +
|
||||
((__t = ( labels.cancel )) == null ? '' : __t) +
|
||||
'" type="button">\n\t\t\t<input class="button-primary js-copy-all-ok alignright" value="' +
|
||||
((__t = ( labels.Ok )) == null ? '' : __t) +
|
||||
'" type="submit">\n\t\t\t<span class="spinner alignright"></span>\n\t\t</div>\n\t</div>\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/filter.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<div class="icl-tt-tools tablenav top clearfix">\n\t';
|
||||
if ( mode === "translate" ) { ;
|
||||
__p += '\n\t\t' +
|
||||
((__t = ( WPML_core[ "templates/taxonomy-translation/status-trans-select.html" ]( { taxonomy: taxonomy } ) )) == null ? '' : __t) +
|
||||
'\n\t\t<label for="in-lang" id="in-lang-label" class="hidden">' +
|
||||
((__t = (labels.in)) == null ? '' : __t) +
|
||||
'</label>\n\t\t\t<select name="language" id="in-lang" class="hidden">\n\t\t\t\t<option value="all">' +
|
||||
((__t = ( labels.anyLang )) == null ? '' : __t) +
|
||||
'</option>\n\t\t\t\t';
|
||||
_.each(langs, function( lang, code ) { ;
|
||||
__p += '\n\t\t\t\t\t<option value="' +
|
||||
((__t = ( code )) == null ? '' : __t) +
|
||||
'">' +
|
||||
((__t = ( lang.label )) == null ? '' : __t) +
|
||||
'</option>\n\t\t\t\t';
|
||||
}); ;
|
||||
__p += '\n\t\t\t</select>\n\t\t<div class="alignright">\n\t\t\t<input type="text" name="search" id="tax-search" placeholder="' +
|
||||
((__t = ( labels.searchPlaceHolder )) == null ? '' : __t) +
|
||||
'" value="">\n\t\t</div>\n\t';
|
||||
} else { ;
|
||||
__p += '\n\t\t' +
|
||||
((__t = ( labels.refLang.replace( "%language%", WPML_core[ "templates/taxonomy-translation/ref_sync_select.html" ]( { taxonomy:taxonomy, langs:langs } ) ) )) == null ? '' : __t) +
|
||||
'\n\t';
|
||||
} ;
|
||||
__p += '\n\t<span class="spinner"></span>\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/individual-label.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<a class="icl_tt_label" id="' +
|
||||
((__t = (taxonomy)) == null ? '' : __t) +
|
||||
'_' +
|
||||
((__t = (lang)) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( langs[ lang ].label )) == null ? '' : __t) +
|
||||
': ' +
|
||||
((__t = ( labels.editTranslation )) == null ? '' : __t) +
|
||||
'">\n\t<i class="otgs-ico-edit"></i>\n</a>\n<div id="popup-' +
|
||||
((__t = (lang)) == null ? '' : __t) +
|
||||
'"></div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/label-popup.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<div class="icl_tt_form wpml-dialog" id="icl_tt_form_' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( labels.labelPopupDialogTitle )) == null ? '' : __t) +
|
||||
'">\n\t<div class="wpml-dialog-body wpml-dialog-translate ">\n\t\t<header class="wpml-term-translation-header">\n\t\t\t<h3 class="wpml-header-original">' +
|
||||
__e( labels.original ) +
|
||||
' <span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( langs[ source_lang ].flag )) == null ? '' : __t) +
|
||||
'"></span><strong>' +
|
||||
__e( langs[ source_lang ].label ) +
|
||||
'</strong></h3>\n\t\t\t<h3 class="wpml-header-translation">' +
|
||||
__e( labels.translationTo ) +
|
||||
' <span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( langs[ lang ].flag )) == null ? '' : __t) +
|
||||
'"></span><strong>' +
|
||||
__e( langs[ lang ].label ) +
|
||||
'</strong></h3>\n\t\t</header>\n\t\n\t\t<div class="wpml-form-row">\n\t\t\t<label for="' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'-singular">' +
|
||||
__e( labels.Singular ) +
|
||||
'</label>\n\t\t\t<input readonly id="' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'-singular-original" value="' +
|
||||
__e( originalLabels.singular ) +
|
||||
'" type="text">\n\t\t\t<button class="button-copy button-secondary js-button-copy otgs-ico-copy" title="' +
|
||||
__e( labels.copyFromOriginal ) +
|
||||
'"></button>\n\t\t\t<input class="js-translation js-required-translation" id="' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'-singular" value="' +
|
||||
__e( translatedLabels.singular ) +
|
||||
'" type="text">\n\t\t</div>\n\t\n\t\t<div class="wpml-form-row">\n\t\t\t<label for="' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'-plural">' +
|
||||
__e( labels.Plural ) +
|
||||
'</label>\n\t\t\t<input readonly id="' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'-plural-original" value="' +
|
||||
__e(originalLabels.general ) +
|
||||
'" type="text">\n\t\t\t<button class="button-copy button-secondary js-button-copy otgs-ico-copy" title="' +
|
||||
__e( labels.copyFromOriginal ) +
|
||||
'"></button>\n\t\t\t<input class="js-translation js-required-translation" id="' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'-plural" value="' +
|
||||
__e( translatedLabels.general ) +
|
||||
'" type="text">\n\t\t</div>\n\n\t\t';
|
||||
if( slugTranslationEnabled ) { ;
|
||||
__p += '\n\t\t\t<div class="wpml-form-row js-slug-translation-wrapper">\n\t\t\t\t<label for="' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'-slug">' +
|
||||
__e( labels.Slug ) +
|
||||
'</label>\n\t\t\t\t<input readonly id="' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'-slug-original" value="' +
|
||||
__e(originalLabels.slug ) +
|
||||
'" type="text">\n\t\t\t\t<button class="button-copy button-secondary js-button-copy otgs-ico-copy" title="' +
|
||||
__e( labels.copyFromOriginal ) +
|
||||
'"></button>\n\t\t\t\t<input class="js-translation" id="' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'-slug" value="' +
|
||||
__e( translatedLabels.slug ) +
|
||||
'" type="text">\n\t\t\t</div>\n\t\t';
|
||||
} ;
|
||||
__p += '\n\t\n\t\t<div class="wpml-dialog-footer ">\n\t\t\t<span class="errors icl_error_text"></span>\n\t\t\t<input class="cancel wpml-dialog-close-button alignleft" value="' +
|
||||
__e( labels.cancel ) +
|
||||
'" type="button">\n\t\t\t<input class="button-primary js-label-save alignright" value="' +
|
||||
__e( labels.save ) +
|
||||
'" type="submit">\n\t\t\t<span class="spinner alignright"></span>\n\t\t</div>\t\n\t</div>\n</div>\n\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/main.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<label for="icl_tt_tax_switch">\n\t' +
|
||||
((__t = (labels.taxToTranslate)) == null ? '' : __t) +
|
||||
'\n\t<select id="icl_tt_tax_switch">\n\t\t<option disabled selected> -- ' +
|
||||
((__t = (labels.taxonomy)) == null ? '' : __t) +
|
||||
' --</option>\n\t\t';
|
||||
_.each(taxonomies, function(taxonomy, index){ ;
|
||||
__p += '\n\t\t\t<option value="' +
|
||||
((__t = (index)) == null ? '' : __t) +
|
||||
'">\n\t\t\t\t' +
|
||||
((__t = (taxonomy.label)) == null ? '' : __t) +
|
||||
'\n\t\t\t</option>\n\t';
|
||||
}); ;
|
||||
__p += '\n\t</select>\n</label>\n<div class="wpml-loading-taxonomy"><span class="spinner is-active"></span>' +
|
||||
((__t = (labels.preparingTermsData)) == null ? '' : __t) +
|
||||
'</div>\n<div id="taxonomy-translation">\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/nav.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<div class="tablenav bottom">\n\t<div class="tablenav-pages" id="taxonomy-terms-table-nav">\n\t\t<span class="displaying-num">\n\t\t\t';
|
||||
if(pages > 1) { ;
|
||||
__p += '\n\t\t\t\t' +
|
||||
((__t = (items)) == null ? '' : __t) +
|
||||
' ' +
|
||||
((__t = (labels.items)) == null ? '' : __t) +
|
||||
'\n\t\t\t';
|
||||
} else if(pages === 1) {;
|
||||
__p += '\n\t\t\t\t1 ' +
|
||||
((__t = (labels.item)) == null ? '' : __t) +
|
||||
'\n\t\t\t';
|
||||
} ;
|
||||
__p += '\n\t\t</span>\n\t\t<a class="first-page ';
|
||||
if(page <= 1 ){ ;
|
||||
__p += ' disabled ';
|
||||
} ;
|
||||
__p += '" href="###" title="' +
|
||||
((__t = (labels.goToFirstPage)) == null ? '' : __t) +
|
||||
'">«</a>\n\t\t<a href="###" title="' +
|
||||
((__t = (labels.goToPreviousPage)) == null ? '' : __t) +
|
||||
'" class="prev-page ';
|
||||
if(page < 2 ) {;
|
||||
__p += ' disabled';
|
||||
} ;
|
||||
__p += '">‹</a>\n\t\t<input class="current-page" size="1" value="' +
|
||||
((__t = (page)) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = (labels.currentPage)) == null ? '' : __t) +
|
||||
'" type="text"/>\n\t\t' +
|
||||
((__t = ( labels.of )) == null ? '' : __t) +
|
||||
' <span class="total-pages">' +
|
||||
((__t = ( pages )) == null ? '' : __t) +
|
||||
'</span>\n\t\t<a class="next-page ';
|
||||
if(page == pages ) {;
|
||||
__p += ' disabled ';
|
||||
} ;
|
||||
__p += '" href="###" title="' +
|
||||
((__t = (labels.goToNextPage)) == null ? '' : __t) +
|
||||
'">›</a>\n\t\t<a class="last-page ';
|
||||
if(page == pages ) {;
|
||||
__p += ' disabled ';
|
||||
} ;
|
||||
__p += '" href="###" title="' +
|
||||
((__t = (labels.goToLastPage)) == null ? '' : __t) +
|
||||
'">»</a>\n\t</div>\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/no-terms-found.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<tr>\n\t<td colspan="2">\n\t\t<h2 class="text-center">' +
|
||||
((__t = ( message )) == null ? '' : __t) +
|
||||
'</h2>\n\t</td>\n</tr>';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/not-translated-label.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<a class="icl_tt_label lowlight" id="' +
|
||||
((__t = ( taxonomy )) == null ? '' : __t) +
|
||||
'_' +
|
||||
((__t = ( lang )) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( langs[ lang ].label )) == null ? '' : __t) +
|
||||
': ' +
|
||||
((__t = ( labels.addTranslation )) == null ? '' : __t) +
|
||||
'" >\n\t<i class="otgs-ico-add"></i>\n</a>\n<div id="popup-' +
|
||||
((__t = ( lang )) == null ? '' : __t) +
|
||||
'"></div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/original-label-disabled.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<span title="' +
|
||||
((__t = ( langs[ lang ].label )) == null ? '' : __t) +
|
||||
': ' +
|
||||
((__t = ( labels.originalLanguage )) == null ? '' : __t) +
|
||||
'">\n\t<i class="otgs-ico-original"></i>\n</span>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/original-label.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<td class="wpml-col-title">\n\t<span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( flag )) == null ? '' : __t) +
|
||||
'"></span><strong>' +
|
||||
((__t = ( taxLabel.singular + ' / ' + taxLabel.general )) == null ? '' : __t) +
|
||||
'</strong>\n\t<p>\n\t\t';
|
||||
if(!langSelector){ ;
|
||||
__p += '<a href="#" class="js-show-lang-selector">' +
|
||||
((__t = ( labels.changeLanguage )) == null ? '' : __t) +
|
||||
'</a>';
|
||||
} ;
|
||||
__p += '\n\t\t' +
|
||||
((__t = ( langSelector )) == null ? '' : __t) +
|
||||
'\n\t</p>\n</td>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/original-term-popup.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<div class="icl_tt_form wpml-dialog" id="icl_tt_form_' +
|
||||
((__t = ( trid + '_' + lang )) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( labels.originalTermPopupDialogTitle )) == null ? '' : __t) +
|
||||
'">\n\t<div class="wpml-dialog-body wpml-dialog-translate ">\n\t\t<header class="wpml-term-translation-header">\n\t\t\t<h3 class="wpml-header-original-no-translation">' +
|
||||
((__t = ( labels.original )) == null ? '' : __t) +
|
||||
' <span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( langs[ lang ].flag )) == null ? '' : __t) +
|
||||
'"></span><strong>' +
|
||||
((__t = ( langs[ lang ].label )) == null ? '' : __t) +
|
||||
'</strong></h3>\n\t\t</header>\n\t\n\t\t<div class="wpml-form-row-no-translation">\n\t\t\t<label for="term-name">' +
|
||||
((__t = ( labels.Name )) == null ? '' : __t) +
|
||||
'</label >\n\t\t\t<input id="term-name" value="' +
|
||||
((__t = ( term.name )) == null ? '' : __t) +
|
||||
'" type="text">\n\t\t</div>\n\n\t\t<div class="wpml-form-row-no-translation">\n\t\t\t<label for="term-slug">' +
|
||||
((__t = ( labels.Slug )) == null ? '' : __t) +
|
||||
'</label>\n\t\t\t<input id="term-slug" value="' +
|
||||
((__t = ( term.slug )) == null ? '' : __t) +
|
||||
'" type="text">\n\t\t</div>\n\t\t<div class="wpml-form-row-no-translation">\n\t\t\t<label for="term-description">' +
|
||||
((__t = ( labels.Description )) == null ? '' : __t) +
|
||||
'</label>\n\t\t\t<textarea id="term-description" cols="22" rows="4">' +
|
||||
((__t = ( term.description )) == null ? '' : __t) +
|
||||
'</textarea>\n\t\t</div>\n\t\t<div class="wpml-dialog-footer ">\n\t\t\t<span class="errors icl_error_text"></span>\n\t\t\t<input class="cancel wpml-dialog-close-button alignleft" value="' +
|
||||
((__t = ( labels.cancel )) == null ? '' : __t) +
|
||||
'" type="button">\n\t\t\t<input class="button-primary term-save alignright" value="' +
|
||||
((__t = ( labels.save )) == null ? '' : __t) +
|
||||
'" type="submit">\n\t\t\t<span class="spinner alignright"></span>\n\t\t</div>\t\n\t</div>\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/original-term.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<a class="icl_tt_term_name"\tid="' +
|
||||
((__t = (trid + '-' + lang)) == null ? '' : __t) +
|
||||
'">\n\t<span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( langs[ lang ].flag )) == null ? '' : __t) +
|
||||
'"></span>\n\t<strong>\n\t\t';
|
||||
if(!name){ ;
|
||||
__p += '\n\t\t\t' +
|
||||
((__t = (labels.lowercaseTranslate)) == null ? '' : __t) +
|
||||
'\n\t\t';
|
||||
} else { ;
|
||||
__p += '\n\t\t\t';
|
||||
if ( level > 0 ) { ;
|
||||
__p += '\n\t\t\t\t' +
|
||||
((__t = (Array(level+1).join('—') + " ")) == null ? '' : __t) +
|
||||
'\n\t\t\t';
|
||||
} ;
|
||||
__p += '\n\t\t\t' +
|
||||
((__t = (name)) == null ? '' : __t) +
|
||||
'\n\t\t';
|
||||
} ;
|
||||
__p += '\n\t</strong>\n</a>\n<div id="' +
|
||||
((__t = (trid + '-popup-' + lang)) == null ? '' : __t) +
|
||||
'"></div>\n<div class="row-actions">\n\t<a class="js-copy-to-all-langs">' +
|
||||
((__t = ( labels.copyToAllLanguages )) == null ? '' : __t) +
|
||||
'</a>\n</div>\n\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/ref_sync_select.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<select id="in-lang" name="language">\n\t';
|
||||
_.each( langs, function( lang, code ) { ;
|
||||
__p += '\n\t\t<option value="' +
|
||||
((__t = (code)) == null ? '' : __t) +
|
||||
'">' +
|
||||
((__t = ( lang.label )) == null ? '' : __t) +
|
||||
'</option>\n\t';
|
||||
}); ;
|
||||
__p += '\n</select>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/status-trans-select.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<div class="alignleft">\n\t<label for="status-select">' +
|
||||
((__t = (labels.Show)) == null ? '' : __t) +
|
||||
'</label>\n\t<select id="status-select" name="status">\n\t\t<option value="0">' +
|
||||
((__t = (labels.all + ' ' + taxonomy.label)) == null ? '' : __t) +
|
||||
'</option>\n\t\t<option value="1">' +
|
||||
((__t = (labels.untranslated + ' ' + taxonomy.label)) == null ? '' : __t) +
|
||||
'</option>\n\t</select>\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/table.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<table class="widefat striped fixed ' +
|
||||
((__t = ( ( mode !== 'sync' )? 'wpml-tt-table' : 'wpml-tt-sync-table' )) == null ? '' : __t) +
|
||||
'" id="tax-table-' +
|
||||
((__t = (tableType)) == null ? '' : __t) +
|
||||
'">\n\t<thead>\n\t\t<tr>\n\t\t\t';
|
||||
if ( mode !== 'sync' ) { ;
|
||||
__p += '\n\t\t\t\t<th class="wpml-col-title">' +
|
||||
((__t = ( firstColumnHeading )) == null ? '' : __t) +
|
||||
'</th>\n\t\t\t\t<th class="wpml-col-languages">\n\t\t\t\t\t';
|
||||
_.each(langs, function( lang ) { ;
|
||||
__p += '\n\t\t\t\t\t\t<span title="' +
|
||||
((__t = ( lang.label )) == null ? '' : __t) +
|
||||
'"><img src="' +
|
||||
((__t = ( lang.flag )) == null ? '' : __t) +
|
||||
'" alt="' +
|
||||
((__t = ( lang.label )) == null ? '' : __t) +
|
||||
'"></span>\n\t\t\t\t\t';
|
||||
}); ;
|
||||
__p += '\n\t\t\t\t</th>\n\t\t\t';
|
||||
} else { ;
|
||||
__p += '\n\t\t\t\t';
|
||||
_.each(langs, function( lang ) { ;
|
||||
__p += '\n\t\t\t\t\t<th class="wpml-col-ttsync">\n\t\t\t\t\t\t<span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( lang.flag )) == null ? '' : __t) +
|
||||
'" alt="' +
|
||||
((__t = ( lang.label )) == null ? '' : __t) +
|
||||
'"></span>' +
|
||||
((__t = ( lang.label )) == null ? '' : __t) +
|
||||
'\n\t\t\t\t\t</th>\n\t\t\t\t';
|
||||
}); ;
|
||||
__p += '\n\t\t\t';
|
||||
} ;
|
||||
__p += '\n\t\t</tr>\n\t</thead>\n</table>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/tabs.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<div id="term-table-tab-controls" class="wpml-tabs">\n\t<button class="nav-tab ' +
|
||||
((__t = ( ( mode ==='translate' ? 'nav-tab-active' : '' ) )) == null ? '' : __t) +
|
||||
'" id="term-table-header">' +
|
||||
((__t = ( headerTerms )) == null ? '' : __t) +
|
||||
'</button>\n\t';
|
||||
if( taxonomy.hierarchical ) {;
|
||||
__p += '\n\t\t<button class="nav-tab ' +
|
||||
((__t = ( ( mode ==='sync' ? 'nav-tab-active' : '' ) )) == null ? '' : __t) +
|
||||
'" id="term-table-sync-header">' +
|
||||
((__t = ( syncLabel )) == null ? '' : __t) +
|
||||
'</button>\n\t';
|
||||
} ;
|
||||
__p += '\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/taxonomy-main-wrap.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<div class="wpml-wrap">\n\t';
|
||||
if ( mode === 'translate' ) { ;
|
||||
__p += '\n\t\t<h3 id="term-table-summary">' +
|
||||
((__t = ( summaryTerms )) == null ? '' : __t) +
|
||||
'</h3>\n\t\t';
|
||||
if ( TaxonomyTranslation.data.resultsTruncated ) { ;
|
||||
__p += '\n\t\t<div class="icl-admin-message-warning"><p>' +
|
||||
((__t = ( resultsTruncated )) == null ? '' : __t) +
|
||||
'</p></div>\n\t\t';
|
||||
} ;
|
||||
__p += '\n\t\t<div id="wpml-taxonomy-translation-filters"></div>\n\t\t<div id="wpml-taxonomy-translation-terms-table"></div>\n\t\t<div id="wpml-taxonomy-translation-terms-nav"></div>\n\n\t\t<h3 id="term-label-summary">' +
|
||||
((__t = ( labelSummary )) == null ? '' : __t) +
|
||||
'</h3>\n\t\t';
|
||||
if ( TaxonomyTranslation.data.translatedTaxonomyLabels ) { ;
|
||||
__p += '\n\t\t\t<div id="wpml-taxonomy-translation-labels-table"></div>\n\t\t';
|
||||
} else { ;
|
||||
__p += '\n\t\t\t<div class="otgs-notice notice notice-warning"><p>' +
|
||||
((__t = ( labels.activateStringTranslation )) == null ? '' : __t) +
|
||||
'</p></div>\n\t\t';
|
||||
} ;
|
||||
__p += '\n\t';
|
||||
} else if ( mode === 'sync' ) { ;
|
||||
__p += '\n\t\t<div id="wpml-taxonomy-translation-filters"></div>\n\t\t';
|
||||
if ( hasContent ) { ;
|
||||
__p += '\n\t\t\t<div id="wpml-taxonomy-translation-terms-table"></div>\n\t\t\t<div id="wpml-taxonomy-translation-terms-nav"></div>\n\t\t\t<div class="wpml-tt-sync-section">\n\t\t\t\t<div class="wpml-tt-sync-legend">\n\t\t\t\t\t<strong>' +
|
||||
((__t = ( labels.legend )) == null ? '' : __t) +
|
||||
'</strong>\n\t\t\t\t\t<span class="wpml-parent-added" style="background-color:#CCFF99;">' +
|
||||
((__t = ( labels.willBeAdded )) == null ? '' : __t) +
|
||||
'</span>\n\t\t\t\t\t<span class="wpml-parent-removed" style="background-color:#F55959;">' +
|
||||
((__t = ( labels.willBeRemoved )) == null ? '' : __t) +
|
||||
'</span>\n\t\t\t\t</div>\n\t\t\t\t<div class="wpml-tt-sync-action">\n\t\t\t\t\t<input type="submit" class="button-primary button-lg" value="' +
|
||||
((__t = ( labels.synchronizeBtn )) == null ? '' : __t) +
|
||||
'" id="tax-apply">\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t';
|
||||
} else { ;
|
||||
__p += '\n\t\t\t<h2 class="text-center">' +
|
||||
((__t = ( labelSynced )) == null ? '' : __t) +
|
||||
'</h2>\n\t\t';
|
||||
} ;
|
||||
__p += '\n\t';
|
||||
} ;
|
||||
__p += '\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/term-not-synced.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<span class="icl_tt_term_name_sync" id="' +
|
||||
((__t = (trid + '-' + lang)) == null ? '' : __t) +
|
||||
'">\n\t';
|
||||
if ( name ) { ;
|
||||
__p += '\n\t\t' +
|
||||
((__t = ( parent )) == null ? '' : __t) +
|
||||
'</br>\n\t\t';
|
||||
if ( level > 0 ) { ;
|
||||
__p += '\n\t\t\t' +
|
||||
((__t = ( Array(level+1).join('—') + " " )) == null ? '' : __t) +
|
||||
'\n\t\t';
|
||||
} ;
|
||||
__p += '\n\t\t' +
|
||||
((__t = ( name )) == null ? '' : __t) +
|
||||
'\n\t';
|
||||
} ;
|
||||
__p += '\n</span>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/term-not-translated.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<a class="icl_tt_term_name lowlight" id="' +
|
||||
((__t = ( trid + '-' + lang )) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( langs[ lang ].label )) == null ? '' : __t) +
|
||||
': ' +
|
||||
((__t = ( labels.addTranslation )) == null ? '' : __t) +
|
||||
'" >\n\t<i class="otgs-ico-add"></i>\n</a>\n<div id="' +
|
||||
((__t = ( trid + '-popup-' + lang )) == null ? '' : __t) +
|
||||
'"></div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/term-original-disabled.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<span title="' +
|
||||
((__t = ( langs[ lang ].label )) == null ? '' : __t) +
|
||||
': ' +
|
||||
((__t = ( labels.originalLanguage )) == null ? '' : __t) +
|
||||
'">\n\t<i class="otgs-ico-original"></i>\n</span>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/term-popup.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<div class="icl_tt_form wpml-dialog" id="icl_tt_form_' +
|
||||
((__t = ( trid + '_' + lang )) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( labels.termPopupDialogTitle )) == null ? '' : __t) +
|
||||
'">\n\t<div class="wpml-dialog-body wpml-dialog-translate ">\n\t\t<header class="wpml-term-translation-header">\n\t\t\t<h3 class="wpml-header-original">' +
|
||||
((__t = ( labels.original )) == null ? '' : __t) +
|
||||
' <span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( langs[ source_lang ].flag )) == null ? '' : __t) +
|
||||
'"></span><strong>' +
|
||||
((__t = ( langs[ source_lang ].label )) == null ? '' : __t) +
|
||||
'</strong></h3>\n\t\t\t<h3 class="wpml-header-translation">' +
|
||||
((__t = ( labels.translationTo )) == null ? '' : __t) +
|
||||
' <span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( langs[ lang ].flag )) == null ? '' : __t) +
|
||||
'"></span><strong>' +
|
||||
((__t = ( langs[ lang ].label )) == null ? '' : __t) +
|
||||
'</strong></h3>\n\t\t</header>\n\t\n\t\t<div class="wpml-form-row">\n\t\t\t<label for="term-name">' +
|
||||
((__t = ( labels.Name )) == null ? '' : __t) +
|
||||
'</label>\n\t\t\t<input readonly id="term-name-original" value="' +
|
||||
((__t = ( original_term.name )) == null ? '' : __t) +
|
||||
'" type="text">\n\t\t\t<button class="button-copy button-secondary js-button-copy otgs-ico-copy" title="' +
|
||||
((__t = ( labels.copyFromOriginal )) == null ? '' : __t) +
|
||||
'"></button>\n\t\t\t<input id="term-name" value="' +
|
||||
((__t = ( term.name )) == null ? '' : __t) +
|
||||
'" type="text">\n\t\t</div>\n\t\n\t\t<div class="wpml-form-row">\n\t\t\t<label for="term-slug">' +
|
||||
((__t = ( labels.Slug )) == null ? '' : __t) +
|
||||
'</label>\n\t\t\t<input readonly id="term-slug-original" value="' +
|
||||
((__t = ( original_term.slug )) == null ? '' : __t) +
|
||||
'" type="text">\n\t\t\t<button class="button-copy button-secondary js-button-copy otgs-ico-copy" title="' +
|
||||
((__t = ( labels.copyFromOriginal )) == null ? '' : __t) +
|
||||
'"></button>\n\t\t\t<input id="term-slug" value="' +
|
||||
((__t = ( term.slug )) == null ? '' : __t) +
|
||||
'" type="text">\n\t\t</div>\n\t\t<div class="wpml-form-row">\n\t\t\t<label for="term-description">' +
|
||||
((__t = ( labels.Description )) == null ? '' : __t) +
|
||||
'</label>\n\t\t\t<textarea readonly id="term-description-original" cols="22" rows="4">' +
|
||||
((__t = ( original_term.description )) == null ? '' : __t) +
|
||||
'</textarea>\n\t\t\t<button class="button-copy button-secondary js-button-copy otgs-ico-copy" title="' +
|
||||
((__t = ( labels.copyFromOriginal )) == null ? '' : __t) +
|
||||
'"></button>\n\t\t\t<textarea id="term-description" cols="22" rows="4">' +
|
||||
((__t = ( term.description )) == null ? '' : __t) +
|
||||
'</textarea>\n\t\t</div>\n\t\t';
|
||||
if ( original_term_meta.length ) { ;
|
||||
__p += '\n\t\t\t<hr>\n\t\t\t<label>' +
|
||||
((__t = ( labels.termMetaLabel)) == null ? '' : __t) +
|
||||
'</label>\n\t\t\t<div class="wpml-form-row">\n\t\t\t\t';
|
||||
_.each(original_term_meta, function(meta_data){ ;
|
||||
__p += '\n\t\t\t\t\t<label for="term-meta">' +
|
||||
((__t = ( meta_data.meta_key )) == null ? '' : __t) +
|
||||
'</label>\n\t\t\t\t\t<input readonly value="' +
|
||||
__e( meta_data.meta_value ) +
|
||||
'" type="text">\n\t\t\t\t\t<button class="button-copy button-secondary js-button-copy otgs-ico-copy" title="' +
|
||||
((__t = ( labels.copyFromOriginal )) == null ? '' : __t) +
|
||||
'"></button>\n\t\t\t\t\t<input name="term-meta" class="term-meta" data-meta-key="' +
|
||||
((__t = ( meta_data.meta_key )) == null ? '' : __t) +
|
||||
'" value="' +
|
||||
__e( term_meta[meta_data.meta_key] ) +
|
||||
'" type="text">\n\t\t\t\t';
|
||||
}); ;
|
||||
__p += '\n\t\t\t</div>\n\t\t';
|
||||
} ;
|
||||
__p += '\n\t</div>\n\t<div class="wpml-dialog-footer ">\n\t\t<span class="errors icl_error_text"></span>\n\t\t<input class="cancel wpml-dialog-close-button alignleft" value="' +
|
||||
((__t = ( labels.cancel )) == null ? '' : __t) +
|
||||
'" type="button">\n\t\t<input class="button-primary term-save alignright" value="' +
|
||||
((__t = ( labels.save )) == null ? '' : __t) +
|
||||
'" type="submit">\n\t\t<span class="spinner alignright"></span>\n\t</div>\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/term-synced.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<span class="icl_tt_term_name_sync" id="' +
|
||||
((__t = (trid + '-' + lang)) == null ? '' : __t) +
|
||||
'">\n\t';
|
||||
if ( name ) { ;
|
||||
__p += '\n\t\t' +
|
||||
((__t = ( parent )) == null ? '' : __t) +
|
||||
'\n\t\t';
|
||||
if ( level > 0 ) { ;
|
||||
__p += '\n\t\t\t</br>\n\t\t\t' +
|
||||
((__t = ( Array(level+1).join('—') + " " )) == null ? '' : __t) +
|
||||
'\n\t\t';
|
||||
} ;
|
||||
__p += '\n\t\t' +
|
||||
((__t = ( name )) == null ? '' : __t) +
|
||||
'\n\t';
|
||||
} ;
|
||||
__p += '\n</span>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_core"]["templates/taxonomy-translation/term-translated.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<a class="icl_tt_term_name " id="' +
|
||||
((__t = ( trid + '-' + lang )) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( langs[ lang ].label )) == null ? '' : __t) +
|
||||
': ' +
|
||||
((__t = ( labels.editTranslation )) == null ? '' : __t) +
|
||||
'">\n\t<i class="otgs-ico-edit"></i>\n</a>\n<div id="' +
|
||||
((__t = ( trid + '-popup-' + lang )) == null ? '' : __t) +
|
||||
'"></div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
(function () {
|
||||
TaxonomyTranslation.util = {
|
||||
langCodes: [],
|
||||
init: function () {
|
||||
_.each(TaxonomyTranslation.data.activeLanguages, function (lang, code) {
|
||||
TaxonomyTranslation.util.langCodes.push(code);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,105 @@
|
||||
/*globals labels, TaxonomyTranslation, Backbone, WPML_core, jQuery, _ */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
TaxonomyTranslation.views.CopyAllPopUpView = Backbone.View.extend({
|
||||
|
||||
tagName: 'div',
|
||||
template: WPML_core[ 'templates/taxonomy-translation/copy-all-popup.html' ],
|
||||
model: TaxonomyTranslation.models.TermRow,
|
||||
|
||||
events: {
|
||||
'click .cancel': 'close',
|
||||
'click .js-copy-all-ok': 'copyAll'
|
||||
},
|
||||
initialize: function () {
|
||||
var self = this;
|
||||
self.dialog = null;
|
||||
return self;
|
||||
},
|
||||
|
||||
render: function () {
|
||||
|
||||
var self = this,
|
||||
trid = self.model.get('trid'),
|
||||
originalLang = self.getOriginalLanguage(),
|
||||
flagUrl = TaxonomyTranslation.data.activeLanguages[ originalLang ].flag,
|
||||
langLabel = TaxonomyTranslation.data.activeLanguages[ originalLang ].label,
|
||||
copyMessage = labels.copyToAllMessage.replace( '%language%', '<img src="' + flagUrl + '"> <strong>' + langLabel + '</strong>' );
|
||||
|
||||
self.$el.html(
|
||||
this.template({
|
||||
trid: trid,
|
||||
lang: originalLang,
|
||||
labels: labels,
|
||||
copyMessage: copyMessage
|
||||
})
|
||||
);
|
||||
|
||||
self.delegateEvents();
|
||||
return self;
|
||||
},
|
||||
open: function ( ) {
|
||||
var self = this,
|
||||
popUpDomEl,
|
||||
trid = self.model.get( 'trid' ),
|
||||
lang = self.getOriginalLanguage();
|
||||
|
||||
self.render();
|
||||
popUpDomEl = jQuery('#' + trid + '-popup-' + lang);
|
||||
popUpDomEl.append( self.$el );
|
||||
|
||||
self.dialog = jQuery( '#icl_tt_form_' + trid + '_' + lang );
|
||||
self.dialog.dialog({
|
||||
autoOpen: true,
|
||||
modal: true,
|
||||
minWidth: 600,
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
dialogClass: 'dialog-fixed otgs-ui-dialog'
|
||||
});
|
||||
self.setElement( self.dialog );
|
||||
self.delegateEvents();
|
||||
|
||||
},
|
||||
close: function () {
|
||||
if ( this.dialog ) {
|
||||
this.dialog.dialog( 'close' );
|
||||
this.undelegateEvents();
|
||||
this.remove();
|
||||
this.dialog = null;
|
||||
}
|
||||
},
|
||||
getOriginalLanguage: function () {
|
||||
var trid = this.model.get( 'trid' );
|
||||
return TaxonomyTranslation.classes.taxonomy.getOriginalTerm( trid ).get( 'language_code' );
|
||||
},
|
||||
copyAll: function () {
|
||||
|
||||
var self = this,
|
||||
trid = self.model.get( 'trid' ),
|
||||
originalTerm = TaxonomyTranslation.classes.taxonomy.getOriginalTerm( trid ),
|
||||
name = originalTerm.get( 'name' ),
|
||||
slug = originalTerm.get( 'slug' ),
|
||||
description = originalTerm.get( 'description' ),
|
||||
overwrite = self.$el.find( 'input[name="overwrite"]:checked' ).length > 0;
|
||||
|
||||
self.$el.find('.js-copy-all-ok').prop( 'disabled', true );
|
||||
self.$el.find('.cancel').prop( 'disabled', true );
|
||||
|
||||
|
||||
var terms = self.model.get("terms");
|
||||
_.each( terms, function ( term ) {
|
||||
if ( overwrite || term.get( 'name' ) === false ) {
|
||||
term.save( name, slug, description );
|
||||
}
|
||||
});
|
||||
|
||||
self.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,129 @@
|
||||
/*globals TaxonomyTranslation, Backbone, WPML_core, labels, jQuery */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
TaxonomyTranslation.views.FilterView = Backbone.View.extend({
|
||||
|
||||
template: WPML_core[ 'templates/taxonomy-translation/filter.html' ],
|
||||
model: TaxonomyTranslation.models.Taxonomy,
|
||||
tag: "div",
|
||||
untranslated: false,
|
||||
parent: 0,
|
||||
lang: 'all',
|
||||
search: '',
|
||||
updatingFilter: false,
|
||||
|
||||
events: {
|
||||
"change #child_of": "updateFilter",
|
||||
"change #status-select": "updateFilter",
|
||||
"change #in-lang": "updateLangFilter",
|
||||
"keyup #tax-search": "updateFilter",
|
||||
"click #tax-apply": "updateTaxHierachy"
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
this.listenTo(this.model, 'newTaxonomySet', this.render);
|
||||
this.listenTo(this.model, 'syncDataLoaded', this.render);
|
||||
this.listenTo(this.model, 'modeChanged', this.modeChanged);
|
||||
this.listenTo(TaxonomyTranslation.classes.taxonomy, 'syncDataLoaded', this.updateLangFilter);
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
|
||||
if ( ! self.updatingFilter ) {
|
||||
var currentTaxonomy = self.model.get("taxonomy");
|
||||
|
||||
if (!currentTaxonomy) {
|
||||
return false;
|
||||
} else {
|
||||
currentTaxonomy = TaxonomyTranslation.data.taxonomies[currentTaxonomy];
|
||||
}
|
||||
|
||||
self.$el.html(self.template({
|
||||
langs: TaxonomyTranslation.data.activeLanguages,
|
||||
taxonomy: currentTaxonomy,
|
||||
parents: self.model.get("parents"),
|
||||
mode: TaxonomyTranslation.mainView.mode
|
||||
}));
|
||||
}
|
||||
|
||||
self.updatingFilter = false;
|
||||
return self;
|
||||
},
|
||||
updateLangFilter: function () {
|
||||
var self = this;
|
||||
|
||||
if (TaxonomyTranslation.mainView.mode === 'sync') {
|
||||
var newLang = self.selectedLang();
|
||||
if (self.lang !== newLang) {
|
||||
self.lang = newLang;
|
||||
self.updatingFilter = true;
|
||||
TaxonomyTranslation.classes.taxonomy.loadSyncData(newLang);
|
||||
TaxonomyTranslation.mainView.showLoadingSpinner();
|
||||
}
|
||||
} else {
|
||||
self.updateFilter();
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
updateFilter: function () {
|
||||
var self = this;
|
||||
|
||||
var parent = self.$el.find("#child_of").val();
|
||||
self.parent = parent != undefined && parent != -1 ? parent : 0;
|
||||
var untranslated = self.$el.find("#status-select").val();
|
||||
self.untranslated = !!(untranslated != undefined && untranslated == 1);
|
||||
self.setSelectVisibility();
|
||||
var search = self.$el.find("#tax-search").val();
|
||||
self.search = search != undefined && search.length > 1 ? search : 0;
|
||||
|
||||
self.trigger("updatedFilter");
|
||||
|
||||
return self;
|
||||
},
|
||||
|
||||
selectedLang: function(){
|
||||
|
||||
var self = this;
|
||||
var inLangSelect = self.$el.find("#in-lang");
|
||||
|
||||
return inLangSelect.val();
|
||||
},
|
||||
setSelectVisibility: function(){
|
||||
var self = this;
|
||||
var inLangLabel = jQuery('#in-lang-label');
|
||||
var inLangSelect = self.$el.find("#in-lang");
|
||||
if (self.untranslated || TaxonomyTranslation.mainView.mode === 'sync') {
|
||||
var lang = self.selectedLang();
|
||||
self.lang = lang != undefined && lang != 'all' ? lang : 'all';
|
||||
inLangSelect.show();
|
||||
inLangLabel.show();
|
||||
} else {
|
||||
self.lang = 'all';
|
||||
inLangSelect.hide();
|
||||
inLangLabel.hide();
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
modeChanged: function() {
|
||||
var self = this;
|
||||
if (TaxonomyTranslation.mainView.mode === 'translate') {
|
||||
self.render();
|
||||
}
|
||||
},
|
||||
updateTaxHierachy: function () {
|
||||
var self = this;
|
||||
|
||||
if (TaxonomyTranslation.mainView.mode === 'sync') {
|
||||
TaxonomyTranslation.mainView.model.doSync(self.selectedLang());
|
||||
} else {
|
||||
self.updateLangFilter();
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,148 @@
|
||||
(function () {
|
||||
TaxonomyTranslation.views.LabelPopUpView = Backbone.View.extend({
|
||||
|
||||
tagName: "div",
|
||||
template: WPML_core[ 'templates/taxonomy-translation/label-popup.html' ],
|
||||
model: TaxonomyTranslation.models.Taxonomy,
|
||||
|
||||
events: {
|
||||
"click .cancel": "close",
|
||||
"click .js-label-save": "saveLabel",
|
||||
"click .js-button-copy": "copyOriginal",
|
||||
"keydown" : "handleEnter",
|
||||
"input .js-translation": "updateUI"
|
||||
},
|
||||
initialize: function (data, options) {
|
||||
var self = this;
|
||||
self.lang = options.lang;
|
||||
self.defLang = options.defLang;
|
||||
self.listenTo(self.model, 'labelTranslationSaved', self.close);
|
||||
self.listenTo(self.model, 'saveFailed', self.render);
|
||||
return self;
|
||||
},
|
||||
|
||||
open: function ( lang ) {
|
||||
var self = this;
|
||||
self.render();
|
||||
var popUpDomEl = jQuery( '#popup-' + lang );
|
||||
popUpDomEl.append( self.$el );
|
||||
|
||||
self.dialog = jQuery( "#icl_tt_form_" + self.model.get( "taxonomy" ) );
|
||||
self.dialog.dialog({
|
||||
autoOpen: true,
|
||||
modal: true,
|
||||
minWidth: 800,
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
dialogClass: 'dialog-fixed otgs-ui-dialog'
|
||||
});
|
||||
self.setElement( self.dialog );
|
||||
self.delegateEvents();
|
||||
self.updateUI();
|
||||
},
|
||||
close: function () {
|
||||
if ( this.dialog ) {
|
||||
this.dialog.dialog( 'close' );
|
||||
this.undelegateEvents();
|
||||
this.remove();
|
||||
this.dialog = null;
|
||||
}
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
var taxonomy = self.model.get("taxonomy");
|
||||
var labels = TaxonomyTranslation.data.translatedTaxonomyLabels[self.lang];
|
||||
var originalLabels = TaxonomyTranslation.data.translatedTaxonomyLabels[self.model.get('stDefaultLang')];
|
||||
var slugTranslationEnabled = originalLabels['globalSlugTranslationEnabled']
|
||||
&& self.model.get('showSlugTranslationField');
|
||||
|
||||
if (!labels) {
|
||||
labels = {
|
||||
singular: undefined,
|
||||
general: undefined
|
||||
};
|
||||
}
|
||||
|
||||
this.$el.html(
|
||||
self.template({
|
||||
langs: TaxonomyTranslation.data.allLanguages,
|
||||
lang: self.lang,
|
||||
source_lang: self.model.get('stDefaultLang'),
|
||||
originalLabels: originalLabels,
|
||||
translatedLabels: labels,
|
||||
taxonomy: taxonomy,
|
||||
slugTranslationEnabled: slugTranslationEnabled
|
||||
})
|
||||
);
|
||||
|
||||
self.delegateEvents();
|
||||
|
||||
return self;
|
||||
},
|
||||
|
||||
handleEnter: function(e){
|
||||
var self = this;
|
||||
if(self.$el.find('input:focus').length !== 0 && e.keyCode == 13){
|
||||
self.saveLabel(e);
|
||||
}
|
||||
return self;
|
||||
},
|
||||
|
||||
updateUI: function ( e ) {
|
||||
var self = this,
|
||||
translationsEntered = true;
|
||||
|
||||
self.$el.find( '.js-required-translation' ).each( function () {
|
||||
if ( jQuery( this ).val() === '' ) {
|
||||
translationsEntered = false;
|
||||
}
|
||||
});
|
||||
|
||||
self.$el.find( '.js-label-save' ).prop( 'disabled', !translationsEntered );
|
||||
},
|
||||
|
||||
saveLabel: function (e) {
|
||||
var singularValueField, pluralValueField, slugValueField, singularValue, pluralValue, slugValue, self, inputPrefix;
|
||||
self = this;
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
inputPrefix = '#' + self.model.get("taxonomy") + '-';
|
||||
singularValueField = self.$el.find(inputPrefix + 'singular');
|
||||
pluralValueField = self.$el.find(inputPrefix + 'plural');
|
||||
slugValueField = self.$el.find(inputPrefix + 'slug');
|
||||
|
||||
if (singularValueField.length > 0 && pluralValueField.length > 0) {
|
||||
singularValue = singularValueField.val();
|
||||
pluralValue = pluralValueField.val();
|
||||
}
|
||||
|
||||
if (slugValueField.length > 0) {
|
||||
slugValue = slugValueField.val();
|
||||
}
|
||||
|
||||
if (singularValue && pluralValue) {
|
||||
self.undelegateEvents();
|
||||
|
||||
self.$el.find(".spinner").show();
|
||||
self.$el.find(".js-label-save").prop( 'disabled', true );
|
||||
self.$el.find(".cancel").prop( 'disabled', true );
|
||||
|
||||
self.model.saveLabel(singularValue, pluralValue, slugValue, self.lang);
|
||||
|
||||
}
|
||||
|
||||
return self;
|
||||
|
||||
},
|
||||
|
||||
copyOriginal: function ( e ) {
|
||||
var self = this,
|
||||
original = jQuery( e.currentTarget ).prev().val();
|
||||
|
||||
jQuery( e.currentTarget ).next().val( original );
|
||||
|
||||
self.updateUI();
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,108 @@
|
||||
(function () {
|
||||
|
||||
TaxonomyTranslation.views.LabelRowView = Backbone.View.extend({
|
||||
|
||||
tagName: 'tbody',
|
||||
model: TaxonomyTranslation.models.Taxonomy,
|
||||
events: {
|
||||
'click .icl_tt_label': 'openPopUPLabel',
|
||||
'click .js-show-lang-selector': 'showLanguageSelector',
|
||||
'change .js-tax-lang-selector': 'changeTaxStringsLanguage'
|
||||
},
|
||||
initialize: function () {
|
||||
var self = this;
|
||||
self.listenTo(self.model, 'labelTranslationSaved', self.render);
|
||||
},
|
||||
|
||||
showLanguageSelector: function(e) {
|
||||
e.preventDefault();
|
||||
this.render( true );
|
||||
|
||||
if ( WPML_Core.SimpleLanguageSelector ) {
|
||||
new WPML_Core.SimpleLanguageSelector();
|
||||
}
|
||||
},
|
||||
|
||||
render: function ( withLangSelector ) {
|
||||
var self = this,
|
||||
taxLabels = TaxonomyTranslation.data.translatedTaxonomyLabels,
|
||||
langs = TaxonomyTranslation.util.langCodes,
|
||||
taxonomy = self.model.get( 'taxonomy' ),
|
||||
labelLang = TaxonomyTranslation.classes.taxonomy.get( 'stDefaultLang' ),
|
||||
langSelector = withLangSelector ? TaxonomyTranslation.data.langSelector : '',
|
||||
html = '<tr>';
|
||||
|
||||
|
||||
html += WPML_core[ 'templates/taxonomy-translation/original-label.html' ](
|
||||
{
|
||||
taxLabel : taxLabels[labelLang],
|
||||
flag : TaxonomyTranslation.data.allLanguages[labelLang].flag,
|
||||
langSelector: langSelector
|
||||
}
|
||||
);
|
||||
|
||||
html += '<td class="wpml-col-languages">';
|
||||
|
||||
_.each(langs, function(lang, code) {
|
||||
if( ! taxLabels[lang] ) {
|
||||
html += WPML_core[ 'templates/taxonomy-translation/not-translated-label.html' ](
|
||||
{
|
||||
taxonomy: taxonomy,
|
||||
lang : lang,
|
||||
langs : TaxonomyTranslation.data.activeLanguages
|
||||
}
|
||||
);
|
||||
} else {
|
||||
if( taxLabels[lang].original ) {
|
||||
html += WPML_core[ 'templates/taxonomy-translation/original-label-disabled.html' ](
|
||||
{
|
||||
lang : lang,
|
||||
langs: TaxonomyTranslation.data.activeLanguages
|
||||
}
|
||||
);
|
||||
} else {
|
||||
html += WPML_core[ 'templates/taxonomy-translation/individual-label.html' ](
|
||||
{
|
||||
taxonomy: taxonomy,
|
||||
lang : lang,
|
||||
langs : TaxonomyTranslation.data.activeLanguages
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
html += '</td>';
|
||||
html += '</tr>';
|
||||
|
||||
self.$el.html( html );
|
||||
|
||||
self.delegateEvents();
|
||||
return self;
|
||||
},
|
||||
openPopUPLabel: function (e) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var link = e.target.closest( '.icl_tt_label' ),
|
||||
id = jQuery( link ).attr( 'id' ),
|
||||
lang = id.split( '_' ).pop();
|
||||
|
||||
if (TaxonomyTranslation.classes.labelPopUpView && typeof TaxonomyTranslation.classes.labelPopUpView !== 'undefined') {
|
||||
TaxonomyTranslation.classes.labelPopUpView.close();
|
||||
}
|
||||
|
||||
TaxonomyTranslation.classes.labelPopUpView = new TaxonomyTranslation.views.LabelPopUpView({model: TaxonomyTranslation.classes.taxonomy}, {
|
||||
lang: lang,
|
||||
defLang: TaxonomyTranslation.classes.taxonomy.get( 'defaultLang' )
|
||||
});
|
||||
TaxonomyTranslation.classes.labelPopUpView.open( lang );
|
||||
},
|
||||
|
||||
changeTaxStringsLanguage: function(e) {
|
||||
var sourceLang = e.target.value;
|
||||
this.$el.find('.js-tax-lang-selector').prepend( '<span class="spinner is-active">' );
|
||||
this.model.changeTaxStringsLanguage(sourceLang);
|
||||
}
|
||||
});
|
||||
}(TaxonomyTranslation));
|
||||
@@ -0,0 +1,73 @@
|
||||
(function () {
|
||||
TaxonomyTranslation.views.NavView = Backbone.View.extend({
|
||||
|
||||
template: WPML_core[ 'templates/taxonomy-translation/nav.html' ],
|
||||
model: TaxonomyTranslation.models.taxonomy,
|
||||
events: {
|
||||
"change .current-page": 'goToPage',
|
||||
"click .next-page": 'nextPage',
|
||||
"click .prev-page": 'prevPage',
|
||||
"click .first-page": 'firstPage',
|
||||
"click .last-page": 'lastPage'
|
||||
},
|
||||
initialize: function (data, options) {
|
||||
this.page = 1;
|
||||
this.perPage = options.perPage;
|
||||
},
|
||||
goToPage: function () {
|
||||
var self = this;
|
||||
var currentPageField = jQuery(".current-page");
|
||||
var page = currentPageField.val();
|
||||
|
||||
if (page > 0 && page <= self.pages) {
|
||||
self.page = parseInt(page);
|
||||
self.trigger("newPage");
|
||||
} else {
|
||||
currentPageField.val(self.page);
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
nextPage: function(){
|
||||
var self = this;
|
||||
self.$el.find('.current-page').val(self.page + 1).change();
|
||||
},
|
||||
prevPage: function(){
|
||||
var self = this;
|
||||
self.$el.find('.current-page').val(self.page - 1).change();
|
||||
},
|
||||
firstPage: function(){
|
||||
var self = this;
|
||||
self.$el.find('.current-page').val(1).change();
|
||||
},
|
||||
lastPage: function(){
|
||||
var self = this;
|
||||
self.$el.find('.current-page').val(self.pages).change();
|
||||
},
|
||||
setCounts: function(){
|
||||
var self = this;
|
||||
var rows = TaxonomyTranslation.data.termRowsCollection.length;
|
||||
var displayedCount = TaxonomyTranslation.mainView.termRowsView.getDisplayCount();
|
||||
rows = displayedCount >= 0 ? displayedCount : rows;
|
||||
rows = rows ? rows : 0;
|
||||
self.rows = rows;
|
||||
self.pages = Math.ceil(rows / self.perPage);
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
self.setCounts();
|
||||
if (self.pages > 1) {
|
||||
self.$el.html(self.template({
|
||||
page: self.page,
|
||||
pages: self.pages,
|
||||
items: self.rows
|
||||
}));
|
||||
self.$el.show();
|
||||
} else {
|
||||
self.$el.hide();
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,11 @@
|
||||
/*globals labels */
|
||||
|
||||
(function () {
|
||||
TaxonomyTranslation.views.OriginalTermPopUpView = TaxonomyTranslation.views.TermPopUpView.extend({
|
||||
|
||||
template: WPML_core[ 'templates/taxonomy-translation/original-term-popup.html' ],
|
||||
getMinDialogWidth: function ( ) {
|
||||
return 400;
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,48 @@
|
||||
/*globals labels */
|
||||
|
||||
(function () {
|
||||
TaxonomyTranslation.views.TableView = Backbone.View.extend({
|
||||
|
||||
template: WPML_core[ 'templates/taxonomy-translation/table.html' ],
|
||||
tag: 'div',
|
||||
termsView: {},
|
||||
|
||||
model: TaxonomyTranslation.models.Taxonomy,
|
||||
|
||||
initialize: function ( data, options ) {
|
||||
this.type = options.type;
|
||||
},
|
||||
|
||||
render: function () {
|
||||
|
||||
if ( ! TaxonomyTranslation.classes.taxonomy.get( "taxonomy" ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var self = this,
|
||||
langs = TaxonomyTranslation.data.activeLanguages,
|
||||
count = self.isTermTable() ? TaxonomyTranslation.data.termRowsCollection.length : 1,
|
||||
tax = self.model.get( 'taxonomy' ),
|
||||
firstColumnHeading = self.isTermTable() ? labels.firstColumnHeading.replace( '%taxonomy%', TaxonomyTranslation.data.taxonomies[ tax ].singularLabel ) : '';
|
||||
|
||||
this.$el.html(self.template({
|
||||
langs: langs,
|
||||
tableType: self.type,
|
||||
count: count,
|
||||
firstColumnHeading: firstColumnHeading,
|
||||
mode: TaxonomyTranslation.mainView.mode
|
||||
}));
|
||||
|
||||
return self;
|
||||
},
|
||||
isTermTable: function () {
|
||||
return this.type === 'terms';
|
||||
},
|
||||
clear: function () {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
/*globals WPML_core, TaxonomyTranslation, Backbone, labels, jQuery, document */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
TaxonomyTranslation.views.TaxonomyView = Backbone.View.extend({
|
||||
|
||||
el: "#taxonomy-translation",
|
||||
model: TaxonomyTranslation.models.Taxonomy,
|
||||
tag: "div",
|
||||
termRowsView: {},
|
||||
mode: 'translate',
|
||||
initialMode: 'translate',
|
||||
perPage: 10,
|
||||
events: {
|
||||
"click #term-table-sync-header": "setToSync",
|
||||
"click #term-table-header": "setToTranslate",
|
||||
"click #tax-apply": "doSync"
|
||||
},
|
||||
syncedLabel: labels.hieraAlreadySynced,
|
||||
initialize: function (model, options) {
|
||||
var self = this;
|
||||
self.perPage = jQuery( '#wpml_tt_taxonomy_translation_wrap' ).data( 'items_per_page' );
|
||||
self.initialMode = options.sync === true ? 'sync' : 'translate';
|
||||
self.navView = new TaxonomyTranslation.views.NavView({model: self.model}, {perPage: self.perPage});
|
||||
self.filterView = new TaxonomyTranslation.views.FilterView({model: self.model});
|
||||
self.listenTo(self.filterView, 'updatedFilter', function () {
|
||||
self.navView.page = 1;
|
||||
self.renderRows();
|
||||
});
|
||||
self.termTableView = new TaxonomyTranslation.views.TableView({model: self.model}, {type: "terms"});
|
||||
self.labelTableView = new TaxonomyTranslation.views.TableView({model: self.model}, {type: "labels"});
|
||||
self.termRowsView = new TaxonomyTranslation.views.TermRowsView({collection: TaxonomyTranslation.data.termRowsCollection}, {
|
||||
start: 0,
|
||||
end: self.perPage
|
||||
});
|
||||
self.listenTo(self.model, 'newTaxonomySet', self.renderNewTaxonomy);
|
||||
self.listenTo(self.model, 'syncDataLoaded', self.renderNewTaxonomy);
|
||||
|
||||
return self;
|
||||
},
|
||||
changeMode: function (mode) {
|
||||
var self = this;
|
||||
self.mode = mode === 'translate' || ( mode === 'sync' && self.model.isHierarchical() ) ? mode : 'translate';
|
||||
self.navView.off();
|
||||
self.navView = new TaxonomyTranslation.views.NavView({model: self.model}, {perPage: self.perPage});
|
||||
self.listenTo(self.navView, 'newPage', self.render);
|
||||
|
||||
if (self.mode === "sync") {
|
||||
self.model.loadSyncData(self.filterView.selectedLang());
|
||||
} else {
|
||||
self.renderRows();
|
||||
self.render();
|
||||
}
|
||||
self.model.trigger('modeChanged');
|
||||
|
||||
self.syncedLabel = labels.hieraAlreadySynced;
|
||||
|
||||
return self;
|
||||
},
|
||||
setToTranslate: function () {
|
||||
var self = this;
|
||||
if (self.mode !== 'translate') {
|
||||
self.changeMode('translate');
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
setToSync: function () {
|
||||
var self = this;
|
||||
if (self.mode !== 'sync') {
|
||||
self.changeMode('sync');
|
||||
TaxonomyTranslation.mainView.showLoadingSpinner();
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
setLabels: function () {
|
||||
var self = this,
|
||||
tax = self.model.get("taxonomy"),
|
||||
taxonomyPluralLabel = TaxonomyTranslation.data.taxonomies[tax].label,
|
||||
taxonomySingularLabel = TaxonomyTranslation.data.taxonomies[tax].singularLabel;
|
||||
|
||||
self.headerTerms = labels.translate.replace( '%taxonomy%', taxonomySingularLabel );
|
||||
self.summaryTerms = labels.summaryTerms.replace( '%taxonomy%', '<strong>' + taxonomyPluralLabel + '</strong>' );
|
||||
self.resultsTruncated = labels.resultsTruncated.replace( '%taxonomy%', '<strong>' + taxonomyPluralLabel + '</strong>' );
|
||||
self.labelSummary = labels.summaryLabels.replace( '%taxonomy%', '<strong>' + taxonomySingularLabel + '</strong>' );
|
||||
|
||||
return self;
|
||||
},
|
||||
renderRows: function () {
|
||||
var self = this;
|
||||
if (TaxonomyTranslation.data.termRowsCollection.length > 0) {
|
||||
self.termRowsView.start = (self.navView.page - 1 ) * self.perPage;
|
||||
self.termRowsView.end = self.termRowsView.start + self.perPage;
|
||||
var termRowsFragment = self.termRowsView.render().el;
|
||||
jQuery("#tax-table-terms").first('tbody').append(termRowsFragment);
|
||||
}
|
||||
self.navView.render();
|
||||
|
||||
return self;
|
||||
},
|
||||
renderNewTaxonomy: function(){
|
||||
var self = this;
|
||||
self.navView.off();
|
||||
self.navView = undefined;
|
||||
self.navView = new TaxonomyTranslation.views.NavView({model: self.model}, {perPage: self.perPage});
|
||||
this.listenTo(this.navView, 'newPage', this.render);
|
||||
self.renderRows();
|
||||
self.render();
|
||||
if (self.initialMode === 'sync') {
|
||||
self.initialMode = false;
|
||||
self.setToSync();
|
||||
}
|
||||
return self;
|
||||
},
|
||||
getMainFragment: function () {
|
||||
var self = this;
|
||||
|
||||
var mainFragment = document.createElement("div"),
|
||||
mainTemplate = WPML_core[ 'templates/taxonomy-translation/taxonomy-main-wrap.html' ],
|
||||
tabsTemplate = WPML_core[ 'templates/taxonomy-translation/tabs.html' ],
|
||||
taxonomy = TaxonomyTranslation.data.taxonomies[ self.model.get( "taxonomy" ) ],
|
||||
htmlTabs = tabsTemplate( {
|
||||
taxonomy: taxonomy,
|
||||
headerTerms: self.headerTerms,
|
||||
syncLabel: labels.Synchronize,
|
||||
mode: self.mode
|
||||
}),
|
||||
hasContent = self.termRowsView && self.termRowsView.getDisplayCount() !== 0,
|
||||
htmlMain = mainTemplate({
|
||||
taxonomy: taxonomy,
|
||||
langs: TaxonomyTranslation.data.activeLanguages,
|
||||
summaryTerms: self.summaryTerms,
|
||||
resultsTruncated: self.resultsTruncated,
|
||||
labelSummary: self.labelSummary,
|
||||
mode: self.mode,
|
||||
hasContent: hasContent,
|
||||
labelSynced: self.syncedLabel
|
||||
});
|
||||
|
||||
mainFragment.innerHTML = htmlTabs + htmlMain;
|
||||
|
||||
mainFragment = self.addMainElements( mainFragment, hasContent );
|
||||
|
||||
return mainFragment;
|
||||
},
|
||||
addMainElements: function ( mainFragment, hasContent ) {
|
||||
var self = this;
|
||||
self.filterFragment = self.filterFragment ? self.filterFragment : self.filterView.render().el;
|
||||
mainFragment.querySelector("#wpml-taxonomy-translation-filters").appendChild(self.filterFragment);
|
||||
if ( hasContent || self.mode === 'translate' ) {
|
||||
var termTableFragment = self.termTableView.render().el;
|
||||
mainFragment.querySelector("#wpml-taxonomy-translation-terms-table").appendChild(termTableFragment);
|
||||
mainFragment = self.addTableRows(mainFragment);
|
||||
}
|
||||
|
||||
var bottomContent = self.model.get( "bottomContent" );
|
||||
if( typeof bottomContent != 'undefined' ){
|
||||
mainFragment.appendChild( jQuery( bottomContent )[0] );
|
||||
}
|
||||
|
||||
return mainFragment;
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
|
||||
self.setLabels();
|
||||
var renderedFragment = document.createDocumentFragment();
|
||||
var mainFragment = self.getMainFragment();
|
||||
renderedFragment.appendChild(mainFragment);
|
||||
|
||||
if (TaxonomyTranslation.data.termRowsCollection.length > self.perPage &&
|
||||
renderedFragment.querySelector("#wpml-taxonomy-translation-terms-nav")) {
|
||||
var navFragment = self.navView.render().el;
|
||||
renderedFragment.querySelector("#wpml-taxonomy-translation-terms-nav").appendChild(navFragment);
|
||||
}
|
||||
self.addLabelTranslation(mainFragment, renderedFragment);
|
||||
self.$el.html(renderedFragment);
|
||||
jQuery(".icl_tt_label").on("click", self.openPopUPLabel);
|
||||
self.showLoadingSpinner( false );
|
||||
self.isRendered = true;
|
||||
self.filterView.delegateEvents();
|
||||
self.delegateEvents();
|
||||
self.maybeHideHeader();
|
||||
jQuery('.icl_tt_main_bottom').show();
|
||||
|
||||
var loading = jQuery( '.wpml-loading-taxonomy' );
|
||||
if ( loading.length ) {
|
||||
loading.hide();
|
||||
var loaded = jQuery( '.wpml_taxonomy_loaded' );
|
||||
if ( loaded.length ) {
|
||||
loaded.show();
|
||||
loaded.parent().children( '.wpml-loading-taxonomy' ).remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
addLabelTranslation: function (mainFragment, renderedFragment) {
|
||||
var self = this;
|
||||
|
||||
if (TaxonomyTranslation.data.translatedTaxonomyLabels && self.mode !== 'sync') {
|
||||
var labelTableFragment = self.labelTableView.render().el;
|
||||
mainFragment.querySelector("#wpml-taxonomy-translation-labels-table").appendChild(labelTableFragment);
|
||||
if (renderedFragment.querySelector("#tax-table-labels")) {
|
||||
var labelRowFragment = new TaxonomyTranslation.views.LabelRowView(({model: self.model})).render().el;
|
||||
mainFragment.querySelector("#tax-table-labels").appendChild(labelRowFragment);
|
||||
}
|
||||
}
|
||||
|
||||
return mainFragment;
|
||||
},
|
||||
addTableRows: function (mainFragment) {
|
||||
var self = this;
|
||||
var termRowsFragment;
|
||||
|
||||
self.termRowsView.start = (self.navView.page - 1 ) * self.perPage;
|
||||
self.termRowsView.end = self.termRowsView.start + self.perPage;
|
||||
termRowsFragment = self.termRowsView.render().el;
|
||||
mainFragment.querySelector("#tax-table-terms").appendChild(termRowsFragment);
|
||||
|
||||
return mainFragment;
|
||||
},
|
||||
/**
|
||||
* Used by WCML to hide the controls for changing the taxonomy
|
||||
*/
|
||||
maybeHideHeader: function () {
|
||||
var taxonomySwitcher = jQuery("#icl_tt_tax_switch");
|
||||
var potentialHiddenSelectInput = jQuery('#tax-selector-hidden');
|
||||
var potentialHiddenTaxInput = jQuery('#tax-preselected');
|
||||
if (potentialHiddenSelectInput.length !== 0 &&
|
||||
potentialHiddenSelectInput.val() &&
|
||||
potentialHiddenTaxInput.length !== 0 &&
|
||||
potentialHiddenTaxInput.val()) {
|
||||
taxonomySwitcher.closest('label').hide();
|
||||
jQuery('[id="term-table-summary"]').hide();
|
||||
}
|
||||
},
|
||||
selectTaxonomy: function () {
|
||||
var self = this,
|
||||
tax = jQuery("#icl_tt_tax_switch").val();
|
||||
|
||||
if (tax !== undefined) {
|
||||
self.mode = 'translate';
|
||||
self.model.setTaxonomy(tax);
|
||||
}
|
||||
},
|
||||
doSync: function () {
|
||||
var self = this;
|
||||
|
||||
self.$el.find( '#tax-apply' ).prop( 'disabled', true );
|
||||
TaxonomyTranslation.mainView.model.doSync( self.$el.find("#in-lang").val() );
|
||||
self.syncedLabel = labels.hieraSynced;
|
||||
},
|
||||
showLoadingSpinner: function( state ) {
|
||||
if ( state === undefined || state ) {
|
||||
jQuery('.wpml-loading-taxonomy').show();
|
||||
} else {
|
||||
jQuery('.wpml-loading-taxonomy').hide();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,30 @@
|
||||
/*globals labels */
|
||||
|
||||
(function () {
|
||||
|
||||
TaxonomyTranslation.views.TermOriginalView = TaxonomyTranslation.views.TermView.extend({
|
||||
|
||||
tagName: "td",
|
||||
className: "wpml-col-title wpml-col-title-flag",
|
||||
template: WPML_core[ 'templates/taxonomy-translation/original-term.html' ],
|
||||
render: function () {
|
||||
var self = this;
|
||||
|
||||
self.needsCorrection = false;
|
||||
|
||||
self.$el.html(
|
||||
self.template({
|
||||
trid: self.model.get("trid"),
|
||||
lang: self.model.get("language_code"),
|
||||
name: self.model.get("name"),
|
||||
level: self.model.get("level"),
|
||||
correctedLevel: self.model.get("level"),
|
||||
langs: TaxonomyTranslation.data.activeLanguages
|
||||
})
|
||||
);
|
||||
|
||||
self.delegateEvents();
|
||||
return self;
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,156 @@
|
||||
/*globals labels */
|
||||
|
||||
(function () {
|
||||
TaxonomyTranslation.views.TermPopUpView = Backbone.View.extend({
|
||||
|
||||
tagName: 'div',
|
||||
template: WPML_core[ 'templates/taxonomy-translation/term-popup.html' ],
|
||||
model: TaxonomyTranslation.models.Term,
|
||||
|
||||
events: {
|
||||
'click .cancel': 'close',
|
||||
'click .term-save': 'saveTerm',
|
||||
'click .js-button-copy': 'copyOriginal',
|
||||
'keydown': 'handleEnter',
|
||||
'input #term-name': 'updateUI',
|
||||
'focusout input#term-name': 'generateSlug'
|
||||
},
|
||||
initialize: function () {
|
||||
var self = this;
|
||||
self.listenTo(self.model, 'translationSaved', self.close);
|
||||
self.listenTo(self.model, 'saveFailed', self.render);
|
||||
self.dialog = null;
|
||||
return self;
|
||||
},
|
||||
|
||||
render: function () {
|
||||
|
||||
var self = this,
|
||||
trid = self.model.get('trid'),
|
||||
term = self.model.getNameSlugAndDescription(),
|
||||
term_meta = self.model.getMetaData(),
|
||||
original_term_meta = TaxonomyTranslation.classes.taxonomy.getOriginalTermMeta( trid ),
|
||||
original_term = TaxonomyTranslation.classes.taxonomy.getOriginalTerm( trid );
|
||||
|
||||
self.$el.html(
|
||||
this.template({
|
||||
trid: trid,
|
||||
lang: self.model.get('language_code'),
|
||||
source_lang: original_term.get( 'language_code' ),
|
||||
langs: TaxonomyTranslation.data.activeLanguages,
|
||||
ttid: self.model.get('term_taxonomy_id'),
|
||||
term: term,
|
||||
original_term: original_term.getNameSlugAndDescription(),
|
||||
term_meta: term_meta,
|
||||
original_term_meta: original_term_meta
|
||||
})
|
||||
);
|
||||
|
||||
self.delegateEvents();
|
||||
return self;
|
||||
},
|
||||
handleEnter: function (e) {
|
||||
var self = this;
|
||||
if (self.$el.find('input:focus').length !== 0 && e.keyCode == 13) {
|
||||
self.saveTerm(e);
|
||||
}
|
||||
return self;
|
||||
},
|
||||
saveTerm: function (e) {
|
||||
var self = this,
|
||||
meta_data = {};
|
||||
|
||||
self.undelegateEvents();
|
||||
|
||||
e.preventDefault();
|
||||
var name = self.$el.find('#term-name').val(),
|
||||
slug = self.$el.find('#term-slug').val(),
|
||||
description = self.$el.find('#term-description').val();
|
||||
|
||||
|
||||
var term_metas = self.$el.find('.term-meta');
|
||||
_.each( term_metas, function ( meta_object ) {
|
||||
meta_data[ meta_object.dataset.metaKey ] = meta_object.value;
|
||||
});
|
||||
|
||||
if (name) {
|
||||
self.$el.find('.spinner').show();
|
||||
self.$el.find('.term-save').prop( 'disabled', true );
|
||||
self.$el.find('.cancel').prop( 'disabled', true );
|
||||
self.model.save(name, slug, description, meta_data);
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
open: function ( trid, lang ) {
|
||||
var self = this;
|
||||
self.render();
|
||||
var popUpDomEl = jQuery('#' + trid + '-popup-' + lang);
|
||||
popUpDomEl.append( self.$el );
|
||||
|
||||
self.dialog = jQuery( '#icl_tt_form_' + trid + '_' + lang );
|
||||
self.dialog.dialog({
|
||||
autoOpen: true,
|
||||
modal: true,
|
||||
minWidth: self.getMinDialogWidth(),
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
dialogClass: 'dialog-fixed otgs-ui-dialog'
|
||||
});
|
||||
self.setElement( self.dialog );
|
||||
self.delegateEvents();
|
||||
self.updateUI();
|
||||
|
||||
},
|
||||
getMinDialogWidth: function ( ) {
|
||||
return 800;
|
||||
},
|
||||
close: function () {
|
||||
if ( this.dialog ) {
|
||||
this.dialog.dialog( 'close' );
|
||||
this.undelegateEvents();
|
||||
this.remove();
|
||||
this.dialog = null;
|
||||
}
|
||||
},
|
||||
copyOriginal: function ( e ) {
|
||||
var self = this,
|
||||
original = jQuery( e.currentTarget ).prev().val();
|
||||
jQuery( e.currentTarget ).next().val( original );
|
||||
self.generateSlug();
|
||||
self.updateUI();
|
||||
},
|
||||
updateUI: function ( ) {
|
||||
var self = this;
|
||||
self.$el.find( '.term-save' ).prop( 'disabled', self.$el.find( '#term-name').val() === '' );
|
||||
},
|
||||
generateSlug: function() {
|
||||
var self = this,
|
||||
term_slug = self.$el.find( '#term-slug' ),
|
||||
term_name = self.$el.find( '#term-name' );
|
||||
if ('' === term_slug.val() && '' !== term_name.val()) {
|
||||
term_slug.prop('disabled', true);
|
||||
term_slug.css('background', 'url(' + window.icl_ajxloaderimg_src + ') no-repeat left center');
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: {
|
||||
action: 'wpml_generate_term_slug',
|
||||
term: term_name.val(),
|
||||
nonce: labels.wpml_generate_unique_slug_nonce,
|
||||
language_code: self.model.get('language_code'),
|
||||
taxonomy: TaxonomyTranslation.classes.taxonomy.get("taxonomy"),
|
||||
},
|
||||
success: function(response) {
|
||||
if( true === response.success ) {
|
||||
term_slug.val( response.data.slug );
|
||||
}
|
||||
term_slug.prop('disabled', false);
|
||||
term_slug.css('background', '');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,100 @@
|
||||
/*globals _, TaxonomyTranslation, document, Backbone, jQuery */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
TaxonomyTranslation.views.TermRowView = Backbone.View.extend({
|
||||
|
||||
tagName: "tr",
|
||||
model: TaxonomyTranslation.models.TermRow,
|
||||
termViews: {},
|
||||
className: '',
|
||||
events: {
|
||||
'click .js-copy-to-all-langs': 'copyToAllLangs'
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
var self = this;
|
||||
|
||||
self.listenTo(TaxonomyTranslation.classes.taxonomy, 'syncDataLoaded', self.maybeHide);
|
||||
},
|
||||
maybeHide: function () {
|
||||
var self = this;
|
||||
var visible = false;
|
||||
var terms = self.model.get("terms");
|
||||
_.each(TaxonomyTranslation.data.syncData, function (correction) {
|
||||
_.each(terms, function (term) {
|
||||
if (correction.translated_id == term.get("term_taxonomy_id")) {
|
||||
visible = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
if (visible) {
|
||||
self.$el.show();
|
||||
} else {
|
||||
self.$el.hide();
|
||||
}
|
||||
},
|
||||
|
||||
render: function () {
|
||||
var termsFragments = {};
|
||||
var self = this;
|
||||
var langs = TaxonomyTranslation.util.langCodes;
|
||||
var terms = self.model.get("terms");
|
||||
var originalTerm = null;
|
||||
|
||||
_.each(langs, function (lang) {
|
||||
var term = terms[lang];
|
||||
if (term === undefined) {
|
||||
term = new TaxonomyTranslation.models.Term({language_code: lang, trid: self.model.get("trid")});
|
||||
terms[lang] = term;
|
||||
self.model.set("terms", terms, {silent: true});
|
||||
}
|
||||
if ( term.isOriginal() ) {
|
||||
originalTerm = term;
|
||||
}
|
||||
var newView = new TaxonomyTranslation.views.TermView({model: term});
|
||||
self.termViews[lang] = newView;
|
||||
if (TaxonomyTranslation.mainView.mode === 'sync') {
|
||||
termsFragments[lang] = newView.loadSyncData().el;
|
||||
} else {
|
||||
termsFragments[lang] = newView.render().el;
|
||||
}
|
||||
});
|
||||
|
||||
if ( originalTerm ) {
|
||||
var newRowFragment = document.createDocumentFragment();
|
||||
|
||||
if ( TaxonomyTranslation.mainView.mode !== 'sync' ) {
|
||||
var originalView = new TaxonomyTranslation.views.TermOriginalView({model: originalTerm });
|
||||
newRowFragment.appendChild( originalView.render().el );
|
||||
|
||||
var newRowLangs = document.createElement( 'td' );
|
||||
jQuery( newRowLangs ).addClass( 'wpml-col-languages' );
|
||||
_.each(langs, function(lang){
|
||||
newRowLangs.appendChild(termsFragments[lang]);
|
||||
});
|
||||
|
||||
newRowFragment.appendChild( newRowLangs );
|
||||
} else {
|
||||
_.each(langs, function(lang){
|
||||
var newRowTD = document.createElement( 'td' );
|
||||
newRowTD.appendChild(termsFragments[lang]);
|
||||
newRowFragment.appendChild( newRowTD );
|
||||
});
|
||||
}
|
||||
self.$el.html(newRowFragment);
|
||||
}
|
||||
|
||||
return self;
|
||||
|
||||
},
|
||||
copyToAllLangs: function () {
|
||||
var self = this;
|
||||
TaxonomyTranslation.classes.copyAllPopUpView = new TaxonomyTranslation.views.CopyAllPopUpView( { model: self.model } );
|
||||
TaxonomyTranslation.classes.copyAllPopUpView.open( );
|
||||
|
||||
}
|
||||
});
|
||||
}(TaxonomyTranslation));
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
(function () {
|
||||
TaxonomyTranslation.views.TermRowsView = Backbone.View.extend({
|
||||
|
||||
tagName: 'tbody',
|
||||
collection: TaxonomyTranslation.data.termRowsCollection,
|
||||
rowViews: [],
|
||||
start: 0,
|
||||
end: 10,
|
||||
count: -1,
|
||||
initialize: function (data, options) {
|
||||
var self = this;
|
||||
self.end = options.end;
|
||||
self.start = options.start;
|
||||
},
|
||||
getDisplayedRows: function () {
|
||||
var self = this;
|
||||
var displayedRows = self.collection;
|
||||
|
||||
if (!displayedRows) {
|
||||
self.count = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TaxonomyTranslation.mainView.mode === 'sync') {
|
||||
displayedRows = displayedRows.filter(function (row) {
|
||||
"use strict";
|
||||
return row.unSyncFilter();
|
||||
});
|
||||
}
|
||||
|
||||
var parentFilter = TaxonomyTranslation.mainView.filterView.parent ? TaxonomyTranslation.mainView.filterView.parent : false;
|
||||
|
||||
if (parentFilter) {
|
||||
displayedRows = displayedRows.filter(function (row) {
|
||||
return row.parentOf(parentFilter);
|
||||
});
|
||||
}
|
||||
|
||||
var untranslatedFilter = TaxonomyTranslation.mainView.filterView.untranslated ? TaxonomyTranslation.mainView.filterView.untranslated : false;
|
||||
|
||||
if (untranslatedFilter) {
|
||||
displayedRows = displayedRows.filter(function (row) {
|
||||
return !row.allTermsTranslated();
|
||||
});
|
||||
}
|
||||
|
||||
var langFilter = TaxonomyTranslation.mainView.filterView.lang && TaxonomyTranslation.mainView.filterView.lang !== 'all' ? TaxonomyTranslation.mainView.filterView.lang : false;
|
||||
|
||||
if (langFilter && langFilter != 'all' && (untranslatedFilter || parentFilter)) {
|
||||
displayedRows = displayedRows.filter(function (row) {
|
||||
return !row.translatedIn(langFilter);
|
||||
});
|
||||
}
|
||||
|
||||
var searchFilter = false;
|
||||
|
||||
if (TaxonomyTranslation.mainView.filterView.search && TaxonomyTranslation.mainView.filterView.search !== '') {
|
||||
searchFilter = TaxonomyTranslation.mainView.filterView.search;
|
||||
}
|
||||
|
||||
if (searchFilter) {
|
||||
displayedRows = displayedRows.filter(function (row) {
|
||||
if (langFilter && langFilter !== 'all') {
|
||||
return row.matchesInLang(searchFilter, langFilter);
|
||||
} else {
|
||||
return row.matches(searchFilter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
self.count = displayedRows.length;
|
||||
|
||||
return displayedRows;
|
||||
},
|
||||
getDisplayCount: function(){
|
||||
return this.count;
|
||||
},
|
||||
render: function () {
|
||||
|
||||
var self = this,
|
||||
output = document.createDocumentFragment(),
|
||||
displayedRows = self.getDisplayedRows();
|
||||
|
||||
self.rowViews = [];
|
||||
|
||||
if ( displayedRows && displayedRows.length > 0 ) {
|
||||
displayedRows = displayedRows.slice(self.start, self.end);
|
||||
|
||||
displayedRows.forEach(function (row) {
|
||||
var newView = new TaxonomyTranslation.views.TermRowView({model: row });
|
||||
self.rowViews.push(newView);
|
||||
output.appendChild(newView.render().el);
|
||||
newView.delegateEvents();
|
||||
|
||||
});
|
||||
self.$el.html(output);
|
||||
} else {
|
||||
var taxonomy = TaxonomyTranslation.classes.taxonomy.get("taxonomy"),
|
||||
taxonomyPluralLabel = TaxonomyTranslation.data.taxonomies[taxonomy].label,
|
||||
message = labels.noTermsFound.replace( '%taxonomy%', taxonomyPluralLabel );
|
||||
|
||||
self.$el.html(
|
||||
WPML_core[ 'templates/taxonomy-translation/no-terms-found.html' ] ({
|
||||
message: message
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return self;
|
||||
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,119 @@
|
||||
/*globals labels, TaxonomyTranslation, _, jQuery, WPML_core */
|
||||
|
||||
(function () {
|
||||
|
||||
TaxonomyTranslation.views.TermView = Backbone.View.extend({
|
||||
|
||||
tagName: 'span',
|
||||
template: WPML_core[ "templates/taxonomy-translation/term-translated.html" ],
|
||||
model: TaxonomyTranslation.models.Term,
|
||||
popUpView: false,
|
||||
needsCorrection: false,
|
||||
events: {
|
||||
"click .icl_tt_term_name": "openPopUpTerm"
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
var self = this;
|
||||
self.listenTo(self.model, 'translationSaved', self.render);
|
||||
self.listenTo(self.model, 'translationSaved', function () {
|
||||
jQuery('#tax-apply').prop('disabled', false);
|
||||
});
|
||||
},
|
||||
loadSyncData: function () {
|
||||
"use strict";
|
||||
var self = this;
|
||||
|
||||
var syncData = TaxonomyTranslation.data.syncData;
|
||||
var ttid = self.model.get('term_taxonomy_id');
|
||||
var parent = self.model.get('parent');
|
||||
var found = false;
|
||||
var needsCorrection = false;
|
||||
var correctParentText = false;
|
||||
var parentName = TaxonomyTranslation.classes.taxonomy.getTermName(parent);
|
||||
_.each(syncData, function (correction) {
|
||||
if (correction.translated_id == ttid) {
|
||||
found = true;
|
||||
|
||||
var oldParent = '';
|
||||
if (parent !== 0) {
|
||||
oldParent = '<span style="background-color:#F55959;">-' + TaxonomyTranslation.classes.taxonomy.getTermName(parent) + '</span>';
|
||||
jQuery('.wpml-parent-removed').show();
|
||||
}
|
||||
var newParent = '';
|
||||
if (correction.correct_parent !== 0) {
|
||||
newParent = '<span style="background-color:#CCFF99;">+' + TaxonomyTranslation.classes.taxonomy.getTermName(correction.correct_parent) + '</span>';
|
||||
jQuery('.wpml-parent-added').show();
|
||||
}
|
||||
parentName = oldParent + ' ' + newParent;
|
||||
needsCorrection = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (needsCorrection === true) {
|
||||
self.template = WPML_core[ 'templates/taxonomy-translation/term-not-synced.html' ];
|
||||
} else {
|
||||
self.template = WPML_core[ 'templates/taxonomy-translation/term-synced.html' ];
|
||||
}
|
||||
|
||||
self.$el.html(
|
||||
self.template({
|
||||
trid: self.model.get("trid"),
|
||||
lang: self.model.get("language_code"),
|
||||
name: self.model.get("name"),
|
||||
level: self.model.get("level"),
|
||||
correctedLevel: self.model.get("level"),
|
||||
correctParent: correctParentText,
|
||||
parent: parentName
|
||||
})
|
||||
);
|
||||
|
||||
self.needsCorrection = needsCorrection;
|
||||
|
||||
return self;
|
||||
},
|
||||
|
||||
render: function () {
|
||||
var self = this;
|
||||
|
||||
self.needsCorrection = false;
|
||||
if ( ! self.model.get( "name" ) ) {
|
||||
self.template = WPML_core[ "templates/taxonomy-translation/term-not-translated.html" ];
|
||||
} else if ( self.model.isOriginal() ) {
|
||||
self.template = WPML_core[ "templates/taxonomy-translation/term-original-disabled.html" ];
|
||||
} else {
|
||||
self.template = WPML_core[ "templates/taxonomy-translation/term-translated.html" ];
|
||||
}
|
||||
|
||||
var html = self.template({
|
||||
trid: self.model.get("trid"),
|
||||
lang: self.model.get("language_code"),
|
||||
name: self.model.get("name"),
|
||||
level: self.model.get("level"),
|
||||
correctedLevel: self.model.get("level"),
|
||||
langs: TaxonomyTranslation.data.activeLanguages
|
||||
});
|
||||
self.$el.html( html );
|
||||
|
||||
return self;
|
||||
},
|
||||
openPopUpTerm: function (e) {
|
||||
var self = this;
|
||||
|
||||
e.preventDefault();
|
||||
var trid = self.model.get("trid");
|
||||
var lang = self.model.get("language_code");
|
||||
if (trid && lang) {
|
||||
if (TaxonomyTranslation.classes.termPopUpView && typeof TaxonomyTranslation.classes.termPopUpView !== 'undefined') {
|
||||
TaxonomyTranslation.classes.termPopUpView.close();
|
||||
}
|
||||
if ( self.model.isOriginal() ) {
|
||||
TaxonomyTranslation.classes.termPopUpView = new TaxonomyTranslation.views.OriginalTermPopUpView( { model: self.model } );
|
||||
} else {
|
||||
TaxonomyTranslation.classes.termPopUpView = new TaxonomyTranslation.views.TermPopUpView( { model: self.model } );
|
||||
}
|
||||
TaxonomyTranslation.classes.termPopUpView.open( trid, lang );
|
||||
}
|
||||
}
|
||||
});
|
||||
})(TaxonomyTranslation);
|
||||
@@ -0,0 +1,60 @@
|
||||
var WPML_Core = WPML_Core || {};
|
||||
WPML_Core.theme_localization = {};
|
||||
|
||||
addLoadEvent(function(){
|
||||
jQuery('#icl_theme_localization').submit(iclSaveThemeLocalization);
|
||||
jQuery('#icl_theme_localization_type').submit(iclSaveThemeLocalizationType);
|
||||
|
||||
jQuery(document).on('change', '.check-column-plugin :checkbox', function () {
|
||||
WPML_Core.theme_localization.check_column( 'plugins', jQuery(this).prop('checked') );
|
||||
});
|
||||
jQuery(document).on('change', '.check-column-theme :checkbox', function () {
|
||||
WPML_Core.theme_localization.check_column( 'themes', jQuery(this).prop('checked') );
|
||||
});
|
||||
});
|
||||
|
||||
function iclSaveThemeLocalization(){
|
||||
var spl = jQuery(this).serialize().split('&');
|
||||
var parameters = {};
|
||||
for(var i=0; i< spl.length; i++){
|
||||
var par = spl[i].split('=');
|
||||
parameters[par[0]] = par[1];
|
||||
}
|
||||
jQuery('#icl_theme_localization_wrap').load(WPML_core.sanitize(location.href) + ' #icl_theme_localization_subwrap', parameters, function(){
|
||||
fadeInAjxResp('#icl_ajx_response_fn', icl_ajx_saved);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function iclSaveThemeLocalizationType(){
|
||||
jQuery(this).find('.icl_form_errors').fadeOut();
|
||||
var val = jQuery(this).find('[name="icl_theme_localization_type"]:checked').val();
|
||||
var td_on = jQuery(this).find('[name="icl_theme_localization_load_td"]').prop('checked');
|
||||
var td_value = jQuery(this).find('[name="textdomain_value"]').val();
|
||||
|
||||
if(val == 2 && td_on && !td_value.trim()){
|
||||
jQuery(this).find('.icl_form_errors_1').fadeIn();
|
||||
return false;
|
||||
}
|
||||
|
||||
var data = jQuery(this).serializeArray();
|
||||
data.push({
|
||||
'name': 'action',
|
||||
'value' : 'WPML_Theme_Localization_Type'
|
||||
});
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: data,
|
||||
success: function(){
|
||||
location.href = WPML_core.sanitize(location.href).replace(/#(.*)$/,'');
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
WPML_Core.theme_localization.check_column = function(type, checked){
|
||||
var visible_rows = jQuery('#wpml_strings_in_' + type).find(':checkbox:visible');
|
||||
visible_rows.prop('checked', checked);
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
/* globals icl_ajx_saved, icl_ajx_error, ajaxurl */
|
||||
|
||||
jQuery(function($){
|
||||
|
||||
'use strict';
|
||||
|
||||
$(function () {
|
||||
var ajax_success_action = function (response, response_text) {
|
||||
|
||||
if (response.success) {
|
||||
response_text.text(icl_ajx_saved);
|
||||
} else {
|
||||
response_text.text(icl_ajx_error);
|
||||
}
|
||||
|
||||
response_text.show();
|
||||
|
||||
setTimeout(function () {
|
||||
response_text.fadeOut('slow');
|
||||
}, 2500);
|
||||
};
|
||||
|
||||
$( '#wpml-js-theme-plugin-save-option' ).click(function(){
|
||||
|
||||
var alert_scan_new_strings = $( 'input[name*="wpml_st_display_strings_scan_notices"]' ),
|
||||
use_theme_plugin_domain = $( 'input[name*="use_theme_plugin_domain"]' ),
|
||||
theme_localization_load_textdomain = $( 'input[name*="theme_localization_load_textdomain"]' ),
|
||||
gettext_theme_domain_name = $( 'input[name*="gettext_theme_domain_name"]' ),
|
||||
response_text = $( '#wpml-js-theme-plugin-options-response' ),
|
||||
spinner = $( '#wpml-js-theme-plugin-options-spinner' );
|
||||
|
||||
spinner.addClass( 'is-active' );
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpml_update_localization_options',
|
||||
nonce: $( '#wpml-localization-options-nonce' ).val(),
|
||||
wpml_st_display_strings_scan_notices: alert_scan_new_strings.is(':checked') ? alert_scan_new_strings.val() : 0,
|
||||
use_theme_plugin_domain: use_theme_plugin_domain.is(':checked') ? use_theme_plugin_domain.val() : 0,
|
||||
theme_localization_load_textdomain: theme_localization_load_textdomain.is(':checked') ? theme_localization_load_textdomain.val() : 0,
|
||||
gettext_theme_domain_name: gettext_theme_domain_name.val()
|
||||
|
||||
},
|
||||
success: function ( response ) {
|
||||
spinner.removeClass( 'is-active' );
|
||||
ajax_success_action( response, response_text );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#theme_localization_load_textdomain').on('change', function() {
|
||||
$('input[name="gettext_theme_domain_name"]').prop('disabled', !$(this).is(':checked'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,353 @@
|
||||
/*global wpml_tm_strings, jQuery, Backbone, icl_ajxloaderimg, ajaxurl, ProgressBar */
|
||||
/*jslint laxbreak: true */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
WPML_TM.Dashboard = Backbone.View.extend({
|
||||
events: {
|
||||
'click td[scope="row"] :checkbox': 'update_td',
|
||||
"click td.check-column :checkbox": 'icl_tm_select_all_documents',
|
||||
"change #icl_tm_languages :radio": 'change_radio',
|
||||
"change #parent-filter-control": 'populate_parent_list',
|
||||
"change #icl_language_selector": 'populate_parent_list',
|
||||
"click #duplicate-all": 'icl_tm_bulk_batch_selection',
|
||||
"click #translate-all": 'icl_tm_bulk_batch_selection',
|
||||
"click #update-none": 'icl_tm_bulk_batch_selection',
|
||||
"submit #icl_tm_dashboard_form": 'submit',
|
||||
"change #filter_type": 'show_hide_parent_controls'
|
||||
},
|
||||
counts: {
|
||||
all: 0,
|
||||
duplicate: 0,
|
||||
translate: 0
|
||||
},
|
||||
init: function ( $ ) {
|
||||
var self = this;
|
||||
self.$ = $;
|
||||
self.counts.all = self.setElement( '.icl_tm_wrap' );
|
||||
self.change_radio();
|
||||
self.show_hide_parent_controls();
|
||||
},
|
||||
submit: function (e) {
|
||||
var self = this;
|
||||
self.recount();
|
||||
if (self.counts.duplicate > 0) {
|
||||
e.preventDefault();
|
||||
var post_ids = [];
|
||||
var langs = [];
|
||||
var radios = jQuery('#icl_tm_languages').find('tbody').find(':radio:checked').filter('[value=2]');
|
||||
radios.each(function () {
|
||||
langs.push(jQuery(this).attr('name').replace('tr_action[', '').replace(']', ''));
|
||||
});
|
||||
|
||||
var languagesCount = langs.length;
|
||||
if (0 < languagesCount) {
|
||||
var post_id_boxes = self.$el.find('#icl-tm-translation-dashboard tbody td :checkbox:checked');
|
||||
var post_ids_count = post_id_boxes.length;
|
||||
|
||||
for (var p = 0; p < post_ids_count; p++) {
|
||||
for (var l = 0; l < languagesCount; l++) {
|
||||
post_ids.push({
|
||||
postId: jQuery(post_id_boxes[p]).val(),
|
||||
languageCode: langs[l]
|
||||
});
|
||||
}
|
||||
}
|
||||
var duplication_ui = new PostDuplication(post_ids, jQuery('#icl_dup_ovr_warn'));
|
||||
duplication_ui.sendBatch();
|
||||
}
|
||||
}
|
||||
},
|
||||
iclTmUpdateDashboardSelection: function () {
|
||||
var self = this;
|
||||
if (self.$el.find(':checkbox:checked').length > 0) {
|
||||
var checked_items = self.$el.find('td.check-column :checkbox');
|
||||
if (self.$el.find('td[scope="row"] :checkbox:checked').length === self.$el.find('td[scope="row"] :checkbox').length) {
|
||||
checked_items.prop('checked', true);
|
||||
} else {
|
||||
checked_items.prop('checked', false);
|
||||
}
|
||||
}
|
||||
},
|
||||
recount: function(){
|
||||
var self = this;
|
||||
var radios = jQuery('#icl_tm_languages').find('tbody').find(':radio:checked');
|
||||
self.counts.duplicate = radios.filter('[value=2]').length;
|
||||
self.counts.translate = radios.filter('[value=1]').length;
|
||||
self.counts.all = radios.length;
|
||||
|
||||
return self;
|
||||
},
|
||||
change_radio: function () {
|
||||
var bulk_select_radio, bulk_select_val, self;
|
||||
self = this;
|
||||
self.recount();
|
||||
self.icl_tm_enable_submit();
|
||||
self.icl_tm_dup_warn();
|
||||
bulk_select_val = self.counts.duplicate === self.counts.all ? "2" : false;
|
||||
bulk_select_val = self.counts.translate === self.counts.all ? "1" : bulk_select_val;
|
||||
bulk_select_val = self.counts.translate === 0 && self.counts.duplicate === 0 ? "0" : bulk_select_val;
|
||||
bulk_select_radio = bulk_select_val !== false
|
||||
? self.$el.find('[name="radio-action-all"]').filter('[value=' + bulk_select_val + ']')
|
||||
: self.$el.find('[name="radio-action-all"]');
|
||||
bulk_select_radio.prop('checked', !!bulk_select_val);
|
||||
},
|
||||
update_td: function () {
|
||||
var self = this;
|
||||
self.icl_tm_update_word_count_estimate();
|
||||
self.iclTmUpdateDashboardSelection();
|
||||
},
|
||||
icl_tm_select_all_documents: function(e) {
|
||||
var self = this;
|
||||
self.$el.find('#icl-tm-translation-dashboard').
|
||||
find(':checkbox:not(:disabled)').
|
||||
prop('checked', !!jQuery(e.target).prop('checked'));
|
||||
self.icl_tm_update_word_count_estimate();
|
||||
self.icl_tm_update_doc_count();
|
||||
self.icl_tm_enable_submit();
|
||||
},
|
||||
icl_tm_update_word_count_estimate: function () {
|
||||
var self = this;
|
||||
self.icl_tm_enable_submit();
|
||||
var element_rows = self.$el.find('tbody').find('tr');
|
||||
var current_overall_word_count = 0;
|
||||
var icl_tm_estimated_words_count = jQuery('#icl-tm-estimated-words-count');
|
||||
jQuery.each(element_rows, function () {
|
||||
var row = jQuery(this);
|
||||
if (row.find(':checkbox').prop('checked')) {
|
||||
var item_word_count = row.data('word_count');
|
||||
var val = parseInt(item_word_count);
|
||||
val = isNaN(val) ? 0 : val;
|
||||
current_overall_word_count += val;
|
||||
}
|
||||
});
|
||||
icl_tm_estimated_words_count.html(current_overall_word_count);
|
||||
self.icl_tm_update_doc_count();
|
||||
},
|
||||
|
||||
populate_parent_list: function () {
|
||||
var self = this,
|
||||
parent_select = self.$( '#parent-filter-control' ),
|
||||
parent_taxonomy_item_container = self.$( '[name="parent-taxonomy-item-container"]' ),
|
||||
val = parent_select.val();
|
||||
|
||||
if ( val ) {
|
||||
parent_taxonomy_item_container.hide();
|
||||
if ( val != 'any' ) {
|
||||
var ajax_loader = self.$( '<span class="spinner"></span>' );
|
||||
ajax_loader.insertBefore( parent_taxonomy_item_container ).css( {
|
||||
visibility: "visible",
|
||||
float: "none"
|
||||
} );
|
||||
self.$.ajax( {
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'icl_tm_parent_filter',
|
||||
type: val,
|
||||
from_lang: self.$( 'select[name="filter[from_lang]"]' ).val(),
|
||||
parent_id: self.$( '[name="filter[parent_id]"]' ).val()
|
||||
},
|
||||
success: function ( response ) {
|
||||
parent_taxonomy_item_container.html( response.data.html );
|
||||
parent_taxonomy_item_container.show();
|
||||
ajax_loader.remove();
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
show_hide_parent_controls: function (e) {
|
||||
var self = this,
|
||||
selected_option = self.$( '#filter_type option:selected' ),
|
||||
parent_data = selected_option.data( 'parent' ),
|
||||
taxonomy_data = selected_option.data( 'taxonomy' );
|
||||
|
||||
if ( parent_data || taxonomy_data ) {
|
||||
self.$( '#parent-taxonomy-container' ).show();
|
||||
self.fill_parent_type_select( parent_data, taxonomy_data );
|
||||
self.populate_parent_list();
|
||||
} else {
|
||||
self.$( '#parent-taxonomy-container' ).hide();
|
||||
}
|
||||
},
|
||||
|
||||
fill_parent_type_select: function ( parent_data, taxonomy_data ) {
|
||||
var self = this,
|
||||
parent_select = self.$( '#parent-filter-control' );
|
||||
|
||||
parent_select.find( 'option' ).remove();
|
||||
|
||||
parent_select.append( '<option value="any">' + wpml_tm_strings.any + '</option>' );
|
||||
|
||||
if ( parent_data ) {
|
||||
parent_select.append( '<option value="page">' + wpml_tm_strings.post_parent + '</option>' );
|
||||
}
|
||||
if ( taxonomy_data ) {
|
||||
taxonomy_data = taxonomy_data.split( ',' );
|
||||
for ( var i = 0; i < taxonomy_data.length; i++ ) {
|
||||
var parts = taxonomy_data[i].split( '=' );
|
||||
parent_select.append( '<option value="' + parts[0] + '">' + parts[1] + '</option>' );
|
||||
}
|
||||
}
|
||||
parent_select.val( parent_select.data( 'original' ) );
|
||||
parent_select.data( 'original', '' );
|
||||
if ( ! parent_select.val() ) {
|
||||
parent_select.val( 'any' );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
icl_update_button_label: function (dupl_count, trans_count) {
|
||||
var button_label;
|
||||
if (dupl_count > 0 && trans_count === 0) {
|
||||
button_label = wpml_tm_strings.BB_duplicate_all;
|
||||
} else if (dupl_count > 0 && trans_count > 0) {
|
||||
button_label = wpml_tm_strings.BB_mixed_actions;
|
||||
} else if (dupl_count === 0 && trans_count > 0) {
|
||||
button_label = wpml_tm_strings.BB_default;
|
||||
} else {
|
||||
button_label = wpml_tm_strings.BB_no_actions;
|
||||
}
|
||||
|
||||
jQuery('#icl_tm_jobs_submit').html(button_label);
|
||||
},
|
||||
icl_update_button_class: function (dupl_count, trans_count) {
|
||||
var button= jQuery('#icl_tm_jobs_submit');
|
||||
var button_class= 'otgs-ico-basket';
|
||||
if ((dupl_count > 0 && trans_count === 0) || button.data('use-basket') === 0) {
|
||||
button.removeClass(button_class);
|
||||
} else {
|
||||
button.addClass(button_class);
|
||||
}
|
||||
},
|
||||
icl_tm_dup_warn: function () {
|
||||
var self = this;
|
||||
if (self.counts.duplicate > 0) {
|
||||
self.$el.find('#icl_dup_ovr_warn').fadeIn(400);
|
||||
} else {
|
||||
self.$el.find('#icl_dup_ovr_warn').fadeOut(400);
|
||||
}
|
||||
self.icl_update_button_label(self.counts.duplicate, self.counts.translate);
|
||||
self.icl_update_button_class(self.counts.duplicate, self.counts.translate);
|
||||
},
|
||||
icl_tm_bulk_batch_selection: function (e) {
|
||||
var self = this;
|
||||
var element = jQuery(e.target);
|
||||
var value = element.val();
|
||||
element.prop('checked', true);
|
||||
self.$el.find('#icl_tm_languages').find('tbody input:radio[value=' + value + ']').prop('checked', true);
|
||||
self.change_radio();
|
||||
return self;
|
||||
},
|
||||
icl_tm_enable_submit: function () {
|
||||
var self = this;
|
||||
var hasSelection = (self.counts.duplicate > 0 || self.counts.translate > 0)
|
||||
&& jQuery('#icl-tm-translation-dashboard').find('td :checkbox:checked').length > 0;
|
||||
jQuery('#icl_tm_jobs_submit').prop('disabled', !hasSelection);
|
||||
},
|
||||
icl_tm_update_doc_count: function () {
|
||||
var self = this;
|
||||
var dox = self.$el.find('tbody td :checkbox:checked').length;
|
||||
jQuery('#icl-tm-sel-doc-count').html(dox);
|
||||
if (dox) {
|
||||
jQuery('#icl-tm-doc-wrap').fadeIn();
|
||||
} else {
|
||||
jQuery('#icl-tm-doc-wrap').fadeOut();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var PostDuplication = Backbone.View.extend({
|
||||
ui: {},
|
||||
posts: [],
|
||||
duplicatedIDs: [],
|
||||
langs: '',
|
||||
initialize: function (posts, element) {
|
||||
var self = this;
|
||||
self.posts = posts;
|
||||
self.ui = new ProgressBar();
|
||||
self.ui.overall_count = posts.length;
|
||||
self.ui.actionText = wpml_tm_strings.duplicating;
|
||||
element.replaceWith(self.ui.getDomElement());
|
||||
self.ui.start();
|
||||
},
|
||||
sendBatch: function () {
|
||||
var nonce;
|
||||
var p;
|
||||
var postsToSend;
|
||||
var languages;
|
||||
var self = this;
|
||||
var postsDataToSend = self.posts.splice(0, 5);
|
||||
var postsDataToSendCount = postsDataToSend.length;
|
||||
|
||||
if(0 < postsDataToSendCount) {
|
||||
postsToSend = [];
|
||||
languages = [];
|
||||
for (p = 0; p < postsDataToSendCount; p++) {
|
||||
if (-1 === jQuery.inArray(postsDataToSend[p].postId, postsToSend)) {
|
||||
postsToSend.push(postsDataToSend[p].postId);
|
||||
}
|
||||
if (-1 === jQuery.inArray(postsDataToSend[p].languageCode, languages)) {
|
||||
languages.push(postsDataToSend[p].languageCode);
|
||||
}
|
||||
}
|
||||
|
||||
if(0 < postsToSend.length && 0 < languages.length) {
|
||||
nonce = wpml_tm_strings.wpml_duplicate_dashboard_nonce;
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'wpml_duplicate_dashboard',
|
||||
duplicate_post_ids: postsToSend,
|
||||
duplicate_target_languages: languages,
|
||||
_icl_nonce: nonce
|
||||
},
|
||||
success: function () {
|
||||
self.ui.change(postsToSend.length);
|
||||
self.duplicatedIDs = self.duplicatedIDs.concat(postsToSend);
|
||||
if (0 < self.posts.length) {
|
||||
self.sendBatch();
|
||||
} else {
|
||||
self.ui.complete(wpml_tm_strings.duplication_complete, false);
|
||||
jQuery('#icl_tm_languages').find('tbody').find(':radio:checked').filter('[value=2]').prop('checked', false);
|
||||
self.setHierarchyNoticeAndSubmit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
setHierarchyNoticeAndSubmit: function () {
|
||||
var self = this;
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'wpml_need_sync_message',
|
||||
duplicated_post_ids: self.duplicatedIDs.join(','),
|
||||
_icl_nonce: wpml_tm_strings.wpml_need_sync_message_nonce
|
||||
|
||||
},
|
||||
success: function () {
|
||||
jQuery('#icl_tm_dashboard_form').submit();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(function () {
|
||||
var tmDashboard = new WPML_TM.Dashboard();
|
||||
tmDashboard.init(jQuery);
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,90 @@
|
||||
var WPMLCore = WPMLCore || {};
|
||||
|
||||
WPMLCore.Tooltip = function (element) {
|
||||
this.trigger = element;
|
||||
this.content = this.trigger.html(this.trigger.html()).text();
|
||||
this.edge = 'bottom';
|
||||
this.align = 'left';
|
||||
this.margin_left = '-54px';
|
||||
|
||||
if (!this.content) {
|
||||
this.content = this.decodeEntities(this.trigger.data('content'));
|
||||
}
|
||||
|
||||
if (this.trigger.data('edge')) {
|
||||
this.edge = this.trigger.data('edge');
|
||||
}
|
||||
|
||||
if (this.trigger.data('align')) {
|
||||
this.align = this.trigger.data('align');
|
||||
}
|
||||
|
||||
if (this.trigger.data('margin_left')) {
|
||||
this.margin_left = this.trigger.data('margin_left');
|
||||
}
|
||||
|
||||
this.trigger.empty();
|
||||
this.trigger.click(jQuery.proxy(this.onTriggerClick, this));
|
||||
};
|
||||
|
||||
WPMLCore.Tooltip.prototype = {
|
||||
open: function () {
|
||||
if (this.trigger.length && this.content) {
|
||||
this.trigger.addClass('js-wpml-active-tooltip');
|
||||
this.trigger.pointer({
|
||||
pointerClass: 'js-wpml-tooltip',
|
||||
content: this.content,
|
||||
position: {
|
||||
edge: this.edge,
|
||||
align: this.align
|
||||
},
|
||||
show: jQuery.proxy(this.onShow, this),
|
||||
close: this.onClose,
|
||||
buttons: this.buttons
|
||||
|
||||
}).pointer('open');
|
||||
}
|
||||
},
|
||||
onShow: function (event, t) {
|
||||
t.pointer.css('marginLeft', this.margin_left);
|
||||
},
|
||||
onClose: function (event, t) {
|
||||
t.pointer.css('marginLeft', '0');
|
||||
},
|
||||
onTriggerClick: function (e) {
|
||||
e.preventDefault();
|
||||
this.open();
|
||||
},
|
||||
buttons: function (event, t) {
|
||||
var button = jQuery('<a class="close" href="#"> </a>');
|
||||
|
||||
return button.on('click.pointer', function (e) {
|
||||
e.preventDefault();
|
||||
t.element.pointer('close');
|
||||
});
|
||||
},
|
||||
decodeEntities: function (encodedString) {
|
||||
var textArea = document.createElement('textarea');
|
||||
textArea.innerHTML = encodedString;
|
||||
return textArea.value;
|
||||
}
|
||||
};
|
||||
|
||||
WPMLCore.initializeTooltips = function() {
|
||||
"use strict";
|
||||
|
||||
var tooltips = jQuery('.js-wpml-tooltip-open'), tooltip = {};
|
||||
|
||||
tooltips.each(function (index, element) {
|
||||
tooltip = new WPMLCore.Tooltip(jQuery(element));
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
jQuery(function () {
|
||||
WPMLCore.initializeTooltips();
|
||||
});
|
||||
}());
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function WpmlTpPollingPickupPopulateAction(jQuery, TranslationProxyPolling) {
|
||||
/*
|
||||
* Before doing anything here, check whether the box, to write
|
||||
* data about translations ready for pickup , even exists.
|
||||
*/
|
||||
var tmPickupBox = jQuery('#icl_tm_pickup_wrap');
|
||||
var icl_tm_pickup_wrap_button = jQuery("#icl_tm_get_translations");
|
||||
var pickup_nof_jobs = jQuery("#icl_pickup_nof_jobs");
|
||||
var pickup_last_pickup = jQuery("#icl_pickup_last_pickup");
|
||||
var nonce = jQuery("#_icl_nonce_populate_t").val();
|
||||
|
||||
return {
|
||||
run: function () {
|
||||
if (tmPickupBox.length === 0) {
|
||||
return;
|
||||
}
|
||||
icl_tm_pickup_wrap_button.val('...Fetching translation job data ...');
|
||||
icl_tm_pickup_wrap_button.prop('disabled', true);
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'icl_populate_translations_pickup_box',
|
||||
_icl_nonce: nonce
|
||||
},
|
||||
success: function (response) {
|
||||
/** @namespace response.data.wait_text */
|
||||
/** @namespace response.data.polling_data */
|
||||
/** @namespace response.data.jobs_in_progress_text */
|
||||
/** @namespace response.data.last_pickup_text */
|
||||
if (response.success) {
|
||||
if (!response.data.wait_text) {
|
||||
icl_tm_pickup_wrap_button.prop('disabled', false);
|
||||
icl_tm_pickup_wrap_button.val(response.data.button_text);
|
||||
pickup_nof_jobs.html(response.data.jobs_in_progress_text);
|
||||
pickup_last_pickup.text(response.data.last_pickup_text);
|
||||
jQuery('#tp_polling_job').text(JSON.stringify(response.data.polling_data));
|
||||
TranslationProxyPolling.init(icl_tm_pickup_wrap_button, icl_ajxloaderimg);
|
||||
} else {
|
||||
pickup_nof_jobs.html(response.data.wait_text);
|
||||
icl_tm_pickup_wrap_button.hide();
|
||||
}
|
||||
} else {
|
||||
icl_tm_pickup_wrap_button.val(response.data.button_text);
|
||||
}
|
||||
},
|
||||
error: function (response) {
|
||||
if (response.data && response.data.error) {
|
||||
jQuery("#icl_pickup_nof_jobs").text(response.data.error);
|
||||
}
|
||||
icl_tm_pickup_wrap_button.hide();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
jQuery(function () {
|
||||
var boxPopulation = new WpmlTpPollingPickupPopulateAction(jQuery, TranslationProxyPolling);
|
||||
boxPopulation.run();
|
||||
});
|
||||
@@ -0,0 +1,142 @@
|
||||
/*global jQuery, ajaxurl, JSON */
|
||||
"use strict";
|
||||
|
||||
var TranslationProxyPolling = {
|
||||
init: function (button, icl_ajxloaderimg) {
|
||||
var self = this;
|
||||
var JSONtext = jQuery('#tp_polling_job').text();
|
||||
self.jobs = JSONtext ? JSON.parse(JSONtext) : [];
|
||||
jQuery(button).click(self.handleOne);
|
||||
self.button = jQuery(button);
|
||||
self.icl_ajxloaderimg = jQuery(icl_ajxloaderimg);
|
||||
self.icl_ajxloaderimg.hide();
|
||||
self.button.after(TranslationProxyPolling.icl_ajxloaderimg);
|
||||
},
|
||||
jobs: [],
|
||||
completed_count: 0,
|
||||
cancel_count: 0,
|
||||
error_data: [],
|
||||
showSpinner: function () {
|
||||
if (!TranslationProxyPolling.spinner) {
|
||||
TranslationProxyPolling.button.prop('disabled', true);
|
||||
TranslationProxyPolling.icl_ajxloaderimg.show();
|
||||
TranslationProxyPolling.spinner = true;
|
||||
}
|
||||
},
|
||||
hideSpinner: function () {
|
||||
TranslationProxyPolling.button.prop('disabled', false);
|
||||
TranslationProxyPolling.icl_ajxloaderimg.hide();
|
||||
TranslationProxyPolling.spinner = false;
|
||||
},
|
||||
handleOne: function () {
|
||||
var nonce = jQuery("#_icl_nonce_pickup_t").val();
|
||||
var currentJob = TranslationProxyPolling.jobs.length > 0 ? TranslationProxyPolling.jobs.pop() : false;
|
||||
if (currentJob) {
|
||||
TranslationProxyPolling.showSpinner();
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'icl_pickup_translations',
|
||||
_icl_nonce: nonce,
|
||||
job_polled: currentJob,
|
||||
completed_jobs: TranslationProxyPolling.completed_count,
|
||||
cancelled_jobs: TranslationProxyPolling.cancel_count
|
||||
},
|
||||
success: function (response) {
|
||||
if (currentJob && !response.data.job_error) {
|
||||
TranslationProxyPolling.updateCounts(currentJob, response);
|
||||
}
|
||||
var icl_message_div;
|
||||
/** @namespace response.data.completed */
|
||||
if (response.data.completed) {
|
||||
icl_message_div = jQuery("#icl_tm_pickup_wrap_completed");
|
||||
icl_message_div.text(response.data.completed);
|
||||
icl_message_div.show();
|
||||
}
|
||||
/** @namespace response.data.cancelled */
|
||||
if (response.data.cancelled) {
|
||||
icl_message_div = jQuery("#icl_tm_pickup_wrap_cancelled");
|
||||
icl_message_div.text(response.data.cancelled);
|
||||
icl_message_div.show();
|
||||
}
|
||||
/** @namespace response.data.submitting */
|
||||
if (response.data.submitting) {
|
||||
icl_message_div = jQuery("#icl_tm_pickup_wrap_submitting");
|
||||
icl_message_div.text(response.data.submitting);
|
||||
icl_message_div.show();
|
||||
}
|
||||
if (TranslationProxyPolling.jobs.length > 0) {
|
||||
TranslationProxyPolling.handleOne();
|
||||
} else {
|
||||
TranslationProxyPolling.hideSpinner();
|
||||
TranslationProxyPolling.button.attr('disabled', 'disabled');
|
||||
TranslationProxyPolling.startReloading(10);
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'icl_pickup_translations_complete'
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
TranslationProxyPolling.hideSpinner();
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
TranslationProxyPolling.hideSpinner();
|
||||
}
|
||||
},
|
||||
updateCounts: function (currentJob, response) {
|
||||
if (currentJob.job_state === 'translation_ready' && response.data.completed) {
|
||||
TranslationProxyPolling.completed_count += 1;
|
||||
}
|
||||
if (currentJob.job_state === 'cancelled' && response.data.cancelled) {
|
||||
TranslationProxyPolling.completed_count += 1;
|
||||
}
|
||||
},
|
||||
startReloading: function (remaining) {
|
||||
if (0 >= remaining) {
|
||||
location.reload(true);
|
||||
} else {
|
||||
TranslationProxyPolling.updatePickupButtonTo('reloading', remaining);
|
||||
setTimeout(function () {
|
||||
TranslationProxyPolling.startReloading(remaining - 1);
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
updatePickupButtonTo: function (state, value) {
|
||||
var dataAttributePrefix, stateData, sanitizedValue;
|
||||
|
||||
dataAttributePrefix = state;
|
||||
if ('undefined' === typeof state) {
|
||||
dataAttributePrefix = 'default';
|
||||
}
|
||||
|
||||
sanitizedValue = value;
|
||||
if ('undefined' === typeof value) {
|
||||
sanitizedValue = '';
|
||||
}
|
||||
|
||||
stateData = TranslationProxyPolling.button.data(dataAttributePrefix + '-text');
|
||||
|
||||
if ('reloading' === dataAttributePrefix) {
|
||||
stateData = TranslationProxyPolling.button.data('reloading-text') + ' ' + sanitizedValue;
|
||||
}
|
||||
|
||||
if ('undefined' !== typeof stateData) {
|
||||
if (stateData) {
|
||||
TranslationProxyPolling.button.data('current-text', stateData);
|
||||
TranslationProxyPolling.button.val(stateData);
|
||||
} else {
|
||||
self.updatePickupButtonTo('default');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,754 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global jQuery, ajaxurl, icl_ajx_url, icl_ajxloaderimg, tm_basket_data */
|
||||
|
||||
(function ($) {
|
||||
"use strict";
|
||||
|
||||
jQuery(
|
||||
function () {
|
||||
|
||||
//Basket
|
||||
|
||||
/* enable button 'Remove from basket' in Translation management > Translate jobs */
|
||||
var translation_jobs_basket_form = jQuery('#translation-jobs-basket-form');
|
||||
var handle_basket_form_cb = function (cb_location) {
|
||||
jQuery('#icl-tm-basket-delete-but').prop('disabled', jQuery('#translation-jobs-basket-form').find(cb_location + ':checked').length);
|
||||
};
|
||||
|
||||
var cb_locations = ['td', 'tfoot th', 'thead th'];
|
||||
jQuery.each(cb_locations,function(cb_location){
|
||||
cb_location += ' :checkbox:checked';
|
||||
translation_jobs_basket_form.find(cb_location).click(
|
||||
function () {
|
||||
handle_basket_form_cb(cb_location);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
jQuery('.js-translation-jobs-basket-form').on(
|
||||
'submit', function (e) { // Display confirmation on form submit
|
||||
e.preventDefault();
|
||||
|
||||
var message = jQuery(this).data('message');
|
||||
var confirmation = confirm(message);
|
||||
|
||||
if (confirmation) {
|
||||
jQuery(this).off('submit');
|
||||
jQuery(this).trigger('submit');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
function Translation_Jobs() {
|
||||
var form = jQuery('#translation-jobs-translators-form');
|
||||
var form_send_button = form.find('.button-primary');
|
||||
var form_delete_button = jQuery('[name="clear-basket"]');
|
||||
var basket_name_element = form.find('#basket_name');
|
||||
var basket_extra_fields_list = form.find('#basket_extra_fields_list');
|
||||
var message_box;
|
||||
var message_box_content;
|
||||
var additional_data;
|
||||
var progress_bar_object = new ProgressBar();
|
||||
var progress_bar = progress_bar_object.getDomElement();
|
||||
var batch_basket_items = [];
|
||||
var batch_number = 0;
|
||||
var batch_size;
|
||||
var batch_deadline = form.find( '#basket-deadline' );
|
||||
|
||||
var init = function () {
|
||||
form.on('submit', submit_form);
|
||||
|
||||
// prevent sending basket by pressing Enter
|
||||
form.on("keypress", function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
basket_name_element.on('blur', basket_name_blur);
|
||||
|
||||
message_box = jQuery('<div class="message_box"><div class="wpml-tm-basket-message-icon"></div></div>');
|
||||
message_box_content = jQuery('<div class="wpml-tm-basket-message-content"></div>');
|
||||
message_box_content.appendTo(message_box);
|
||||
message_box.insertBefore(form_send_button).hide();
|
||||
|
||||
additional_data = jQuery('<div class="additional_data"></div>');
|
||||
|
||||
progress_bar.insertAfter(message_box_content);
|
||||
progress_bar.hide();
|
||||
|
||||
initDatePicker();
|
||||
$('#icl-translation-translators').on('change', '.js-wpml-translator-dropdown', refresh_deadline_date);
|
||||
};
|
||||
|
||||
var initDatePicker = function() {
|
||||
batch_deadline.datepicker({
|
||||
minDate: new Date( Date.now() ),
|
||||
dateFormat: "yy-mm-dd",
|
||||
dayNames: wpml_tm_translation_basket_and_options.day_names,
|
||||
dayNamesMin: wpml_tm_translation_basket_and_options.day_initials,
|
||||
monthNames: wpml_tm_translation_basket_and_options.month_names
|
||||
});
|
||||
|
||||
jQuery( 'body' ).addClass( 'wpml' );
|
||||
};
|
||||
|
||||
var refresh_deadline_date = function(e) {
|
||||
var translatorsTable = $(e.delegateTarget);
|
||||
var selectors = translatorsTable.find('.js-wpml-translator-dropdown');
|
||||
var spinner = batch_deadline.siblings('.spinner');
|
||||
var translators = {};
|
||||
|
||||
$.each(selectors, function(i, selector) {
|
||||
selector = $(selector);
|
||||
var lang_to = selector.data('lang-to');
|
||||
translators[ lang_to ] = selector.find(':selected').val();
|
||||
});
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
$.post({
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: 'wpml-tm-jobs-deadline-estimate-ajax-action',
|
||||
nonce: form.find('#_icl_nonce_refresh_deadline').val(),
|
||||
translators: translators
|
||||
},
|
||||
success: function(response) {
|
||||
form.find('#basket-deadline').val(response.data.deadline);
|
||||
spinner.removeClass('is-active');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var basket_name_blur = function (e) {
|
||||
if (e !== null && typeof e.preventDefault !== 'undefined') {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
var spinner = jQuery('<span class="spinner" style="display: inline-block;"></span>');
|
||||
spinner.hide();
|
||||
|
||||
spinner.insertAfter(jQuery(this));
|
||||
spinner.css('float', 'none');
|
||||
spinner.show();
|
||||
|
||||
check_basket_name();
|
||||
|
||||
spinner.hide();
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
var get_nonce = function (action) {
|
||||
var nonceField = jQuery('[id="_icl_nonce_' + action + '"]');
|
||||
|
||||
return nonceField ? nonceField.val() : '';
|
||||
};
|
||||
|
||||
var check_basket_name = function () {
|
||||
|
||||
var action = 'check_basket_name';
|
||||
var nonce = get_nonce(action);
|
||||
var check_result = false;
|
||||
var basket_name = get_basket_name();
|
||||
form_send_button.attr('disabled', 'disabled');
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
async: false,
|
||||
data: {
|
||||
action: 'check_basket_name',
|
||||
basket_name: basket_name,
|
||||
_icl_nonce: nonce
|
||||
},
|
||||
success: function (result) {
|
||||
result = result.data;
|
||||
/** @namespace result.new_value */
|
||||
form_send_button.prop('disabled', !result.valid)
|
||||
if (result.valid) {
|
||||
if (result.modified) {
|
||||
set_basket_name(result.new_value);
|
||||
}
|
||||
form_send_button.show();
|
||||
} else {
|
||||
alert(result.message);
|
||||
set_basket_name(result.new_value);
|
||||
check_basket_name();
|
||||
}
|
||||
|
||||
check_result = result.valid;
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
show_errors(jqXHR, textStatus);
|
||||
form_send_button.prop('disabled', true);
|
||||
check_result = false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return check_result;
|
||||
};
|
||||
|
||||
var get_basket_name = function () {
|
||||
if (typeof basket_name_element !== 'undefined' && basket_name_element.val().length === 0) {
|
||||
basket_name_element.val(basket_name_element.attr('placeholder'));
|
||||
}
|
||||
|
||||
return basket_name_element.val();
|
||||
};
|
||||
|
||||
var set_basket_name = function (value) {
|
||||
if (typeof basket_name_element !== 'undefined') {
|
||||
basket_name_element.val(value);
|
||||
}
|
||||
|
||||
return basket_name_element.val();
|
||||
};
|
||||
|
||||
// translator[it]
|
||||
// translator[en-US]
|
||||
var get_translators = function () {
|
||||
var extract_translator = function (translators, key, value) {
|
||||
if (typeof key !== 'undefined' && /^translator/.test(key)) {
|
||||
key = key.replace('translator[', '').replace(']', '');
|
||||
if (translators[key] !== undefined) {
|
||||
if (!translators[key].push) {
|
||||
translators[key] = [translators[key]];
|
||||
}
|
||||
translators[key].push(value || '');
|
||||
} else {
|
||||
translators[key] = value || '';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Todo: get only translators
|
||||
var translators = {};
|
||||
var a = form.serializeArray();
|
||||
jQuery.each(
|
||||
a, function () {
|
||||
var key = this.name;
|
||||
var value = this.value;
|
||||
extract_translator(translators, key, value);
|
||||
}
|
||||
);
|
||||
|
||||
return translators;
|
||||
};
|
||||
|
||||
var get_extra_fields = function () {
|
||||
var items = jQuery('#basket_extra_fields_list').find(':input').get();
|
||||
var string = '';
|
||||
var items_total = jQuery(items).length;
|
||||
|
||||
if (items_total > 0) {
|
||||
jQuery(items).each(function (index, elm) {
|
||||
string += elm.name +":"+ jQuery(elm).val();
|
||||
if (index !== items_total - 1) {
|
||||
string += "|";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return encodeURIComponent(string);
|
||||
};
|
||||
|
||||
var sending_only_to_professional_translation = function (translators) {
|
||||
var isProfessionalTranslator = function (translator) {
|
||||
return translator.match(/^ts-\d+$/);
|
||||
};
|
||||
|
||||
var translatorsArray = Object.values(translators);
|
||||
return translatorsArray.length === translatorsArray.filter(isProfessionalTranslator).length;
|
||||
};
|
||||
|
||||
var submit_form = function (e) {
|
||||
//Prevent submitting the form
|
||||
if (typeof e.preventDefault !== 'undefined') {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
if (!check_basket_name()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
additional_data.empty();
|
||||
message_box.hide();
|
||||
additional_data.appendTo(message_box_content);
|
||||
|
||||
var basket_name = get_basket_name();
|
||||
var translators = get_translators();
|
||||
translation_jobs_basket_form.find('.row-actions').hide();
|
||||
|
||||
form_send_button.attr('disabled', 'disabled').hide();
|
||||
form_delete_button.attr('disabled', 'disabled');
|
||||
|
||||
message_box.show();
|
||||
|
||||
var header = sending_only_to_professional_translation(translators) ?
|
||||
tm_basket_data.strings['sending_batch_to_ts'] :
|
||||
tm_basket_data.strings['sending_batch'];
|
||||
|
||||
update_message('<h4>' + header + '</h4>', true, 'sending', false);
|
||||
|
||||
|
||||
if (typeof translators === 'undefined' || translators.length === 0) {
|
||||
update_message(tm_basket_data.strings['error_no_translators'], true, 'error', false);
|
||||
end_process(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
progress_bar_object.start();
|
||||
var action = 'send_basket_items';
|
||||
var nonce = get_nonce(action);
|
||||
|
||||
//Retrieve basket items
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: action,
|
||||
basket_name: basket_name,
|
||||
_icl_nonce: nonce
|
||||
},
|
||||
success: function (result) {
|
||||
result = result.data;
|
||||
|
||||
update_message(result.message, false, 'sending', false);
|
||||
|
||||
batch_basket_items = [];
|
||||
var batch_basket_string_items = [];
|
||||
|
||||
//Loop through basket item group
|
||||
jQuery.each(result.basket, prepare_basket_items(result.allowed_item_types, batch_basket_string_items));
|
||||
|
||||
progress_bar_object.overall_count = batch_basket_items.length + batch_basket_string_items.length;
|
||||
batch_number = 0;
|
||||
|
||||
update_basket_badge_count(progress_bar_object.getRemainingCount());
|
||||
|
||||
if (batch_basket_string_items.length > 0) {
|
||||
batch_send_strings(basket_name, translators, batch_basket_string_items);
|
||||
} else {
|
||||
batch_send_basket_to_tp(basket_name, translators);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
show_errors(jqXHR, textStatus);
|
||||
show_rollback_message();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
//Prevent submitting the form (backward compatibility)
|
||||
return false;
|
||||
};
|
||||
|
||||
var prepare_basket_items = function (allowed_item_types, batch_basket_string_items) {
|
||||
return function (item_type, basket_group) {
|
||||
if (jQuery.inArray(item_type, allowed_item_types) >= 0) {
|
||||
jQuery.each(
|
||||
basket_group, function (post_id) {
|
||||
var batch_basket_item = {};
|
||||
batch_basket_item.type = item_type;
|
||||
batch_basket_item.post_id = post_id;
|
||||
|
||||
if (item_type === 'string') {
|
||||
batch_basket_string_items.push(batch_basket_item);
|
||||
} else {
|
||||
batch_basket_items.push(batch_basket_item);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var progressbar_finish_text = '100%';
|
||||
var progressbar_callback = function (progress_bar) {
|
||||
progress_bar.dom.remove();
|
||||
};
|
||||
|
||||
var update_basket_badge_count = function (count) {
|
||||
var badge = jQuery('#wpml-basket-items');
|
||||
count = parseInt(count, 10);
|
||||
|
||||
if (count > 0) {
|
||||
badge.find('#basket-item-count').text(count);
|
||||
} else {
|
||||
badge.hide();
|
||||
}
|
||||
};
|
||||
|
||||
var batch_send_strings = function (basket_name, translators, strings) {
|
||||
if (strings.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
batch_number++;
|
||||
var batch_number_label = jQuery('<p><strong>' + tm_basket_data.strings['batch'] + ' #' + batch_number + '</strong></p>');
|
||||
update_message(batch_number_label, true, 'sending', true);
|
||||
|
||||
batch_size = strings.length;
|
||||
|
||||
var success_callback = build_success_callback(function() {
|
||||
batch_send_basket_to_tp(basket_name, translators);
|
||||
});
|
||||
|
||||
send_basket_item_request(basket_name, translators, strings, success_callback);
|
||||
};
|
||||
|
||||
var batch_send_basket_to_tp = function (basket_name, translators, skip_items) {
|
||||
|
||||
if (typeof skip_items === 'undefined') {
|
||||
skip_items = 0;
|
||||
// We consider 2s per doc and per lang, and we don't want to exceed 20s per request
|
||||
var langs = Object.keys(translators);
|
||||
batch_size = Math.ceil(20 / langs.length); // 1 to 20
|
||||
batch_size = Math.min(5, batch_size); // 1 to 5
|
||||
}
|
||||
|
||||
batch_number++;
|
||||
|
||||
var batch_length = batch_basket_items.length;
|
||||
if ((batch_length - skip_items) <= 0) {
|
||||
end_process(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (batch_length > 1) {
|
||||
|
||||
var batch_number_label = jQuery('<p><strong>' + tm_basket_data.strings['batch'] + ' #' + batch_number + '</strong></p>');
|
||||
|
||||
update_message(batch_number_label, true, 'sending', true);
|
||||
}
|
||||
|
||||
var batch_data = batch_basket_items.slice(skip_items, skip_items + batch_size);
|
||||
|
||||
var success_callback = build_success_callback(function () {
|
||||
setTimeout(
|
||||
function () {
|
||||
batch_send_basket_to_tp(basket_name, translators, (skip_items + batch_size));
|
||||
}, 1000
|
||||
)
|
||||
});
|
||||
|
||||
send_basket_item_request(basket_name, translators, batch_data, success_callback);
|
||||
};
|
||||
|
||||
var build_success_callback = function(nextStepCallback) {
|
||||
return function (result) {
|
||||
var success = result.success;
|
||||
var data = result.data;
|
||||
|
||||
if (success) {
|
||||
progress_bar_object.change(batch_size);
|
||||
//Let's give some rest to the server
|
||||
nextStepCallback();
|
||||
} else {
|
||||
handle_ajax_error(data);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var handle_ajax_error = function (data) {
|
||||
update_message(data.message, true, 'error', true);
|
||||
show_additional_messages(data);
|
||||
progress_bar_object.stop();
|
||||
end_process(false);
|
||||
};
|
||||
|
||||
var send_basket_item_request = function(basket_name, translators, batch_data, success_callback) {
|
||||
var action = 'send_basket_item';
|
||||
|
||||
var data = {
|
||||
action: action,
|
||||
_icl_nonce: get_nonce(action),
|
||||
basket_name: basket_name,
|
||||
batch: batch_data,
|
||||
translators: translators,
|
||||
extra_fields: get_extra_fields(),
|
||||
deadline_date: batch_deadline.val()
|
||||
};
|
||||
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
success: success_callback,
|
||||
error: function (jqXHR, textStatus) {
|
||||
if (jqXHR.status >= 500) {
|
||||
request_rollback_for_batch(basket_name);
|
||||
}
|
||||
|
||||
show_errors(jqXHR, textStatus);
|
||||
show_rollback_message();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
var show_additional_messages = function (result) {
|
||||
/** @namespace result.additional_messages */
|
||||
if (typeof result.additional_messages !== 'undefined' && result.additional_messages !== null && result.additional_messages.length > 0) {
|
||||
jQuery.each(
|
||||
result.additional_messages, function (i, additional_message) {
|
||||
update_message(additional_message.text, true, additional_message.type, true);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
var show_errors = function (jqXHR, textStatus) {
|
||||
if (jqXHR.responseText === 'undefined') {
|
||||
update_message('<strong>'+tm_basket_data.strings['error_occurred']+'</strong><div>' + textStatus + '</div>', false, 'error', true);
|
||||
} else if (jqXHR.responseText === 'Invalid nonce') {
|
||||
update_message(tm_basket_data.strings['error_not_allowed'], false, 'error', true);
|
||||
} else {
|
||||
var error_content = jQuery(jqXHR.responseText.substring(1, jqXHR.responseText.length - 1));
|
||||
update_message(tm_basket_data.strings['error_occurred'], false, 'error', true);
|
||||
update_message(error_content, true, 'error', true);
|
||||
}
|
||||
};
|
||||
|
||||
var batch_send_basket_to_tp_commit = function () {
|
||||
update_message(tm_basket_data.strings['jobs_committing'], false, 'sending', false);
|
||||
|
||||
var action = 'send_basket_commit';
|
||||
var nonce = get_nonce(action);
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: action,
|
||||
_icl_nonce: nonce,
|
||||
translators: get_translators(),
|
||||
basket_name: get_basket_name()
|
||||
},
|
||||
success: function (result) {
|
||||
var success = result.success;
|
||||
result = result.data;
|
||||
if (success) {
|
||||
if(typeof result.result.is_local !== 'undefined' && result.result.is_local ) {
|
||||
var message = tm_basket_data.strings['jobs_sent_to_local_translator'];
|
||||
|
||||
if(typeof result.result.emails_did_not_sent !== 'undefined' && result.result.emails_did_not_sent ){
|
||||
message = message.replace(/<ul><li>[\s\S]*?<\/li>/, '<ul>' + tm_basket_data.strings['jobs_emails_local_did_not_sent'] );
|
||||
}
|
||||
}else{
|
||||
var message = tm_basket_data.strings['jobs_committed'];
|
||||
}
|
||||
if (typeof result.links !== 'undefined') {
|
||||
var links = jQuery('<ul></ul>');
|
||||
jQuery.each(
|
||||
result.links, function (i, link) {
|
||||
var link_item = jQuery('<li></li>');
|
||||
var link_anchor = jQuery('<a></a>');
|
||||
link_anchor.attr('href', link.url);
|
||||
link_anchor.text(link.text);
|
||||
|
||||
link_anchor.appendTo(link_item);
|
||||
link_item.appendTo(links);
|
||||
}
|
||||
);
|
||||
links.appendTo(message);
|
||||
}
|
||||
update_message(message, false, 'updated', false);
|
||||
var call_to_action = false;
|
||||
/** @namespace result.result.call_to_action */
|
||||
if(typeof result.result.call_to_action !== 'undefined') {
|
||||
call_to_action = jQuery('<p>' + result.result.call_to_action + '</p>');
|
||||
update_message(call_to_action, true, 'updated', true);
|
||||
}
|
||||
|
||||
batch_send_basket_to_tp_completed(result);
|
||||
|
||||
} else {
|
||||
handle_response(result);
|
||||
show_rollback_message();
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
show_errors(jqXHR, textStatus);
|
||||
show_rollback_message();
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var show_rollback_message = function () {
|
||||
update_message(tm_basket_data.strings['rollbacks'], false, 'error', false);
|
||||
update_message(tm_basket_data.strings['rolled'], false, 'error', true);
|
||||
progress_bar_object.complete(progressbar_finish_text, progressbar_callback);
|
||||
};
|
||||
|
||||
var request_rollback_for_batch = function(basket_name) {
|
||||
var action = 'rollback_basket';
|
||||
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: action,
|
||||
_icl_nonce: get_nonce(action),
|
||||
basket_name: basket_name
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var batch_send_basket_to_tp_completed = function (response) {
|
||||
progress_bar_object.complete(progressbar_finish_text, progressbar_callback);
|
||||
form_send_button.attr('disabled', 'disabled');
|
||||
form_delete_button.attr('disabled', 'disabled');
|
||||
basket_name_element.attr('disabled', 'disabled');
|
||||
basket_name_element.attr('readonly', 'readonly');
|
||||
batch_deadline.attr('disabled', 'disabled');
|
||||
batch_deadline.attr('readonly', 'readonly');
|
||||
form.attr('disabled', 'disabled');
|
||||
form.attr('readonly', 'readonly');
|
||||
form.trigger('wpml-tm-basket-submitted', response);
|
||||
|
||||
// hide the badge
|
||||
jQuery('#wpml-basket-items').hide();
|
||||
|
||||
};
|
||||
|
||||
var end_process = function (commit) {
|
||||
|
||||
if (commit) {
|
||||
batch_send_basket_to_tp_commit();
|
||||
} else {
|
||||
form_delete_button.prop('disabled', false);
|
||||
form_send_button.prop('disabled', false);
|
||||
form_send_button.show();
|
||||
show_rollback_message();
|
||||
}
|
||||
};
|
||||
|
||||
var handle_response = function (response) {
|
||||
var errors = [];
|
||||
if (typeof response.errors !== 'undefined') {
|
||||
errors = response.errors;
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
update_message(tm_basket_data.strings['errors'], false, 'error', true);
|
||||
jQuery.each(
|
||||
errors, function (i, error_message) {
|
||||
update_message(error_message, true, 'error', true);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
var update_message = function (message, details, status, append) {
|
||||
var target;
|
||||
|
||||
if (typeof append !== 'undefined' && append !== false) {
|
||||
append = true;
|
||||
}
|
||||
|
||||
if (typeof status !== 'undefined') {
|
||||
message_box.removeClass();
|
||||
message_box.addClass('wpml-tm-basket-message wpml-tm-basket-message-' + status);
|
||||
}
|
||||
|
||||
if (typeof details !== 'undefined' && details !== false) {
|
||||
target = additional_data;
|
||||
if (!target.length) {
|
||||
target = message_box_content;
|
||||
}
|
||||
} else {
|
||||
target = message_box_content;
|
||||
}
|
||||
if (!append) {
|
||||
target.empty();
|
||||
if (target === message_box_content) {
|
||||
additional_data.appendTo(message_box_content);
|
||||
}
|
||||
}
|
||||
build_message(target, message);
|
||||
};
|
||||
|
||||
var build_message = function (container, message_element_or_string) {
|
||||
|
||||
if (message_element_or_string && typeof container !== 'undefined') {
|
||||
if (container.is(":hidden") || !container.is(':visible')) {
|
||||
container.show();
|
||||
}
|
||||
if (typeof message_element_or_string === 'string') {
|
||||
message_element_or_string = jQuery('<p>' + message_element_or_string + '</p>');
|
||||
}
|
||||
if (typeof message_element_or_string === 'object') {
|
||||
message_element_or_string.appendTo(container);
|
||||
}
|
||||
}
|
||||
|
||||
return message_element_or_string;
|
||||
};
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
Translation_Jobs();
|
||||
|
||||
var basket_extra_fields_refresh = jQuery('#basket_extra_fields_refresh');
|
||||
basket_extra_fields_refresh.click(function(event) {
|
||||
event.preventDefault();
|
||||
var basket_extra_fields_list = jQuery('#basket_extra_fields_list');
|
||||
var ajax_spinner = jQuery('<span class="spinner"></span>');
|
||||
ajax_spinner.show();
|
||||
ajax_spinner.css('visibility', 'visible');
|
||||
basket_extra_fields_list.html(ajax_spinner);
|
||||
var ajax_data = {
|
||||
'action': 'basket_extra_fields_refresh'
|
||||
};
|
||||
|
||||
jQuery.post(ajaxurl, ajax_data, function(response) {
|
||||
basket_extra_fields_list.html(response);
|
||||
});
|
||||
});
|
||||
|
||||
var duplicated = document.getElementById('icl_duplicate_post_in_basket'),
|
||||
button = $('.button-primary'),
|
||||
nonce = document.getElementById('icl_disconnect_nonce');
|
||||
if (duplicated !== null) {
|
||||
$('<div />', {
|
||||
id: 'icl_disconnect_message',
|
||||
text: tm_basket_data.tmi_message,
|
||||
class: 'icl-admin-message-warning'
|
||||
}).insertBefore('.button-primary');
|
||||
button.on('click', function () {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: 'icl_disconnect_posts',
|
||||
nonce: nonce.value,
|
||||
posts: duplicated.value
|
||||
}
|
||||
}).success(function (resp) {
|
||||
if (resp.success !== true) {
|
||||
alert(resp.data);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}(jQuery));
|
||||
@@ -0,0 +1,79 @@
|
||||
jQuery(function ($) {
|
||||
"use strict";
|
||||
|
||||
var dialog = $('.js-wpml-translation-basket-dialog');
|
||||
|
||||
var openDialog = function (result) {
|
||||
/** @namespace result.call_to_action */
|
||||
/** @namespace result.ts_batch_link */
|
||||
|
||||
var hasAdditionalContent = typeof result.call_to_action !== 'undefined' || typeof result.ts_batch_link !== 'undefined';
|
||||
|
||||
var options = {
|
||||
dialogClass: 'wpml-dialog otgs-ui-dialog',
|
||||
width: 600,
|
||||
title: dialog.data('title'),
|
||||
modal: true,
|
||||
closeOnEscape: false,
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
open: function () {
|
||||
var dialogContent = dialog.find('.js-dialog-content');
|
||||
|
||||
var callToAction = dialogContent.find('.js-call-to-action');
|
||||
|
||||
var batchLink = dialogContent.find('.js-batch-link');
|
||||
var batchLinkAnchor = batchLink.find('a');
|
||||
|
||||
if (callToAction && typeof result.call_to_action !== 'undefined') {
|
||||
callToAction.text(result.call_to_action);
|
||||
hasAdditionalContent = true;
|
||||
}
|
||||
if (batchLinkAnchor && typeof result.ts_batch_link !== 'undefined') {
|
||||
batchLinkAnchor.attr('href', result.ts_batch_link.href);
|
||||
batchLinkAnchor.text(result.ts_batch_link.text);
|
||||
$(batchLinkAnchor).on('click', function () {
|
||||
dialog.dialog('close');
|
||||
});
|
||||
|
||||
batchLink.show();
|
||||
hasAdditionalContent = true;
|
||||
}
|
||||
dialog.show();
|
||||
repositionDialog();
|
||||
}
|
||||
};
|
||||
|
||||
if (hasAdditionalContent) {
|
||||
dialog.dialog(options);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var repositionDialog = function() {
|
||||
if (dialog.hasClass("ui-dialog-content") && dialog.dialog('isOpen')) {
|
||||
var winH = $(window).height() - 180;
|
||||
$(".otgs-ui-dialog .ui-dialog-content").css({
|
||||
"max-height": winH
|
||||
});
|
||||
$(".otgs-ui-dialog").css({
|
||||
"max-width": "95%"
|
||||
});
|
||||
dialog.dialog("option", "position", {
|
||||
my: "center",
|
||||
at: "center",
|
||||
of: window
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(window).resize(repositionDialog);
|
||||
|
||||
var form = $('#translation-jobs-translators-form');
|
||||
|
||||
form.on('wpml-tm-basket-submitted', function(event, response) {
|
||||
if (response.result) {
|
||||
openDialog(response.result);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
jQuery(function () {
|
||||
"use strict";
|
||||
|
||||
var dialog = jQuery('.wpml-tm-invalid-fields-dialog');
|
||||
|
||||
jQuery('.wpml-tm-invalid-fields-open-dialog').click(function () {
|
||||
var fields = jQuery(this).data('fields');
|
||||
dialog.dialog({
|
||||
dialogClass: 'wpml-dialog otgs-ui-dialog',
|
||||
width : 'auto',
|
||||
title : jQuery(this).data('page-title'),
|
||||
modal: true,
|
||||
open: function () {
|
||||
dialog.html('');
|
||||
dialog.append('<ul>');
|
||||
jQuery.each(fields, function(index, value){
|
||||
var field = JSON.parse(value);
|
||||
dialog.append('<li><strong>' + field.title + '</strong>: ' + field.content + '</li>');
|
||||
});
|
||||
dialog.append( '</ul>' );
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,293 @@
|
||||
this["WPML_TM"] = this["WPML_TM"] || {};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/footer.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<div class="wpml-translation-action-buttons-abort">\n\t<button class="cancel wpml-dialog-close-button js-dialog-cancel">' +
|
||||
((__t = (cancel)) == null ? '' : __t) +
|
||||
'</button>\n\t<button class="button-secondary wpml-resign-button js-resign">' +
|
||||
((__t = (resign)) == null ? '' : __t) +
|
||||
'</button>\n</div>\n<div class="wpml-translation-action-buttons-status">\n\t<div class="progress-bar js-progress-bar"><div class="progress-bar-text"></div></div>\n\t<label><input class="js-translation-complete" name="complete" type="checkbox"/>' +
|
||||
((__t = (translation_complete)) == null ? '' : __t) +
|
||||
'</label>\n\n\n\t<div class="otgs-toggle-group">\n\t\t<input type="checkbox" class="js-toggle-translated otgs-switcher-input" id="wpml_tm_toggle_translated">\n\t\t<label for="wpml_tm_toggle_translated" class="otgs-switcher" data-on="ON" data-off="OFF">' +
|
||||
((__t = (hide_translated)) == null ? '' : __t) +
|
||||
'</label>\n\t</div>\n</div>\n<div class = "wpml-translation-action-buttons-apply">\n\t<span class = "js-saving-message" style = "display:none"><img src="' +
|
||||
((__t = (loading_url)) == null ? '' : __t) +
|
||||
'" alt="' +
|
||||
((__t = (saving)) == null ? '' : __t) +
|
||||
'" height="16" width="16"/>' +
|
||||
((__t = (saving)) == null ? '' : __t) +
|
||||
'</span>\n\t<button class = "button button-primary button-large wpml-dialog-close-button js-save-and-close">' +
|
||||
((__t = (save_and_close)) == null ? '' : __t) +
|
||||
'</button>\n\t<button class = "button button-primary button-large wpml-dialog-close-button js-save">' +
|
||||
((__t = (save)) == null ? '' : __t) +
|
||||
'</button>\n</div>\n\n\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/group.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
|
||||
if ( title ) { ;
|
||||
__p +=
|
||||
((__t = ( title )) == null ? '' : __t);
|
||||
} ;
|
||||
__p += '\n<div class="inside">\n</div>\n\n';
|
||||
if ( divider ) { ;
|
||||
__p += '\n<hr />\n';
|
||||
} ;
|
||||
__p += '\n<button class="button-copy button-secondary js-button-copy-group">\n\t<i class="otgs-ico-copy"></i>\n</button>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/header.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p +=
|
||||
((__t = ( title )) == null ? '' : __t) +
|
||||
'\n<a href="' +
|
||||
((__t = ( link_url )) == null ? '' : __t) +
|
||||
'" class="view" target="_blank">' +
|
||||
((__t = ( link_text )) == null ? '' : __t) +
|
||||
'</a>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/image.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '\t<div class="inside">\n\t\t<img src="' +
|
||||
((__t = ( image_src )) == null ? '' : __t) +
|
||||
'">\n\t</div>\n\n\n';
|
||||
if ( divider ) { ;
|
||||
__p += '\n<hr />\n';
|
||||
} ;
|
||||
__p += '\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/languages.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '\t<input type="hidden" name="source_lang" value="' +
|
||||
((__t = ( language.source )) == null ? '' : __t) +
|
||||
'" />\n\t<input type="hidden" name="target_lang" value="' +
|
||||
((__t = ( language.target )) == null ? '' : __t) +
|
||||
'" />\n\t<h3 class="wpml-header-original">' +
|
||||
((__t = ( labels.source_lang )) == null ? '' : __t) +
|
||||
':\n\t\t<span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( language.img.source_url )) == null ? '' : __t) +
|
||||
'" alt="' +
|
||||
((__t = ( language.source_lang )) == null ? '' : __t) +
|
||||
'"/></span>\n\t\t<strong>' +
|
||||
((__t = ( language.source_lang )) == null ? '' : __t) +
|
||||
'</strong>\n\t</h3>\n\n\t<h3 class="wpml-header-translation">' +
|
||||
((__t = ( labels.target_lang )) == null ? '' : __t) +
|
||||
':\n\t\t<span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( language.img.target_url )) == null ? '' : __t) +
|
||||
'" alt="' +
|
||||
((__t = ( language.target_lang )) == null ? '' : __t) +
|
||||
'"/></span>\n\t\t<strong>' +
|
||||
((__t = ( language.target_lang )) == null ? '' : __t) +
|
||||
'</strong>\n\t</h3>\n\n\t<div class="wpml-copy-container">\n\t\t<button class="button-secondary button-copy-all js-button-copy-all" title="' +
|
||||
((__t = ( labels.copy_from_original )) == null ? '' : __t) +
|
||||
'">\n\t\t\t<i class="otgs-ico-copy"></i> ' +
|
||||
((__t = ( labels.copy_all )) == null ? '' : __t) +
|
||||
'\n\t\t</button>\n\t</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/note.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<p>' +
|
||||
((__t = ( note )) == null ? '' : __t) +
|
||||
'</p>\n\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/section.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<div class="handlediv button-link"><br></div>\n<h3 class="hndle">\n\t<span>' +
|
||||
((__t = ( section.title )) == null ? '' : __t) +
|
||||
' ';
|
||||
if ( section.empty ) { ;
|
||||
__p += ' <i>' +
|
||||
((__t = ( section.empty_message )) == null ? '' : __t);
|
||||
} ;
|
||||
__p += '</span>\n\t';
|
||||
if ( section.sub_title ) { ;
|
||||
__p += '\n\t<span class="subtitle"><i class="otgs-ico-warning"></i>' +
|
||||
((__t = ( section.sub_title )) == null ? '' : __t) +
|
||||
'</span>\n\t';
|
||||
} ;
|
||||
__p += '\n</h3>\n\n<div class="inside">\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/single-line.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<label>' +
|
||||
((__t = (field.title)) == null ? '' : __t) +
|
||||
'</label>\n<input readonly class="original_value js-original-value" value="' +
|
||||
__e( field.field_data ) +
|
||||
'" type="text" ' +
|
||||
((__t = (field.original_direction)) == null ? '' : __t) +
|
||||
'/>\n<button class="button-copy button-secondary js-button-copy icl_tm_copy_link otgs-ico-copy" id="icl_tm_copy_link_' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( labels.copy_from_original )) == null ? '' : __t) +
|
||||
'" ></button>\n<input class="translated_value js-translated-value" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][data]" value="' +
|
||||
__e( field.field_data_translated ) +
|
||||
'" type="text" ' +
|
||||
((__t = (field.translation_direction)) == null ? '' : __t) +
|
||||
'/>\n\n<div class="field_translation_complete">\n\t<label><input class="icl_tm_finished js-field-translation-complete" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][finished]" type="checkbox" ';
|
||||
if (field.field_finished) { ;
|
||||
__p += ' checked="checked" ';
|
||||
} ;
|
||||
__p += ' />' +
|
||||
((__t = (labels.translation_complete)) == null ? '' : __t) +
|
||||
'</label>\n</div>\n\n';
|
||||
if (field.diff) { ;
|
||||
__p += '\n<a class="js-toggle-diff toggle-diff">' +
|
||||
((__t = (labels.show_diff)) == null ? '' : __t) +
|
||||
'</a>\n' +
|
||||
((__t = (field.diff)) == null ? '' : __t) +
|
||||
'\n';
|
||||
} ;
|
||||
__p += '\n\n\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][tid]" value="' +
|
||||
((__t = (field.tid)) == null ? '' : __t) +
|
||||
'">\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][format]" value="base64">\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/textarea.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<label>' +
|
||||
((__t = (field.title)) == null ? '' : __t) +
|
||||
'</label>\n<textarea class="original_value js-original-value" readonly cols="22" rows="10" ' +
|
||||
((__t = (field.original_direction)) == null ? '' : __t) +
|
||||
'>' +
|
||||
((__t = ( field.field_data )) == null ? '' : __t) +
|
||||
'</textarea>\n<button class="button-copy button-secondary js-button-copy icl_tm_copy_link otgs-ico-copy" id="icl_tm_copy_link_' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( labels.copy_from_original )) == null ? '' : __t) +
|
||||
'"></button>\n<textarea class="translated_value js-translated-value cols="22" rows="10" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][data]" ' +
|
||||
((__t = (field.translation_direction)) == null ? '' : __t) +
|
||||
'>' +
|
||||
((__t = ( field.field_data_translated )) == null ? '' : __t) +
|
||||
'</textarea>\n\n<div class="field_translation_complete">\n\t<label><input class="icl_tm_finished js-field-translation-complete" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][finished]" type="checkbox" ';
|
||||
if (field.field_finished) { ;
|
||||
__p += ' checked="checked" ';
|
||||
} ;
|
||||
__p += ' />' +
|
||||
((__t = (labels.translation_complete)) == null ? '' : __t) +
|
||||
'</label>\n</div>\n\n';
|
||||
if (field.diff) { ;
|
||||
__p += '\n<a class="js-toggle-diff toggle-diff">' +
|
||||
((__t = (labels.show_diff)) == null ? '' : __t) +
|
||||
'</a>\n' +
|
||||
((__t = (field.diff)) == null ? '' : __t) +
|
||||
'\n';
|
||||
} ;
|
||||
__p += '\n\n\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][tid]" value="' +
|
||||
((__t = (field.tid)) == null ? '' : __t) +
|
||||
'">\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][format]" value="base64">\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/wysiwyg.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<label>' +
|
||||
((__t = (field.title)) == null ? '' : __t) +
|
||||
'</label>\n<div id="original_' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'_placeholder"></div>\n<button class="button-copy button-secondary js-button-copy icl_tm_copy_link otgs-ico-copy" id="icl_tm_copy_link_' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( labels.copy_from_original )) == null ? '' : __t) +
|
||||
'"></button>\n<div id="translated_' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'_placeholder"></div>\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][tid]" value="' +
|
||||
((__t = (field.tid)) == null ? '' : __t) +
|
||||
'">\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][format]" value="base64">\n\n<div class="field_translation_complete">\n <label><input class="icl_tm_finished js-field-translation-complete" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][finished]" type="checkbox" ';
|
||||
if (field.field_finished) { ;
|
||||
__p += ' checked="checked" ';
|
||||
} ;
|
||||
__p += ' />' +
|
||||
((__t = (labels.translation_complete)) == null ? '' : __t) +
|
||||
'</label>\n</div>\n\n';
|
||||
if (field.diff) { ;
|
||||
__p += '\n<a class="js-toggle-diff toggle-diff">' +
|
||||
((__t = (labels.show_diff)) == null ? '' : __t) +
|
||||
'</a>\n' +
|
||||
((__t = (field.diff)) == null ? '' : __t) +
|
||||
'\n';
|
||||
} ;
|
||||
__p += '\n\n\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
@@ -0,0 +1,211 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global _, jQuery, ajaxurl, icl_ajx_url, icl_ajxloaderimg, wpActiveEditor, tinyMCE,
|
||||
tinymce, iclSaveForm,
|
||||
tmEditorStrings, WPML_TM.editorFooterView, WPML_TM.editorHeaderView,
|
||||
WpmlTmEditorMainView,
|
||||
WpmlTranslationEditorTemplates, WpmlTemplateCompiler */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
"use strict";
|
||||
var tmEditor = {
|
||||
dontShowAgain: false,
|
||||
copyLinks: {},
|
||||
copyLinkViews: [],
|
||||
footerView: {},
|
||||
model: {},
|
||||
view: {},
|
||||
update_copy_link_visibility: function () {
|
||||
var self = tmEditor;
|
||||
self.copyLinks.each(function () {
|
||||
var type = this.id.replace(/^icl_tm_copy_link_/, '');
|
||||
var content = self.get_content_for_copy_field(type);
|
||||
if (content && content.trim() !== "") {
|
||||
jQuery(this).closest('span').hide();
|
||||
} else {
|
||||
jQuery(this).closest('span').show();
|
||||
}
|
||||
});
|
||||
if (self.copyLinks.filter(':visible').length === 1) {
|
||||
self.copyLinks.closest('span').hide();
|
||||
} else {
|
||||
self.copyLinks.find('#icl_tm_copy_link_icl_all_fields').closest('span').show();
|
||||
}
|
||||
},
|
||||
findInputFieldForCheckBox: function (cbName) {
|
||||
var fieldName = cbName.replace(/finished/, 'data');
|
||||
var inputField = jQuery('[name="' + fieldName + '"]');
|
||||
if (inputField.length === 0) {
|
||||
inputField = false;
|
||||
}
|
||||
|
||||
return inputField;
|
||||
},
|
||||
find_custom_editor: function (field_type) {
|
||||
var custom_editor = false;
|
||||
var editors;
|
||||
if (typeof tinyMCE !== 'undefined' && (editors = tinyMCE.editors) !== undefined) {
|
||||
jQuery.each(
|
||||
editors, function () {
|
||||
var item = this;
|
||||
if (("field-wpcf-" + field_type).toLowerCase() === item.id.toLowerCase()
|
||||
|| field_type.toLowerCase() === item.id.toLowerCase()) {
|
||||
custom_editor = item;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return custom_editor;
|
||||
},
|
||||
get_content_for_copy_field: function (field_type) {
|
||||
var editor = this.find_custom_editor(field_type);
|
||||
|
||||
return editor !== false ? editor.getContent() : jQuery('#' + field_type).val();
|
||||
},
|
||||
icl_populate_field: function (field_type, content) {
|
||||
var custom_editor = tmEditor.find_custom_editor(field_type);
|
||||
|
||||
if (custom_editor !== false && !custom_editor.isHidden() && custom_editor.getContent().trim() === "") {
|
||||
custom_editor.insertContent(content);
|
||||
} else {
|
||||
custom_editor = jQuery('#' + field_type);
|
||||
if ('undefined' !== typeof custom_editor && 'undefined' !== typeof custom_editor.val()) {
|
||||
custom_editor.val(custom_editor.val().trim() !== "" ? custom_editor.val() : content);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jQuery(function () {
|
||||
var wpml_diff_toggle = jQuery('.wpml_diff_toggle');
|
||||
wpml_diff_toggle.closest('.wpml_diff_wrapper').find('.wpml_diff').hide();
|
||||
wpml_diff_toggle.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
jQuery(this).closest('.wpml_diff_wrapper').find('.wpml_diff').slideToggle();
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.tm-learn-more').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var popUpHtml = '<div id="tm-editor-learn-more" title="' + tmEditorStrings.title + '">' + tmEditorStrings.learnMore + '</div>';
|
||||
jQuery(popUpHtml).dialog();
|
||||
});
|
||||
|
||||
var icl_tm_editor = jQuery('#icl_tm_editor');
|
||||
icl_tm_editor.find('.handlediv').click(function () {
|
||||
if (jQuery(this).parent().hasClass('closed')) {
|
||||
jQuery(this).parent().removeClass('closed');
|
||||
} else {
|
||||
jQuery(this).parent().addClass('closed');
|
||||
}
|
||||
});
|
||||
|
||||
jQuery('.icl_tm_finished').change(function () {
|
||||
jQuery(this).parent().parent().find('.icl_tm_error').hide();
|
||||
|
||||
var field = jQuery(this).attr('name').replace(/finished/, 'data');
|
||||
|
||||
var data;
|
||||
var datatemp = '';
|
||||
if (field === 'fields[body][data]') {
|
||||
try {
|
||||
datatemp = tinyMCE.get('body').getContent();
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
data = jQuery('*[name="' + field + '"]').val() + datatemp;
|
||||
} else if (jQuery(this).hasClass('icl_tmf_multiple')) {
|
||||
data = 1;
|
||||
jQuery('[name*="' + field + '"]').each(function () {
|
||||
data = data * jQuery(this).val().length;
|
||||
});
|
||||
} else {
|
||||
|
||||
try {
|
||||
datatemp = tinyMCE.get(field.replace('fields[', '').replace('][data]', '')).getContent();
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
|
||||
data = jQuery('[name="' + field + '"]*').val() + datatemp;
|
||||
data = jQuery('[name="' + field.toLowerCase() + '"]*').val() + datatemp;
|
||||
}
|
||||
|
||||
if (jQuery(this).prop('checked') && !data) {
|
||||
jQuery(this).closest('.icl_tm_error').show();
|
||||
jQuery(this).prop('checked', false);
|
||||
}
|
||||
});
|
||||
|
||||
jQuery('.icl_tmf_term').on('click', function (e) {
|
||||
var box = jQuery(this);
|
||||
var inputField = tmEditor.findInputFieldForCheckBox(box.attr('name'));
|
||||
if (box.prop('checked')) {
|
||||
box.prop('checked', true);
|
||||
} else {
|
||||
if (tmEditor.dontShowAgain === true) {
|
||||
inputField.attr('disabled', false);
|
||||
} else {
|
||||
var popUpHtml = ['<div id="tm-editor-learn-more"><span>',
|
||||
tmEditorStrings.warning,
|
||||
'</span><p><input type="checkbox" class="tm-editor-not-show-again"/>',
|
||||
tmEditorStrings.dontShowAgain,
|
||||
'</p></div>'].join('');
|
||||
jQuery(popUpHtml).dialog(
|
||||
{
|
||||
width: 'auto',
|
||||
buttons: [
|
||||
{
|
||||
text: "Ok",
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
if (inputField) {
|
||||
inputField.attr('disabled', false);
|
||||
box.prop('checked', false);
|
||||
if (jQuery(this).find('.tm-editor-not-show-again').prop('checked')) {
|
||||
jQuery(this).dialog("destroy");
|
||||
tmEditor.dontShowAgain = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
text: "Cancel",
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
box.prop('checked', true);
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var job_id = jQuery('[name="job_id"]').val();
|
||||
|
||||
tmEditor.model = new WPML_TM.editorJob(
|
||||
{
|
||||
job_id: job_id,
|
||||
nonce: tmEditorStrings.contentNonce,
|
||||
is_dirty: false
|
||||
}
|
||||
);
|
||||
tmEditor.copyLinks = jQuery('.icl_tm_copy_link');
|
||||
tmEditor.view = new WPML_TM.editorMainView({
|
||||
el: jQuery('.icl-translation-editor'),
|
||||
model: tmEditor.model
|
||||
});
|
||||
tmEditor.view.render();
|
||||
|
||||
|
||||
icl_tm_editor.submit(function () {
|
||||
return false;
|
||||
});
|
||||
|
||||
tmEditor.update_copy_link_visibility();
|
||||
|
||||
jQuery(window).trigger('customEvent');
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
/*jshint devel:true */
|
||||
/*global jQuery */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.editorCopyAll = function (mainView) {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
var init = function (mainView) {
|
||||
self.mainView = mainView;
|
||||
};
|
||||
|
||||
self.copy = function () {
|
||||
var hasTranslations = self.mainView.hasTranslations();
|
||||
if (!hasTranslations) {
|
||||
self.mainView.copyOriginalOverwrite();
|
||||
} else {
|
||||
self.copyAllDialog = new WPML_TM.editorCopyAllDialog(this);
|
||||
}
|
||||
};
|
||||
|
||||
self.copyAllNotTranslated = function () {
|
||||
self.mainView.copyOriginalDontOverwrite();
|
||||
};
|
||||
|
||||
self.copyAllOverwrite = function () {
|
||||
self.mainView.copyOriginalOverwrite();
|
||||
};
|
||||
|
||||
|
||||
init(mainView);
|
||||
|
||||
};
|
||||
|
||||
WPML_TM.editorCopyAllDialog = function (editor) {
|
||||
"use strict";
|
||||
|
||||
var dialog;
|
||||
|
||||
var init = function (editor) {
|
||||
dialog = jQuery("#wpml-translation-editor-copy-all-dialog");
|
||||
dialog.dialog({
|
||||
autoOpen: true,
|
||||
modal: true,
|
||||
minWidth: 500,
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
dialogClass: 'dialog-fixed otgs-ui-dialog'
|
||||
});
|
||||
|
||||
jQuery(dialog).find('.js-copy-cancel').off('click');
|
||||
jQuery(dialog).find('.js-copy-cancel').on('click', dialogCancel);
|
||||
|
||||
jQuery(dialog).find('.js-copy-not-translated').off('click');
|
||||
jQuery(dialog).find('.js-copy-not-translated').on('click', function () {
|
||||
editor.copyAllNotTranslated();
|
||||
dialog.dialog('close');
|
||||
});
|
||||
jQuery(dialog).find('.js-copy-overwrite').off('click');
|
||||
jQuery(dialog).find('.js-copy-overwrite').on('click', function () {
|
||||
editor.copyAllOverwrite();
|
||||
dialog.dialog('close');
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var dialogCancel = function () {
|
||||
dialog.dialog('close');
|
||||
};
|
||||
|
||||
init(editor);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*jshint devel:true */
|
||||
/*global jQuery */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.editorEditIndependentlyDialog = function (editor) {
|
||||
"use strict";
|
||||
|
||||
var dialog;
|
||||
var endingDuplicate;
|
||||
|
||||
var init = function (editor) {
|
||||
endingDuplicate = false;
|
||||
|
||||
dialog = jQuery("#wpml-translation-editor-edit-independently-dialog");
|
||||
dialog.dialog({
|
||||
autoOpen: true,
|
||||
modal: true,
|
||||
minWidth: 500,
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
dialogClass: 'dialog-fixed otgs-ui-dialog',
|
||||
beforeClose: function (event, ui) {
|
||||
if (!endingDuplicate) {
|
||||
dialogCancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(dialog).find('.js-edit-independently-cancel').off('click');
|
||||
jQuery(dialog).find('.js-edit-independently-cancel').on('click', dialogCancel);
|
||||
|
||||
jQuery(dialog).find('.js-edit-independently').off('click');
|
||||
jQuery(dialog).find('.js-edit-independently').on('click', function () {
|
||||
editor.editIndependently();
|
||||
endingDuplicate = true;
|
||||
dialog.dialog('close');
|
||||
});
|
||||
};
|
||||
|
||||
var dialogCancel = function () {
|
||||
editor.cancel();
|
||||
};
|
||||
|
||||
init(editor);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.FIELD_STYLE_SINGLE_LINE = '0';
|
||||
WPML_TM.FIELD_STYLE_TEXT_AREA = '1';
|
||||
WPML_TM.FIELD_STYLE_WYSIWYG = '2';
|
||||
|
||||
WPML_TM.fieldViewFactory = {
|
||||
create: function (field, args) {
|
||||
var view = null;
|
||||
if (field.field_style === WPML_TM.FIELD_STYLE_SINGLE_LINE) {
|
||||
view = new WPML_TM.editorSingleLineFieldView(args);
|
||||
} else if (field.field_style === WPML_TM.FIELD_STYLE_TEXT_AREA) {
|
||||
view = new WPML_TM.editorTextareaFieldView(args);
|
||||
} else if (field.field_style === WPML_TM.FIELD_STYLE_WYSIWYG) {
|
||||
view = new WPML_TM.editorWysiwygFieldView(args);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*global jQuery, ajaxurl, Backbone, WpmlTmEditorModel, window, tmEditorStrings, _ */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorFooterView = Backbone.View.extend({
|
||||
tagName: 'footer',
|
||||
className: 'wpml-translation-action-buttons',
|
||||
|
||||
events: {
|
||||
'click .js-save': 'save',
|
||||
'click .js-resign': 'resign',
|
||||
'click .js-dialog-cancel': 'cancel',
|
||||
'click .js-save-and-close': 'save_and_close',
|
||||
'change .js-toggle-translated': 'toggleTranslated'
|
||||
},
|
||||
initialize: function (options) {
|
||||
var self = this;
|
||||
self.mainView = options.mainView;
|
||||
self.listenTo(self.model, 'translationUpdated', self.setDirty);
|
||||
},
|
||||
save: function () {
|
||||
var self = this;
|
||||
self.doSave();
|
||||
},
|
||||
editIndependently: function () {
|
||||
WpmlTmEditorModel.is_duplicate = false;
|
||||
},
|
||||
doSave: function () {
|
||||
var self = this;
|
||||
var saveMessage = jQuery('.js-saving-message');
|
||||
saveMessage.show();
|
||||
self.disableButtons(true);
|
||||
self.listenToOnce(self.model, 'saveJobSuccess', function () {
|
||||
saveMessage.hide();
|
||||
self.disableButtons(false);
|
||||
});
|
||||
self.model.save(jQuery('#icl_tm_editor').serialize());
|
||||
|
||||
self.setDirty(false);
|
||||
return self;
|
||||
},
|
||||
resign: function () {
|
||||
if (window.confirm(tmEditorStrings.resign_translation)) {
|
||||
window.location.href = WPML_core.sanitize( tmEditorStrings.resign_url );
|
||||
}
|
||||
},
|
||||
cancel: function () {
|
||||
this.redirect_to_return_url('wpml_tm_cancel=1');
|
||||
},
|
||||
save_and_close: function () {
|
||||
var self = this;
|
||||
self.listenToOnce(self.model, 'saveJobSuccess', function () {
|
||||
self.setDirty(false);
|
||||
this.redirect_to_return_url('wpml_tm_saved=1');
|
||||
});
|
||||
|
||||
self.save();
|
||||
},
|
||||
redirect_to_return_url: function (param_string) {
|
||||
var url = WpmlTmEditorModel.return_url;
|
||||
if (url.indexOf('?') < 0) {
|
||||
url += '?' + param_string;
|
||||
} else {
|
||||
url += '&' + param_string;
|
||||
}
|
||||
window.location = WPML_core.sanitize( url );
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/footer.html'](tmEditorStrings));
|
||||
self.progressBar = self.$el.find('.js-progress-bar');
|
||||
self.translationComplete = self.$el.find(':checkbox[name=complete]');
|
||||
self.showProgressBar();
|
||||
self.maybeShowTranslationComplete();
|
||||
self.maybeHideHideCompletedSwitcher();
|
||||
|
||||
window.onbeforeunload = function (e) {
|
||||
if (self.isDirty()) {
|
||||
return tmEditorStrings.confirmNavigate;
|
||||
}
|
||||
};
|
||||
_.defer(_.bind(self.maybeShowDuplicateDialog, self));
|
||||
},
|
||||
maybeShowDuplicateDialog: function () {
|
||||
var self = this;
|
||||
if (WpmlTmEditorModel.is_duplicate) {
|
||||
self.dialog = new WPML_TM.editorEditIndependentlyDialog(self);
|
||||
}
|
||||
},
|
||||
showProgressBar: function () {
|
||||
|
||||
var self = this;
|
||||
self.progressBar.css('display', WpmlTmEditorModel.requires_translation_complete_for_each_field ? 'inline-block' : 'none');
|
||||
self.progressBar.find('.ui-progressbar-value').height(self.progressBar.find('.progress-bar-text').height());
|
||||
self.progressBar.progressbar({});
|
||||
var value = parseInt(self.model.progressPercentage(), 10);
|
||||
self.progressBar.find('.progress-bar-text').html(value + '% Complete');
|
||||
self.progressBar.find('.ui-progressbar-value').attr('data-progressbar-text', value + '% Complete');
|
||||
self.progressBar.progressbar({value: value});
|
||||
self.progressBar.find('.ui-progressbar-value').height(self.progressBar.find('.progress-bar-text').height());
|
||||
|
||||
return self;
|
||||
},
|
||||
setCompleteCheckBox: function () {
|
||||
var self = this;
|
||||
if (WpmlTmEditorModel.requires_translation_complete_for_each_field) {
|
||||
self.translationComplete.prop('checked', self.model.progressPercentage() === 100);
|
||||
}
|
||||
return self;
|
||||
},
|
||||
maybeShowTranslationComplete: function () {
|
||||
var self = this;
|
||||
if (WpmlTmEditorModel.requires_translation_complete_for_each_field) {
|
||||
self.translationComplete.parent().hide();
|
||||
} else {
|
||||
self.translationComplete.prop('checked', WpmlTmEditorModel.translation_is_complete);
|
||||
}
|
||||
},
|
||||
maybeHideHideCompletedSwitcher: function () {
|
||||
var self = this;
|
||||
if (!WpmlTmEditorModel.display_hide_completed_switcher) {
|
||||
self.$el.find('#wpml_tm_toggle_translated').parent().hide();
|
||||
}
|
||||
},
|
||||
progressBar: function () {
|
||||
return this.$el.find('.js-progress-bar');
|
||||
},
|
||||
setDirty: function (value) {
|
||||
this.model.set('is_dirty', value);
|
||||
},
|
||||
isDirty: function () {
|
||||
return this.model.get('is_dirty');
|
||||
},
|
||||
disableButtons: function (state) {
|
||||
this.$el.find('.js-save, .js-resign, .js-dialog-cancel, .js-save-and-close').prop('disabled', state);
|
||||
},
|
||||
disableSaveButtons: function (state) {
|
||||
this.$el.find('.js-save, .js-save-and-close').prop('disabled', state);
|
||||
},
|
||||
hideResignButton: function (state) {
|
||||
if (state) {
|
||||
this.$el.find('.js-resign').hide();
|
||||
} else {
|
||||
this.$el.find('.js-resign').show();
|
||||
}
|
||||
},
|
||||
toggleTranslated: function() {
|
||||
var toggle = this.$el.find('.js-toggle-translated');
|
||||
this.mainView.hideTranslated(toggle.is(':checked'));
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -0,0 +1,62 @@
|
||||
/*global Backbone, jQuery*/
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorGroupView = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'wpml-form-row wpml-field-group',
|
||||
events: {
|
||||
'click .js-button-copy-group': 'onCopy',
|
||||
'update_button_state .js-button-copy-group': 'setCopyButtonState'
|
||||
},
|
||||
render: function (group) {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/group.html'](group));
|
||||
},
|
||||
setup: function () {
|
||||
this.$el.find('.js-button-copy').css({visibility: 'hidden'});
|
||||
this.initializeGroupCopyButtons();
|
||||
this.setCopyButtonState();
|
||||
},
|
||||
initializeGroupCopyButtons: function () {
|
||||
|
||||
var self = this;
|
||||
|
||||
// Poistion the copy button so it's between the original and translation
|
||||
|
||||
self.$el.find('.js-button-copy:first').each(function () {
|
||||
|
||||
// center the button in group
|
||||
var groupCopyButton = self.$el.find('.js-button-copy-group');
|
||||
var firstButton = jQuery(this);
|
||||
var lastButton = self.$el.find('.js-button-copy:last');
|
||||
if (lastButton.length) {
|
||||
var groupHeight = lastButton.position().top + lastButton.height() - firstButton.position().top;
|
||||
var newTop = groupHeight / 2 - groupCopyButton.height() / 2;
|
||||
groupCopyButton.css({
|
||||
'position': 'relative',
|
||||
'top': newTop
|
||||
});
|
||||
}
|
||||
|
||||
groupCopyButton.insertAfter(firstButton);
|
||||
|
||||
// hide the original copy button
|
||||
firstButton.hide();
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
onCopy: function () {
|
||||
this.$el.find('.js-button-copy').trigger('click');
|
||||
},
|
||||
setCopyButtonState: function () {
|
||||
this.$el.find('.js-button-copy-group').prop('disabled', this.$el.find('.js-button-copy:disabled').length > 0);
|
||||
}
|
||||
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*global Backbone, jQuery*/
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorHeaderView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
||||
render: function () {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/header.html'](self.model));
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*global Backbone, jQuery*/
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorImageView = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'wpml-field-image',
|
||||
render: function (image) {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/image.html'](image));
|
||||
},
|
||||
setup: function () {
|
||||
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -0,0 +1,37 @@
|
||||
/*global Backbone, jQuery, _, tmEditor */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorBasicFieldView = WPML_TM.editorJobFieldView.extend({
|
||||
events: _.extend({
|
||||
'input .js-translated-value': 'onChange'
|
||||
}, WPML_TM.editorJobFieldView.prototype.events),
|
||||
|
||||
onChange: function () {
|
||||
tmEditor.model.trigger('translationUpdated', true);
|
||||
this.updateUI();
|
||||
},
|
||||
|
||||
getOriginal: function () {
|
||||
return this.$el.find('.js-original-value').val();
|
||||
},
|
||||
|
||||
getTranslation: function () {
|
||||
return this.$el.find('.js-translated-value').val();
|
||||
},
|
||||
|
||||
setTranslation: function (value) {
|
||||
this.$el.find('.js-translated-value').val(value);
|
||||
this.updateUI();
|
||||
},
|
||||
|
||||
setTranslatedColor: function(css) {
|
||||
this.$el.find('.js-translated-value').css(css);
|
||||
}
|
||||
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/*global Backbone, WpmlTmEditorModel, document, jQuery, _ */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorJobFieldView = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'wpml-form-row',
|
||||
events: {
|
||||
'click .icl_tm_copy_link': 'copyField',
|
||||
'click .js-toggle-diff': 'toggleDiff',
|
||||
'change .js-field-translation-complete' : 'setInputStatus'
|
||||
},
|
||||
toggleDiff: function(e) {
|
||||
e.preventDefault();
|
||||
var diff = this.$el.find('.diff');
|
||||
if(diff.is(':visible')) {
|
||||
diff.fadeOut();
|
||||
} else {
|
||||
diff.fadeIn();
|
||||
}
|
||||
this.updateUI();
|
||||
},
|
||||
copyField: function () {
|
||||
var self = this;
|
||||
self.setTranslation(self.getOriginal());
|
||||
return false;
|
||||
},
|
||||
updateUI: function () {
|
||||
var self = this;
|
||||
if (self.$el.is(':visible')) {
|
||||
try {
|
||||
var original = self.getOriginal();
|
||||
var translation = self.getTranslation();
|
||||
|
||||
self.$el.find('.icl_tm_copy_link').prop('disabled', translation !== '' || original === '');
|
||||
self.translationCompleteCheckbox.prop('disabled', translation === '');
|
||||
if ('' === translation) {
|
||||
self.translationCompleteCheckbox.prop('checked', false);
|
||||
self.translationCompleteCheckbox.trigger('change');
|
||||
}
|
||||
self.sendMessageToGroupView();
|
||||
jQuery(document).trigger('WPML_TM.editor.field_update_ui', self);
|
||||
}
|
||||
catch(err) {
|
||||
// this try - catch block is needed because this is sometimes called before tiny MCE editor is completely initialized
|
||||
}
|
||||
}
|
||||
},
|
||||
escapeHTML: function (string) {
|
||||
return string.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
||||
},
|
||||
render: function (field, labels) {
|
||||
var self = this;
|
||||
self.field = field;
|
||||
if (typeof self.field.title === 'undefined' || '' === self.field.title) {
|
||||
self.$el.removeClass('wpml-form-row').addClass('wpml-form-row-nolabel');
|
||||
}
|
||||
if (field.field_style !== WPML_TM.FIELD_STYLE_SINGLE_LINE) {
|
||||
self.field.field_data = self.escapeHTML(self.field.field_data);
|
||||
}
|
||||
self.$el.html(WPML_TM[self.getTemplate()]({
|
||||
field: self.field,
|
||||
labels: labels
|
||||
}));
|
||||
self.translationCompleteCheckbox = self.$el.find('.js-field-translation-complete');
|
||||
_.defer(_.bind(self.updateUI, self));
|
||||
if (WpmlTmEditorModel.hide_empty_fields && field.field_data === '') {
|
||||
self.$el.hide().addClass('hidden');
|
||||
self.translationCompleteCheckbox.prop('checked', true);
|
||||
self.translationCompleteCheckbox.prop('disabled', false);
|
||||
}
|
||||
if (!WpmlTmEditorModel.requires_translation_complete_for_each_field) {
|
||||
self.translationCompleteCheckbox.hide();
|
||||
self.translationCompleteCheckbox.parent().hide();
|
||||
}
|
||||
self.$el.find('.field-diff').find('.diff').hide();
|
||||
|
||||
self.setTranslatedColor( self.getStatusColors() );
|
||||
|
||||
jQuery(document).trigger('WPML_TM.editor.field_view_ready', self);
|
||||
},
|
||||
|
||||
setup: function () {
|
||||
},
|
||||
|
||||
sendMessageToGroupView: function () {
|
||||
var group = this.$el.closest('.wpml-field-group');
|
||||
if (group.length) {
|
||||
group.find('.js-button-copy-group').trigger('update_button_state');
|
||||
}
|
||||
},
|
||||
|
||||
getFieldType: function () {
|
||||
return this.field.field_type;
|
||||
},
|
||||
|
||||
setInputStatus: function() {
|
||||
var self = this;
|
||||
self.setTranslatedColor( self.getStatusColors() );
|
||||
_.delay( function () {
|
||||
jQuery( '.js-toggle-translated' ).trigger( 'change' );
|
||||
}, 1000 );
|
||||
},
|
||||
|
||||
getStatusColors: function () {
|
||||
var self = this;
|
||||
if (self.translationCompleteCheckbox.is(':checked')) {
|
||||
return {
|
||||
background: '#e8f7e3',
|
||||
borderColor: '#d0e9c6'
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
background: '',
|
||||
borderColor: ''
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
hideTranslated: function ( state ) {
|
||||
var self = this;
|
||||
if ( self.translationCompleteCheckbox.is( ':checked' ) && state ) {
|
||||
self.$el.hide();
|
||||
} else {
|
||||
if ( !self.$el.hasClass( 'hidden' ) ) {
|
||||
self.$el.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,15 @@
|
||||
/*global */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorSingleLineFieldView = WPML_TM.editorBasicFieldView.extend({
|
||||
|
||||
getTemplate: function () {
|
||||
return 'templates/translation-editor/single-line.html';
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,15 @@
|
||||
/*global */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorTextareaFieldView = WPML_TM.editorBasicFieldView.extend({
|
||||
|
||||
getTemplate: function () {
|
||||
return 'templates/translation-editor/textarea.html';
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,151 @@
|
||||
/*global jQuery, tinymce, tinyMCE, _, quicktags, tmEditor, WpmlTmEditorModel*/
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorWysiwygFieldView = WPML_TM.editorJobFieldView.extend({
|
||||
getTemplate: function () {
|
||||
return 'templates/translation-editor/wysiwyg.html';
|
||||
},
|
||||
|
||||
getOriginal: function () {
|
||||
return this.$el.find('textarea.original_value').text();
|
||||
},
|
||||
|
||||
getTranslation: function () {
|
||||
var self = this;
|
||||
var editor = tinymce.get(self.field.field_type);
|
||||
if (editor && editor instanceof tinyMCE.Editor && !editor.isHidden()) {
|
||||
return editor.getContent();
|
||||
} else {
|
||||
return self.getTextAreaElement().val();
|
||||
}
|
||||
},
|
||||
|
||||
setTranslation: function (value) {
|
||||
var self = this;
|
||||
|
||||
var editor = tinymce.get(self.field.field_type);
|
||||
var shouldToggle = editor && editor instanceof tinyMCE.Editor && !editor.isHidden();
|
||||
|
||||
if (shouldToggle) {
|
||||
tinymce.execCommand('mceToggleEditor', false, self.field.field_type);
|
||||
}
|
||||
|
||||
self.getTextAreaElement().val(value);
|
||||
|
||||
if (shouldToggle) {
|
||||
tinymce.execCommand('mceToggleEditor', false, self.field.field_type);
|
||||
}
|
||||
|
||||
this.updateUI();
|
||||
},
|
||||
|
||||
setup: function () {
|
||||
var self = this;
|
||||
self.replacePlaceHolder('original');
|
||||
self.replacePlaceHolder('translated');
|
||||
|
||||
self.$el.find('textarea.original_value').prop('readonly', true);
|
||||
self.getTextAreaElement().on('input', _.bind(self.updateUI, self));
|
||||
self.getTextAreaElement().on('input', function () {
|
||||
tmEditor.model.trigger('translationUpdated', true);
|
||||
});
|
||||
|
||||
if (!WpmlTmEditorModel.show_media_button) {
|
||||
self.$el.find('.wp-media-buttons').hide();
|
||||
}
|
||||
|
||||
_.delay(_.bind(self.waitForEditorAndThenInstallHooks, self, self.translationCompleteCheckbox.is( ':checked' )), 1000);
|
||||
|
||||
_.delay(_.bind(self.setInputStatus, self, 1000 ) );
|
||||
|
||||
},
|
||||
|
||||
getTextAreaElement: function () {
|
||||
return this.$el.find('textarea#' + this.field.field_type);
|
||||
},
|
||||
|
||||
waitForEditorAndThenInstallHooks: function (checked) {
|
||||
var self = this;
|
||||
var editor = tinymce.get(self.field.field_type);
|
||||
if (editor && editor instanceof tinyMCE.Editor) {
|
||||
editor.on('nodechange keyup', function (e) {
|
||||
var lazyOnChange = _.debounce(_.bind(self.updateUI, self), 1000);
|
||||
lazyOnChange(editor);
|
||||
editor.save();
|
||||
});
|
||||
|
||||
editor.on('change', function (e) {
|
||||
tmEditor.model.trigger('translationUpdated', true);
|
||||
});
|
||||
_.delay(function () {
|
||||
self.$el.find('.mce_editor_origin .mce-toolbar-grp').height(self.$el.find('.mce_editor .mce-toolbar-grp').height());
|
||||
}, 1000);
|
||||
self.setRtlAttributes(editor);
|
||||
self.setOriginalBackgroundGray( editor );
|
||||
|
||||
if( checked ) {
|
||||
self.translationCompleteCheckbox.prop('checked', true);
|
||||
self.translationCompleteCheckbox.prop('disabled', false);
|
||||
self.translationCompleteCheckbox.trigger('change');
|
||||
}
|
||||
} else {
|
||||
_.delay(_.bind(self.waitForEditorAndThenInstallHooks, self), 1000);
|
||||
}
|
||||
},
|
||||
|
||||
replacePlaceHolder: function (type) {
|
||||
var self = this;
|
||||
var $placeholder = self.$el.find('#' + type + '_' + self.field.field_type + '_placeholder');
|
||||
jQuery('#' + self.field.field_type + '_' + type + '_editor').detach().insertAfter($placeholder);
|
||||
$placeholder.remove();
|
||||
},
|
||||
setRtlAttributes: function (editor) {
|
||||
var self = this, dir, body, html;
|
||||
|
||||
dir = WpmlTmEditorModel.rtl_translation ? 'rtl' : 'ltr';
|
||||
html = jQuery(editor.iframeElement).contents().find('html');
|
||||
html.attr('dir', dir);
|
||||
body = html.find('body');
|
||||
if (body.length) {
|
||||
body.attr('dir', dir);
|
||||
}
|
||||
self.getTextAreaElement().attr('dir', dir);
|
||||
|
||||
dir = WpmlTmEditorModel.rtl_original ? 'rtl' : 'ltr';
|
||||
html = self.$el.find('.mce_editor_origin').find('iframe').contents().find('html');
|
||||
html.attr('dir', dir);
|
||||
body = html.find('body');
|
||||
if (body.length) {
|
||||
body.attr('dir', dir);
|
||||
}
|
||||
self.$el.find('textarea.original_value').attr('dir', dir);
|
||||
},
|
||||
setOriginalBackgroundGray: function ( editor ) {
|
||||
var self = this,
|
||||
html = self.$el.find( '.mce_editor_origin' ).find( 'iframe' ).contents().find( 'html' ),
|
||||
body = html.find('body'),
|
||||
sizer = self.$el.find( '.mce_editor_origin' ).find( '.mce-statusbar' ).find( '.mce-flow-layout' );
|
||||
|
||||
body.css( 'background-color', '#eee' );
|
||||
sizer.css( 'background-color', '#eee' );
|
||||
},
|
||||
setTranslatedColor: function ( css ) {
|
||||
var input = this.$el.find( '.translated_value' ),
|
||||
html = input.find( 'iframe' ).contents().find( 'html' ),
|
||||
body = html.find( 'body' ),
|
||||
sizer = input.find( '.mce-statusbar' ).find( '.mce-flow-layout' ),
|
||||
textArea = input.find( '.translated_value' );
|
||||
|
||||
body.css( 'background-color', css.background );
|
||||
sizer.css( 'background-color', css.background );
|
||||
textArea.css( 'background-color', css.background );
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}());
|
||||
@@ -0,0 +1,56 @@
|
||||
/*global _, Backbone, jQuery, WpmlTmEditorModel, ajaxurl */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorJob = Backbone.Model.extend({
|
||||
fetch: function (successCallback) {
|
||||
var self = this;
|
||||
|
||||
_.each(WpmlTmEditorModel.fields, function (field) {
|
||||
field.field_finished = parseInt(field.field_finished, 10);
|
||||
self.set(field.field_type, field.field_data);
|
||||
self.set(field.field_type + '_raw', field);
|
||||
});
|
||||
self.set('layout', WpmlTmEditorModel.layout);
|
||||
successCallback();
|
||||
},
|
||||
save: function (data) {
|
||||
var self = this;
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: self.url(),
|
||||
dataType: 'json',
|
||||
data: {
|
||||
data: data,
|
||||
action: 'wpml_save_job_ajax',
|
||||
_icl_nonce: self.get('nonce')
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
self.trigger('saveJobSuccess');
|
||||
} else {
|
||||
self.trigger('saveJobFailed');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
progressPercentage: function () {
|
||||
|
||||
return jQuery('.icl_tm_finished:checked:visible').length / jQuery('.icl_tm_finished:visible').length * 100;
|
||||
},
|
||||
/**
|
||||
* Overrides the BackBone url method to use the WordPress ajax endpoint
|
||||
*
|
||||
* @returns {String}
|
||||
*/
|
||||
url: function () {
|
||||
|
||||
return ajaxurl;
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*global Backbone */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorLanguagesView = Backbone.View.extend({
|
||||
tagName: 'header',
|
||||
className: 'wpml-translation-header',
|
||||
events: {
|
||||
'click .js-button-copy-all': 'copyAll'
|
||||
},
|
||||
initialize: function (options) {
|
||||
this.mainView = options.mainView;
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/languages.html'](self.model));
|
||||
},
|
||||
copyAll: function () {
|
||||
var copyAllTask = new WPML_TM.editorCopyAll(this.mainView);
|
||||
copyAllTask.copy();
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -0,0 +1,210 @@
|
||||
/*global _, Backbone, WpmlTmEditorModel, tmEditorStrings, jQuery, tmEditor, document */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorMainView = Backbone.View.extend({
|
||||
events: {
|
||||
'change .icl_tm_finished': 'updateState'
|
||||
},
|
||||
updateState: function () {
|
||||
var self = this;
|
||||
self.footerView.showProgressBar().setCompleteCheckBox();
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
var job_type = jQuery('input[name="job_post_type"]').val();
|
||||
self.fieldViews = [];
|
||||
|
||||
self.translationMemory = null;
|
||||
|
||||
if (
|
||||
WpmlTmEditorModel.translation_memory
|
||||
&& tmEditorStrings.translationMemoryNonce
|
||||
&& tmEditorStrings.translationMemoryEndpoint
|
||||
) {
|
||||
self.translationMemory = new WPML_TM.translationMemory( WpmlTmEditorModel.languages );
|
||||
}
|
||||
|
||||
jQuery('#screen-meta-links').hide();
|
||||
|
||||
jQuery(document).trigger('WPML_TM.editor.before_render', [job_type] );
|
||||
|
||||
self.addHeaderView();
|
||||
self.addNoteView();
|
||||
self.addLanguagesView();
|
||||
|
||||
self.model.fetch(function () {
|
||||
self.addFields(self.model.get('layout'), self.$el.find('#wpml-translation-editor-wrapper'));
|
||||
self.addFooterView();
|
||||
|
||||
jQuery(document).trigger('WPML_TM.editor.ready', [job_type, self.fieldViews, self.footerView]);
|
||||
});
|
||||
self.updateState();
|
||||
|
||||
if ( self.translationMemory ) {
|
||||
self.translationMemory.fetch();
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
addFields: function (fields, $location) {
|
||||
var self = this;
|
||||
_.each(fields, function (field) {
|
||||
if (typeof field == 'string') {
|
||||
self.fieldViews.push(self.createFieldView(field, $location));
|
||||
} else if (field.field_type == 'tm-section') {
|
||||
self.createSection(field, $location);
|
||||
} else if (field.field_type == 'tm-group') {
|
||||
self.createGroup(field, $location);
|
||||
} else if (field.field_type == 'wcml-image') {
|
||||
self.createImage(field, $location);
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
createFieldView: function (field, $location) {
|
||||
var self = this;
|
||||
field = self.model.get(field + '_raw');
|
||||
var view = WPML_TM.fieldViewFactory.create(field, {
|
||||
id: 'job_field_' + field.field_type,
|
||||
job_id: self.model.get('job_id')
|
||||
});
|
||||
view.render(self.model.get(field.field_type + '_raw'), tmEditorStrings);
|
||||
$location.last().append(view.$el);
|
||||
view.setup();
|
||||
|
||||
if ( self.translationMemory ) {
|
||||
self.translationMemory.addField( field, view );
|
||||
}
|
||||
|
||||
return view;
|
||||
},
|
||||
createSection: function (field, $location) {
|
||||
var self = this;
|
||||
var view = new WPML_TM.editorSectionView({
|
||||
job_id: self.model.get('job_id')
|
||||
});
|
||||
view.render(field);
|
||||
$location.last().append(view.$el);
|
||||
self.addFields(field.fields, view.$el.find('.inside'));
|
||||
},
|
||||
createGroup: function (field, $location) {
|
||||
var self = this;
|
||||
var view = new WPML_TM.editorGroupView({
|
||||
job_id: self.model.get('job_id')
|
||||
});
|
||||
view.render(field);
|
||||
$location.last().append(view.$el);
|
||||
self.addFields(field.fields, view.$el.find('.inside'));
|
||||
view.setup();
|
||||
},
|
||||
createImage: function (field, $location) {
|
||||
var self = this;
|
||||
var view = new WPML_TM.editorImageView({
|
||||
job_id: self.model.get('job_id')
|
||||
});
|
||||
view.render(field);
|
||||
$location.last().append(view.$el);
|
||||
self.addFields(field.fields, view.$el.find('.inside'));
|
||||
view.setup();
|
||||
},
|
||||
addHeaderView: function () {
|
||||
var self = this;
|
||||
var headerView = new WPML_TM.editorHeaderView({
|
||||
model: WpmlTmEditorModel.header
|
||||
});
|
||||
headerView.render();
|
||||
self.appendToDom(headerView);
|
||||
},
|
||||
addNoteView: function () {
|
||||
var self = this;
|
||||
if (WpmlTmEditorModel.note) {
|
||||
var noteView = new WPML_TM.editorNoteView({
|
||||
model: WpmlTmEditorModel
|
||||
});
|
||||
noteView.render();
|
||||
self.appendToDom(noteView);
|
||||
}
|
||||
},
|
||||
addLanguagesView: function () {
|
||||
var self = this;
|
||||
self.languagesView = new WPML_TM.editorLanguagesView({
|
||||
model: {
|
||||
language: WpmlTmEditorModel.languages,
|
||||
labels: tmEditorStrings
|
||||
},
|
||||
mainView: self
|
||||
});
|
||||
self.languagesView.render();
|
||||
self.appendToDom(self.languagesView);
|
||||
},
|
||||
addFooterView: function () {
|
||||
var self = this;
|
||||
self.footerView = new WPML_TM.editorFooterView({
|
||||
model: tmEditor.model,
|
||||
mainView: self
|
||||
});
|
||||
self.footerView.render();
|
||||
self.appendToDom(self.footerView);
|
||||
},
|
||||
appendToDom: function (view) {
|
||||
var self = this;
|
||||
if (view instanceof WPML_TM.editorHeaderView) {
|
||||
self.$el.find('#wpml-translation-editor-header').last().append(view.$el);
|
||||
} else {
|
||||
self.$el.find('#wpml-translation-editor-wrapper').last().append(view.$el);
|
||||
}
|
||||
},
|
||||
hasTranslations: function () {
|
||||
var self = this;
|
||||
var hasTranslation = false;
|
||||
_.each( self.fieldViews, function ( view ) {
|
||||
if ( ! hasTranslation) {
|
||||
if ( view.getTranslation() !== '' && view.getTranslation() !== view.getOriginal() ) {
|
||||
hasTranslation = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return hasTranslation;
|
||||
},
|
||||
copyOriginalOverwrite: function () {
|
||||
var self = this;
|
||||
_.each(self.fieldViews, function (view) {
|
||||
view.copyField();
|
||||
});
|
||||
},
|
||||
copyOriginalDontOverwrite: function () {
|
||||
var self = this;
|
||||
_.each(self.fieldViews, function (view) {
|
||||
if (view.getTranslation() === '') {
|
||||
view.copyField();
|
||||
}
|
||||
});
|
||||
},
|
||||
hideTranslated: function (state) {
|
||||
var self = this;
|
||||
_.each(self.fieldViews, function (view) {
|
||||
view.hideTranslated(state);
|
||||
});
|
||||
self.hideEmptyGroups();
|
||||
},
|
||||
hideEmptyGroups: function () {
|
||||
jQuery('.postbox').each( function () {
|
||||
var elements = jQuery('[class*="wpml-form-row"]', jQuery(this));
|
||||
var hiddenElements = elements.filter( function () {
|
||||
return jQuery(this).css('display') === 'none';
|
||||
} );
|
||||
if ( elements.length === hiddenElements.length ) {
|
||||
jQuery(this).hide();
|
||||
} else {
|
||||
jQuery(this).show();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*global Backbone */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorNoteView = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'wpml-form-row wpml-note',
|
||||
|
||||
render: function () {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/note.html'](self.model));
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -0,0 +1,28 @@
|
||||
/*global Backbone, tmEditorStrings */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorSectionView = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'postbox',
|
||||
events: {
|
||||
'click .handlediv': 'showHideSection',
|
||||
'click .hndle': 'showHideSection'
|
||||
},
|
||||
|
||||
render: function (field) {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/section.html']({
|
||||
section: field,
|
||||
labels: tmEditorStrings
|
||||
}));
|
||||
},
|
||||
showHideSection: function () {
|
||||
this.$el.toggleClass('closed');
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,78 @@
|
||||
/*jshint devel:true */
|
||||
/*global jQuery, ajaxurl, tmEditorStrings */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.translationMemory = function ( languages ) {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
var init = function ( languages ) {
|
||||
self.strings = {};
|
||||
self.languages = languages;
|
||||
};
|
||||
|
||||
var hasTranslation = function ( field ) {
|
||||
return '' === field.field_data || '' !== field.field_data_translated || 0 !== field.field_finished;
|
||||
};
|
||||
|
||||
var updateViewWithTranslation = function ( data ) {
|
||||
if ( data.original in self.strings ) {
|
||||
for ( var i = 0; i < self.strings[ data.original ].length; i++ ) {
|
||||
var view = self.strings[ data.original ][ i ];
|
||||
if ( view.getTranslation() === '' ) {
|
||||
view.setTranslation( data.translation );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.addField = function ( field, view ) {
|
||||
if ( !hasTranslation( field ) ) {
|
||||
|
||||
var string = field.field_data;
|
||||
if ( !(string in self.strings) ) {
|
||||
self.strings[ string ] = [];
|
||||
}
|
||||
self.strings[ string ].push( view );
|
||||
}
|
||||
};
|
||||
|
||||
self.fetch = function () {
|
||||
var strings = [];
|
||||
|
||||
for ( var key in self.strings ) {
|
||||
if ( self.strings.hasOwnProperty( key ) ) {
|
||||
strings.push( {string: key, source: self.languages['source'], target: self.languages['target']} );
|
||||
}
|
||||
}
|
||||
if ( strings.length > 0 ) {
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
data: JSON.stringify({ batch: true, strings: strings }),
|
||||
action: 'wpml_action',
|
||||
nonce: tmEditorStrings.translationMemoryNonce,
|
||||
endpoint: tmEditorStrings.translationMemoryEndpoint
|
||||
},
|
||||
success: function ( response ) {
|
||||
if ( response.success ) {
|
||||
var data = response.data;
|
||||
for ( var i = 0; i < data.length; i++ ) {
|
||||
if ( data[i].length > 0 ) {
|
||||
updateViewWithTranslation( data[i][0] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
init( languages );
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global jQuery, wp */
|
||||
(function($){
|
||||
"use strict";
|
||||
|
||||
$(function () {
|
||||
|
||||
var section = $('#wpml-translation-feedback-options'),
|
||||
enableToggle = section.find('#wpml-tf-enable-translation-feedback'),
|
||||
displayMode = section.find('input[name="display_mode"]'),
|
||||
saveTriggers = section.find('.js-wpml-tf-trigger-save');
|
||||
|
||||
var saveSettings = function (node) {
|
||||
var spinner = node.closest('.js-wpml-tf-settings-block').find('.spinner'),
|
||||
message = node.closest('.js-wpml-tf-settings-block').find('.js-wpml-tf-request-status').empty(),
|
||||
settings = getSerializedSettings();
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
wp.ajax.send({
|
||||
data: {
|
||||
action: section.data('action'),
|
||||
nonce: section.data('nonce'),
|
||||
settings: settings
|
||||
},
|
||||
success: function (data) {
|
||||
spinner.removeClass('is-active');
|
||||
message.html(data).fadeIn().delay(3000).fadeOut();
|
||||
},
|
||||
error: function (data) {
|
||||
spinner.removeClass('is-active');
|
||||
message.html(data).fadeIn().delay(3000).fadeOut();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var getSerializedSettings = function() {
|
||||
var form = section.find('form'),
|
||||
disabled = form.find(':input:disabled').prop('disabled', false),
|
||||
settings = form.find('input, select, textarea').serialize();
|
||||
|
||||
disabled.prop('disabled', true);
|
||||
|
||||
return settings;
|
||||
};
|
||||
|
||||
enableToggle.on('change', function() {
|
||||
section.find('.js-wpml-tf-full-options').slideToggle();
|
||||
});
|
||||
|
||||
displayMode.on('change', function() {
|
||||
var customDisplayMode = section.find('#wpml_tf_display_mode_custom');
|
||||
|
||||
if (customDisplayMode.is(':checked')) {
|
||||
customDisplayMode.closest('li').find('select').prop('disabled', false);
|
||||
} else {
|
||||
customDisplayMode.closest('li').find('select').prop('disabled', true);
|
||||
}
|
||||
});
|
||||
|
||||
saveTriggers.on('change', function() {
|
||||
saveSettings($(this));
|
||||
});
|
||||
|
||||
});
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,190 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global jQuery, wp */
|
||||
(function($){
|
||||
"use strict";
|
||||
|
||||
$(function () {
|
||||
var table = $('.js-wpml-tf-feedback-list-table'),
|
||||
ajax_action = $('.wpml-tf-feedback-list-page input[name="ajax_action"]').val(),
|
||||
ajax_nonce = $('.wpml-tf-feedback-list-page input[name="ajax_nonce"]').val();
|
||||
|
||||
var openFeedbackDetails = function (feedbackId) {
|
||||
table.find('#wpml-tf-feedback-' + feedbackId).hide();
|
||||
table.find('#wpml-tf-feedback-details-' + feedbackId).show();
|
||||
};
|
||||
|
||||
var closeAllFeedbackDetails = function () {
|
||||
table.find('.js-wpml-tf-feedback-details').hide();
|
||||
table.find('.js-wpml-tf-feedback').show();
|
||||
};
|
||||
|
||||
var getFeedbackNode = function(el) {
|
||||
return $(el).closest('.js-wpml-tf-feedback-details, .js-wpml-tf-feedback');
|
||||
};
|
||||
|
||||
var getFeedbackId = function(el) {
|
||||
return getFeedbackNode(el).data('feedback-id');
|
||||
};
|
||||
|
||||
var getFeedbackContentUpdate = function(node) {
|
||||
var newContentNode = node.find('.js-wpml-tf-edit-feedback'),
|
||||
originalContent = node.find('.js-wpml-tf-readonly-feedback').text();
|
||||
|
||||
if ( newContentNode.length && originalContent !== newContentNode.val() ) {
|
||||
return newContentNode.val();
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
var getFeedbackReviewerId = function(node) {
|
||||
var reviewerNode = node.find('.js-wpml-tf-reviewer');
|
||||
|
||||
if ( reviewerNode.length ) {
|
||||
return parseInt(reviewerNode.val());
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
var getFeedbackMessage = function(node) {
|
||||
var newMessage = node.find('.js-wpml-tf-new-message').val();
|
||||
|
||||
if ( newMessage ) {
|
||||
return newMessage;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
var submitActionOnFeedback = function(id, action) {
|
||||
var currentURL = WPML_core.sanitize( window.location.href ),
|
||||
params = {
|
||||
nonce: WPML_core.sanitize(table.closest('form').find('input[name="nonce"]').val()),
|
||||
bulk_action: action,
|
||||
bulk_action2: action,
|
||||
feedback_ids: [ id ],
|
||||
};
|
||||
|
||||
window.location = currentURL + '&' + $.param(params);
|
||||
};
|
||||
|
||||
var sendRequest = function(node, data, reload) {
|
||||
var spinner = node.find('.spinner'),
|
||||
error_notification = node.find('.js-wpml-tf-feedback-details-error').empty();
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
data.action = ajax_action;
|
||||
data.nonce = ajax_nonce;
|
||||
data.feedback_id = getFeedbackId(node);
|
||||
|
||||
wp.ajax.send({
|
||||
data: data,
|
||||
success: function (response) {
|
||||
if (reload) {
|
||||
window.location.href = WPML_core.sanitize(window.location.pathname + window.location.search + window.location.hash);
|
||||
} else {
|
||||
spinner.removeClass('is-active');
|
||||
refreshFeedbackRows(data.feedback_id, response);
|
||||
}
|
||||
},
|
||||
error: function (error_message) {
|
||||
spinner.removeClass('is-active');
|
||||
error_notification.html(error_message).fadeIn();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var refreshFeedbackRows = function(feedbackId, data) {
|
||||
var summary = $.parseHTML(data.summary_row),
|
||||
details = $.parseHTML(data.details_row);
|
||||
|
||||
table.find('#wpml-tf-feedback-' + feedbackId).first().replaceWith(summary);
|
||||
table.find('#wpml-tf-feedback-details-' + feedbackId).first().replaceWith(details);
|
||||
};
|
||||
|
||||
var attachEvents = function() {
|
||||
table.on( 'click', '.js-wpml-tf-open-details', function(e) {
|
||||
e.preventDefault();
|
||||
closeAllFeedbackDetails();
|
||||
openFeedbackDetails(getFeedbackId(this));
|
||||
}).on( 'click', '.js-wpml-tf-cancel', function(e) {
|
||||
e.preventDefault();
|
||||
closeAllFeedbackDetails();
|
||||
}).on( 'click', '.js-wpml-tf-enable-translator-note', function(e) {
|
||||
e.preventDefault();
|
||||
var trigger = $(this);
|
||||
trigger.siblings('.js-wpml-tf-translator-note').show();
|
||||
trigger.remove();
|
||||
}).on( 'click', '.js-wpml-tf-enable-edit-feedback', function(e) {
|
||||
e.preventDefault();
|
||||
var trigger = $(this);
|
||||
trigger.siblings('.js-wpml-tf-readonly-feedback').hide();
|
||||
trigger.siblings('.js-wpml-tf-edit-feedback').show();
|
||||
trigger.remove();
|
||||
}).on( 'click', '.js-wpml-tf-send', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var node = getFeedbackNode(this),
|
||||
data = {
|
||||
edit_action: 'update_feedback'
|
||||
};
|
||||
|
||||
if (getFeedbackContentUpdate(node)) {
|
||||
data.feedback_content = getFeedbackContentUpdate(node);
|
||||
}
|
||||
|
||||
if (getFeedbackReviewerId(node)) {
|
||||
data.feedback_reviewer_id = getFeedbackReviewerId(node);
|
||||
}
|
||||
|
||||
if (getFeedbackMessage(node)) {
|
||||
data.message_content = getFeedbackMessage(node);
|
||||
}
|
||||
|
||||
data.feedback_status = $(this).val();
|
||||
|
||||
if (node.find('.js-wpml-tf-translation-fixed-checkbox:checked').length > 0) {
|
||||
data.feedback_status = 'fixed';
|
||||
}
|
||||
|
||||
sendRequest(node, data);
|
||||
}).on('click', '.js-wpml-tf-refresh-status', function(e) {
|
||||
e.preventDefault();
|
||||
var node = getFeedbackNode(this),
|
||||
data = {
|
||||
edit_action: 'update_feedback',
|
||||
feedback_status: 'sent_to_ts_api'
|
||||
};
|
||||
|
||||
sendRequest(node, data);
|
||||
}).on('click', '.js-wpml-tf-translation-fixed', function(e) {
|
||||
e.preventDefault();
|
||||
var node = getFeedbackNode(this),
|
||||
data = {
|
||||
edit_action: 'update_feedback',
|
||||
feedback_status: 'fixed'
|
||||
};
|
||||
|
||||
sendRequest(node, data);
|
||||
}).on('click', '.js-wpml-tf-error-details a', function(e) {
|
||||
e.preventDefault();
|
||||
$(this).siblings('pre').show();
|
||||
$(this).remove();
|
||||
}).on('click', '.js-wpml-tf-trash', function(e) {
|
||||
e.preventDefault();
|
||||
submitActionOnFeedback(getFeedbackId(this), 'trash');
|
||||
}).on('click', '.js-wpml-tf-untrash', function(e) {
|
||||
e.preventDefault();
|
||||
submitActionOnFeedback(getFeedbackId(this), 'untrash');
|
||||
}).on('click', '.js-wpml-tf-delete', function(e) {
|
||||
e.preventDefault();
|
||||
submitActionOnFeedback(getFeedbackId(this), 'delete');
|
||||
});
|
||||
};
|
||||
|
||||
attachEvents();
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,146 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global jQuery, wp */
|
||||
(function($){
|
||||
"use strict";
|
||||
|
||||
$(function () {
|
||||
var form = $('.js-wpml-tf-feedback-form'),
|
||||
openIcon = $('.js-wpml-tf-feedback-icon'),
|
||||
ratingInput = form.find('input[name="wpml-tf-rating"]'),
|
||||
sendButton = form.find('.js-wpml-tf-comment-button'),
|
||||
documentId = form.find('input[name="document_id"]').val(),
|
||||
documentType = form.find('input[name="document_type"]').val(),
|
||||
action = form.find('input[name="action"]').val(),
|
||||
nonce = form.find('input[name="nonce"]').val(),
|
||||
noCommentThreshold = 4,
|
||||
dialogInitialized = false,
|
||||
feedbackId;
|
||||
|
||||
var disableRating = function() {
|
||||
ratingInput.prop('disabled', true);
|
||||
};
|
||||
|
||||
var enableRating = function() {
|
||||
if(feedbackId && !form.hasClass('wpml-tf-closing-rating')) {
|
||||
ratingInput.prop('disabled', false);
|
||||
}
|
||||
};
|
||||
|
||||
var enableComment = function() {
|
||||
sendButton.prop('disabled', false);
|
||||
};
|
||||
|
||||
var displayClosingComment = function() {
|
||||
form.removeClass('wpml-tf-pending-comment').addClass('wpml-tf-closing-comment');
|
||||
window.setTimeout(destroyDialogAndButton, 3000);
|
||||
};
|
||||
|
||||
var displayPendingComment = function() {
|
||||
form.addClass('wpml-tf-pending-comment').removeClass('wpml-tf-closing-rating');
|
||||
enableRating();
|
||||
};
|
||||
|
||||
var displayClosingRating = function() {
|
||||
form.addClass('wpml-tf-closing-rating').removeClass('wpml-tf-pending-comment');
|
||||
disableRating();
|
||||
};
|
||||
|
||||
var displayPendingRating = function() {
|
||||
form.removeClass('wpml-tf-closing-rating').removeClass('wpml-tf-pending-comment');
|
||||
enableRating();
|
||||
};
|
||||
|
||||
var sendFeedback = function(data) {
|
||||
var options;
|
||||
|
||||
if ( ! itLooksLikeSpam() ) {
|
||||
disableRating();
|
||||
form.addClass('wpml-tf-pending-request');
|
||||
|
||||
data.nonce = nonce;
|
||||
data.document_id = documentId;
|
||||
data.document_type = documentType;
|
||||
|
||||
options = {
|
||||
data: data,
|
||||
success: function(data) {
|
||||
feedbackId = data.feedback_id;
|
||||
form.addClass('wpml-tf-has-feedback-id').removeClass('wpml-tf-pending-request');
|
||||
enableRating();
|
||||
enableComment();
|
||||
}
|
||||
};
|
||||
|
||||
wp.ajax.send(action, options);
|
||||
}
|
||||
};
|
||||
|
||||
var itLooksLikeSpam = function() {
|
||||
var more_comment = form.find('textarea[name="more_comment"]');
|
||||
return ! dialogInitialized || more_comment.val();
|
||||
};
|
||||
|
||||
var openForm = function() {
|
||||
form.dialog({
|
||||
dialogClass: 'wpml-tf-feedback-form-dialog otgs-ui-dialog',
|
||||
closeOnEscape: true,
|
||||
draggable: true,
|
||||
modal: false,
|
||||
title: form.data('dialog-title'),
|
||||
dragStop: function() {
|
||||
$(this).parent().height('auto');
|
||||
}
|
||||
});
|
||||
|
||||
dialogInitialized = true;
|
||||
|
||||
// Fix display glitch with bootstrap.js
|
||||
$('.wpml-tf-feedback-form-dialog').find('.ui-dialog-titlebar-close').addClass('ui-button');
|
||||
};
|
||||
|
||||
var destroyDialogAndButton = function() {
|
||||
form.dialog( 'destroy' );
|
||||
openIcon.remove();
|
||||
};
|
||||
|
||||
openIcon.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
openForm();
|
||||
});
|
||||
|
||||
ratingInput.on('click', function() {
|
||||
var data = {
|
||||
rating: $(this).val()
|
||||
};
|
||||
|
||||
if ( feedbackId ) {
|
||||
data.feedback_id = feedbackId;
|
||||
}
|
||||
|
||||
sendFeedback(data);
|
||||
|
||||
if(data.rating < noCommentThreshold) {
|
||||
displayPendingComment();
|
||||
} else {
|
||||
displayClosingRating();
|
||||
}
|
||||
});
|
||||
|
||||
form.on('click', '.js-wpml-tf-change-rating', function(e) {
|
||||
e.preventDefault();
|
||||
displayPendingRating();
|
||||
});
|
||||
|
||||
sendButton.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var data = {
|
||||
content: $('textarea[name="wpml-tf-comment"]').val(),
|
||||
feedback_id: feedbackId
|
||||
};
|
||||
|
||||
sendFeedback(data);
|
||||
displayClosingComment();
|
||||
});
|
||||
|
||||
});
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,6 @@
|
||||
/*globals iclSaveForm*/
|
||||
jQuery(function () {
|
||||
jQuery('#icl_page_sync_options').submit(iclSaveForm);
|
||||
jQuery('form[name="icl_custom_tax_sync_options"]').submit(iclSaveForm);
|
||||
jQuery('form[name="icl_custom_posts_sync_options"]').submit(iclSaveForm);
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
jQuery(function () {
|
||||
jQuery('*[data-tp-enabled="0"]').hide();
|
||||
jQuery('.wpml_tp_custom_dismiss_able').click(icl_dismiss_custom_text);
|
||||
});
|
||||
|
||||
function icl_dismiss_custom_text() {
|
||||
var item = jQuery(this);
|
||||
item.parentNode.parentNode.removeChild(item.parentNode);
|
||||
jQuery.ajax({
|
||||
type:'POST',
|
||||
url : item.href,
|
||||
success: function(msg){
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user