[Rt-commit] rt branch, 4.6/core-rt-extension-quoteselection, created. rt-4.4.3-63-g67ef08ef4

Maureen Mirville maureen at bestpractical.com
Tue Nov 6 18:29:38 EST 2018


The branch, 4.6/core-rt-extension-quoteselection has been created
        at  67ef08ef40c21f4c60e7849142b4bae547f221b4 (commit)

- Log -----------------------------------------------------------------
commit 67ef08ef40c21f4c60e7849142b4bae547f221b4
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date:   Tue Nov 6 18:13:21 2018 -0500

    Core RT::Extension::QuoteSelection to 4.6

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index b85519d77..382b5de40 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -137,6 +137,7 @@ sub JSFiles {
       assets.js
       /static/RichText/ckeditor.js
       dropzone.min.js
+      quoteselection.js
       }, RT->Config->Get('JSFiles');
 }
 
diff --git a/share/static/js/quoteselection.js b/share/static/js/quoteselection.js
new file mode 100644
index 000000000..ec246790e
--- /dev/null
+++ b/share/static/js/quoteselection.js
@@ -0,0 +1,54 @@
+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);
+    });
+});

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


More information about the rt-commit mailing list