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