From f808ff33cbfb375c97a6363b92f87486be1944cd Mon Sep 17 00:00:00 2001 From: Django Doucet Date: Sun, 1 Oct 2023 11:38:37 -0600 Subject: [PATCH] Separate comment reply script --- assets/js/activitypub-admin.js | 16 ---------------- assets/js/activitypub-reply.js | 32 ++++++++++++++++++++++++++++++++ includes/class-admin.php | 5 ++++- 3 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 assets/js/activitypub-reply.js diff --git a/assets/js/activitypub-admin.js b/assets/js/activitypub-admin.js index 2b43ad2..37117ca 100644 --- a/assets/js/activitypub-admin.js +++ b/assets/js/activitypub-admin.js @@ -18,20 +18,4 @@ jQuery( function( $ ) { }, 1200 ); } ); - //Reply Comment-edit screen - if ( $('body').hasClass('edit-comments-php') || $('body').hasClass('index-php') ) { - //Insert Mentions into comment content on reply - $( '.comment-inline.button-link' ).on( 'click', function( event ) { - var recipients = $(this).attr('data-recipients') ? $(this).attr('data-recipients') + ' ' : ''; - setTimeout(function() { - if ( recipients ){ - $('#replycontent').val( recipients ) - } - }, 100); - }) - //Clear Mentions from content on cancel - $('.cancel.button').on('click', function(){ - $('#replycontent').val(''); - }); - } } ); diff --git a/assets/js/activitypub-reply.js b/assets/js/activitypub-reply.js new file mode 100644 index 0000000..8894ec4 --- /dev/null +++ b/assets/js/activitypub-reply.js @@ -0,0 +1,32 @@ +jQuery( function( $ ) { + // Reply from Comment-edit screen & Dashboard. + if ( $('body').hasClass('edit-comments-php') || $('body').hasClass('index-php') ) { + //Insert @mentions into comment content on reply + $( '.comment-inline.button-link' ).on( 'click', function( event ) { + var recipients = $(this).attr('data-recipients') ? $(this).attr('data-recipients') + ' ' : ''; + setTimeout(function() { + if ( recipients ){ + $('#replycontent').val( recipients ) + } + }, 100); + }) + //Clear @mentions from content on cancel + $('.cancel.button').on('click', function(){ + $('#replycontent').val(''); + }); + } + // Reply from frontend. + if ( $('body').hasClass('logged-in') && $('body').hasClass('single') ) { + //Insert @mentions into comment content on reply + $( '.comment-reply-link' ).on( 'click', function( event ) { + console.log( 'comment-reply-link', $(this) ) + var recipients = $(this).attr('data-recipients') ? $(this).attr('data-recipients') + ' ' : ''; + console.log( 'recipients', recipients ) + setTimeout(function() { + if ( recipients ){ + $('#respond #comment').val( recipients ) + } + }, 100); + }) + } +} ); diff --git a/includes/class-admin.php b/includes/class-admin.php index 827012a..5f91c52 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -290,9 +290,12 @@ class Admin { } public static function enqueue_scripts( $hook_suffix ) { - if ( false !== strpos( $hook_suffix, 'activitypub' ) || ( 'edit-comments.php' === $hook_suffix ) || ( 'index.php' === $hook_suffix ) ) { + if ( false !== strpos( $hook_suffix, 'activitypub' ) ) { wp_enqueue_style( 'activitypub-admin-styles', plugins_url( 'assets/css/activitypub-admin.css', ACTIVITYPUB_PLUGIN_FILE ), array(), '1.0.0' ); wp_enqueue_script( 'activitypub-admin-styles', plugins_url( 'assets/js/activitypub-admin.js', ACTIVITYPUB_PLUGIN_FILE ), array( 'jquery' ), '1.0.0', false ); } + if ( ( 'edit-comments.php' === $hook_suffix ) || ( 'index.php' === $hook_suffix ) ) { + wp_enqueue_script( 'activitypub-reply', plugins_url( 'assets/js/activitypub-reply.js', ACTIVITYPUB_PLUGIN_FILE ), array( 'jquery' ), '1.0.0', false ); + } } }