[Rt-commit] rt branch 5.0/refine-selected-text-quoting-transaction-area created. rt-5.0.3-221-gb8990ea5d2

BPS Git Server git at git.bestpractical.com
Tue Feb 28 13:43:02 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/refine-selected-text-quoting-transaction-area has been created
        at  b8990ea5d2a2aaadcdf5294d832cecb8b8ff46e1 (commit)

- Log -----------------------------------------------------------------
commit b8990ea5d2a2aaadcdf5294d832cecb8b8ff46e1
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Mon Jan 23 12:08:08 2023 -0300

    Only quote text from transaction areas in the ticket history

diff --git a/share/static/js/quoteselection.js b/share/static/js/quoteselection.js
index 6d1fdf1e7c..48e01a7557 100644
--- a/share/static/js/quoteselection.js
+++ b/share/static/js/quoteselection.js
@@ -4,12 +4,35 @@ jQuery(function() {
             var link = jQuery(this);
 
             var selection;
-            if (window.getSelection)
+            var activeElement;
+            if (window.getSelection) {
                 selection = window.getSelection();
-            else if (document.getSelection)
-                selection = document.getSelection();
-            else if (document.selection)
-                selection = document.selection.createRange().text;
+            } else {
+                return;
+            }
+
+            if (selection.rangeCount) {
+                activeElement = selection.getRangeAt(0);
+            } else {
+                return;
+            }
+
+            // check if selection has commonAncestorContainer with class 'messagebody'
+            var commonAncestor = activeElement.commonAncestorContainer;
+            if (commonAncestor) {
+                var isMessageBody = false;
+                var parent = commonAncestor.parentNode;
+                while (parent) {
+                    if (parent.className && parent.className.indexOf('messagebody') != -1) {
+                        isMessageBody = true;
+                        break;
+                    }
+                    parent = parent.parentNode;
+                }
+                if (!isMessageBody) {
+                    return;
+                }
+            }
 
             if (selection.toString)
                 selection = selection.toString();

commit 307f9d918dc9e8822ac8c8188c2da486a452957b
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Fri Jan 20 17:04:38 2023 -0300

    Add option to disable the quoting of selected text in Comment
    
    Added config QuoteSelectedText at user/global level to disable the
    quoting of selected text in Comment or Reply pages.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 6c80eaa26b..8e0abe55f1 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2890,6 +2890,17 @@ Set(%PriorityAsString,
     Default => { Low => 0, Medium => 50, High => 100 },
 );
 
+=item C<$QuoteSelectedText>
+
+Users can select text to be quoted when replying or commenting
+in a ticket by default. Set this configuration to C<0> to disable this
+feature.
+
+=cut
+
+Set($QuoteSelectedText, 1);
+
+
 =back
 
 =head2 Group Summary Configuration
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index ea99df798d..f4f6e51cae 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -631,6 +631,15 @@ our %META;
             Hints       => 'Show search navigation links of "First", "Last", "Prev" and "Next"', # loc
         }
     },
+    QuoteSelectedText => {
+        Section     => 'Ticket display',
+        Overridable => 1,
+        SortOrder   => 14,
+        Widget      => '/Widgets/Form/Boolean',
+        WidgetArguments => {
+            Description => 'Quote Selected Text on Reply/Comment', # loc
+        }
+    },
 
     # User overridable locale options
     DateTimeFormat => {
diff --git a/share/html/Elements/JavascriptConfig b/share/html/Elements/JavascriptConfig
index 4b9b7b52b5..4b858096df 100644
--- a/share/html/Elements/JavascriptConfig
+++ b/share/html/Elements/JavascriptConfig
@@ -49,7 +49,7 @@
 my $Config = {};
 $Config->{$_} = RT->Config->Get( $_, $session{CurrentUser} )
   for qw(rtname WebPath MessageBoxRichText MessageBoxRichTextHeight
-         MaxAttachmentSize WebDefaultStylesheet);
+         MaxAttachmentSize WebDefaultStylesheet QuoteSelectedText );
 
 my $CurrentUser = {};
 if ($session{CurrentUser} and $session{CurrentUser}->id) {
diff --git a/share/static/js/quoteselection.js b/share/static/js/quoteselection.js
index ec246790ee..6d1fdf1e7c 100644
--- a/share/static/js/quoteselection.js
+++ b/share/static/js/quoteselection.js
@@ -1,54 +1,56 @@
 jQuery(function() {
-    var reply_from_selection = function(ev) {
-        var link = jQuery(this);
-
-        var selection;
-        if (window.getSelection)
-            selection = window.getSelection();
-        else if (document.getSelection)
-            selection = document.getSelection();
-        else if (document.selection)
-            selection = document.selection.createRange().text;
-
-        if (selection.toString)
-            selection = selection.toString();
-
-        if (typeof(selection) !== "string" || selection.length < 3)
-            return;
-
-        // TODO: wrap long lines before quoting
-        selection = selection.replace(/^/gm, "> ");
-        if ( RT.Config.MessageBoxRichText ) {
-            selection = selection.replace(/\r?\n/g, "<br>");
-            selection = selection.concat("<br><br>");
-        }
-        else {
-            selection = selection.concat("\n\n");
-        }
-        selection = encodeURIComponent(selection);
-
-        if ( !link.prop('data-href') ) {
-            link.prop('data-href', link.attr('href'));
-        }
-        link.attr("href", link.prop("data-href").concat("&UpdateContent=" + selection));
-    };
-
-    var apply_quote = function() {
-        var link = jQuery(this);
-        if (link.data("quote-selection"))
-            return;
-        link.data("quote-selection",true);
-        link.click(reply_from_selection);
-    };
-
-    jQuery(
-        ".reply-link, "         +
-        ".comment-link, "       +
-        "#page-actions-reply, " +
-        "#page-actions-comment"
-    ).each(apply_quote);
-
-    jQuery(document).ajaxComplete(function(ev){
-        jQuery(".reply-link, .comment-link").each(apply_quote);
-    });
+    if(RT.Config.QuoteSelectedText) {
+        var reply_from_selection = function(ev) {
+            var link = jQuery(this);
+
+            var selection;
+            if (window.getSelection)
+                selection = window.getSelection();
+            else if (document.getSelection)
+                selection = document.getSelection();
+            else if (document.selection)
+                selection = document.selection.createRange().text;
+
+            if (selection.toString)
+                selection = selection.toString();
+
+            if (typeof(selection) !== "string" || selection.length < 3)
+                return;
+
+            // TODO: wrap long lines before quoting
+            selection = selection.replace(/^/gm, "> ");
+            if ( RT.Config.MessageBoxRichText ) {
+                selection = selection.replace(/\r?\n/g, "<br>");
+                selection = selection.concat("<br><br>");
+            }
+            else {
+                selection = selection.concat("\n\n");
+            }
+            selection = encodeURIComponent(selection);
+
+            if ( !link.prop('data-href') ) {
+                link.prop('data-href', link.attr('href'));
+            }
+            link.attr("href", link.prop("data-href").concat("&UpdateContent=" + selection));
+        };
+
+        var apply_quote = function() {
+            var link = jQuery(this);
+            if (link.data("quote-selection"))
+                return;
+            link.data("quote-selection",true);
+            link.click(reply_from_selection);
+        };
+
+        jQuery(
+            ".reply-link, "         +
+            ".comment-link, "       +
+            "#page-actions-reply, " +
+            "#page-actions-comment"
+        ).each(apply_quote);
+
+        jQuery(document).ajaxComplete(function(ev){
+            jQuery(".reply-link, .comment-link").each(apply_quote);
+        });
+    }
 });

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list