[Rt-commit] rt branch 5.0/quoting-text-with-ckeditor created. rt-5.0.4-20-g57101e74ec

BPS Git Server git at git.bestpractical.com
Thu Jun 1 20:58:05 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/quoting-text-with-ckeditor has been created
        at  57101e74ecb84d76a4a8a4a8d600b7d6bc90b80b (commit)

- Log -----------------------------------------------------------------
commit 57101e74ecb84d76a4a8a4a8d600b7d6bc90b80b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Jun 1 23:57:44 2023 +0300

    stab

diff --git a/share/static/js/quoteselection.js b/share/static/js/quoteselection.js
index 48e01a7557..96cd19913e 100644
--- a/share/static/js/quoteselection.js
+++ b/share/static/js/quoteselection.js
@@ -1,79 +1,117 @@
 jQuery(function() {
-    if(RT.Config.QuoteSelectedText) {
-        var reply_from_selection = function(ev) {
-            var link = jQuery(this);
+    if(!RT.Config.QuoteSelectedText) {
+        return;
+    }
 
-            var selection;
-            var activeElement;
-            if (window.getSelection) {
-                selection = window.getSelection();
-            } else {
-                return;
+    var add_sub_container = function (container, tagName) {
+        var sub = document.createElement(tagName);
+        container.appendChild(sub);
+        return sub;
+    };
+      
+    var range_html = function (range) {
+        var topContainer = document.createElement('div');
+        var container = topContainer;
+        
+        var fragment = range.cloneContents();
+        
+        var child = fragment.firstElementChild;
+        if (child) {
+            var tn = child.tagName
+            if (tn == "LI") {
+                container = addSubContainer(container, 'ul');
+            } else if (tn == "DT" || tn == "DD") {
+                container = addSubContainer(container, 'dl');
+            } else if (tn == "TD" || tn == "TH") {
+                container = addSubContainer(container, 'table');
+                container = addSubContainer(container, 'tbody');      
+                container = addSubContainer(container, 'tr');      
+            } else if (tn == "TR") {
+                container = addSubContainer(container, 'table');
+                container = addSubContainer(container, 'tbody');      
+            } else if (tn == "TBODY" || tn == "THEAD" || tn == "TFOOT") {
+                container = addSubContainer(container, 'table');
             }
+        }
 
-            if (selection.rangeCount) {
-                activeElement = selection.getRangeAt(0);
-            } else {
-                return;
-            }
+        container.appendChild(fragment);
+        return topContainer.innerHTML;
+    };
 
-            // 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;
+    var reply_from_selection = function(ev) {
+        var link = jQuery(this);
+
+        var selection;
+        var activeElement;
+        if (window.getSelection) {
+            selection = window.getSelection();
+        } 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;
+            }
+        }
+        
+        var ct = '';
+        if ( RT.Config.MessageBoxRichText ) {
+            selection = range_html(activeElement);
+            ct = 'html';
+        }
+        else {
             if (selection.toString)
                 selection = selection.toString();
 
-            if (typeof(selection) !== "string" || selection.length < 3)
-                return;
+            selection = selection.concat("\n\n");
+            ct = 'text';
+        }
+        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);
+        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));
-        };
+        if ( !link.prop('data-href') ) {
+            link.prop('data-href', link.attr('href'));
+        }
+        link.attr("href", link.prop("data-href")
+            .concat("&QuoteContent=" + selection + "&QuoteContentType=" + ct));
+    };
 
-        var apply_quote = function() {
-            var link = jQuery(this);
-            if (link.data("quote-selection"))
-                return;
-            link.data("quote-selection",true);
-            link.click(reply_from_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(
+        ".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);
-        });
-    }
+    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