first commit
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user