diff --git a/includes/class-gp-translation-helpers.php b/includes/class-gp-translation-helpers.php index bb4d41a2..59d09835 100644 --- a/includes/class-gp-translation-helpers.php +++ b/includes/class-gp-translation-helpers.php @@ -420,14 +420,20 @@ public function register_comment_feedback_js( $template, $translation_set ) { ); gp_enqueue_scripts( array( 'gp-translation-helpers-editor' ) ); + $vars = array( + 'translation_helper_url' => gp_url_project( $translation_set['project']->path, gp_url_join( $translation_set['locale_slug'], $translation_set['translation_set']->slug, '-get-translation-helpers' ) ), + 'reply_text' => esc_attr__( 'Reply' ), + 'cancel_reply_text' => esc_html__( 'Cancel reply' ), + ); wp_localize_script( 'gp-translation-helpers-editor', '$gp_translation_helpers_editor', - array( - 'translation_helper_url' => gp_url_project( $translation_set['project']->path, gp_url_join( $translation_set['locale_slug'], $translation_set['translation_set']->slug, '-get-translation-helpers' ) ), - 'reply_text' => esc_attr__( 'Reply' ), - 'cancel_reply_text' => esc_html__( 'Cancel reply' ), - ) + $vars + ); + wp_localize_script( + 'gp-translation-helpers-editor', + '$gp_translation_helpers_editor_' . $translation_set['translation_set']->id, + $vars ); wp_localize_script( 'gp-translation-helpers-editor', diff --git a/js/editor.js b/js/editor.js index 52c66976..9b375b98 100644 --- a/js/editor.js +++ b/js/editor.js @@ -11,7 +11,7 @@ jQuery( function( $ ) { let focusedRowId = ''; // When a user clicks on a sidebar tab, the visible tab and div changes. - $gp.editor.table.on( 'click', '.sidebar-tabs li', function() { + $( document ).on( 'click', '.sidebar-tabs li', function() { const tab = $( this ); const tabId = tab.attr( 'data-tab' ); const divId = tabId.replace( 'tab', 'div' ); @@ -23,7 +23,7 @@ jQuery( function( $ ) { // When a new translation row is opened (with double click, clicking in the "Details" button, // or with the hotkeys), the translation textarea is focused, so the tabs (header tabs and // divs with the content) for the right sidebar are updated. - $gp.editor.table.on( 'focus', 'tr.editor textarea.foreign-text', function() { + $( document ).on( 'focus', 'tr.editor textarea.foreign-text', function() { const tr = $( this ).closest( 'tr.editor' ); const rowId = tr.attr( 'row' ); const translation_status = tr.find( '.panel-header' ).find( 'span' ).html(); @@ -48,7 +48,7 @@ jQuery( function( $ ) { } } ); - $gp.editor.table.on( 'click', 'a.retry-auto-review', function( event ) { + $( document ).on( 'click', 'a.retry-auto-review', function( event ) { const tr = $( this ).closest( 'tr.editor' ); const rowId = tr.attr( 'row' ); event.preventDefault(); @@ -74,7 +74,7 @@ jQuery( function( $ ) { } ); // Shows/hides the reply form for a comment in the discussion. - $gp.editor.table.on( 'click', 'a.comment-reply-link', function( event ) { + $( document ).on( 'click', 'a.comment-reply-link', function( event ) { const commentId = $( this ).attr( 'data-commentid' ); event.preventDefault(); $( '#comment-reply-' + commentId ).toggle().find( 'textarea' ).focus(); @@ -110,7 +110,7 @@ jQuery( function( $ ) { } // Sends the new comment or the reply to an existing comment. - $gp.editor.table.on( 'submit', '.meta.discussion .comment-form', function( e ) { + $( document ).on( 'submit', '.meta.discussion .comment-form', function( e ) { const $commentform = $( e.target ); const postId = $commentform.attr( 'id' ).split( '-' )[ 1 ]; const divDiscussion = $commentform.closest( '.meta.discussion' ); @@ -178,7 +178,7 @@ jQuery( function( $ ) { } ); // Copies the translation from another language to the current translation. - $gp.editor.table.on( 'click', 'button.sidebar-other-locales', function() { + $( document ).on( 'click', 'button.sidebar-other-locales', function() { const textToCopy = $( this ).closest( 'li' ).find( 'a' ).text(); const textareaToPaste = $( this ).closest( '.editor' ).find( 'textarea.foreign-text' ); let selectionStart = textareaToPaste.get( 0 ).selectionStart;