[Bps-public-commit] rt-extension-quoteselection branch, 4.2, updated. 5d1999e278ea9e28faad983235552996ca6d7b66

Thomas Sibley trs at bestpractical.com
Thu Jun 13 18:38:10 EDT 2013


The branch, 4.2 has been updated
       via  5d1999e278ea9e28faad983235552996ca6d7b66 (commit)
      from  cc199c9aeaa3d9a67d7f4c62f7a6f43c4293b224 (commit)

Summary of changes:
 static/js/RTx-QuoteSelection.js | 46 ++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

- Log -----------------------------------------------------------------
commit 5d1999e278ea9e28faad983235552996ca6d7b66
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Jun 13 15:36:16 2013 -0700

    Use a delegated event handler to catch links in delay-loaded history
    
    This requires jQuery 1.9's .on() method.  Older jQuery versions can
    replace it with .live() after slight adjustment (and taking a minor
    performance decrease).
    
    Diff best viewed with ignored whitespace.

diff --git a/static/js/RTx-QuoteSelection.js b/static/js/RTx-QuoteSelection.js
index 28530bf..081e789 100644
--- a/static/js/RTx-QuoteSelection.js
+++ b/static/js/RTx-QuoteSelection.js
@@ -1,31 +1,35 @@
 jQuery(function() {
-    jQuery(
+    jQuery(document).on(
+        "click",
+
         ".reply-link, "         +
         ".comment-link, "       +
         "#page-actions-reply, " +
-        "#page-actions-comment"
-    ).click(function(ev) {
-        var link = jQuery(this);
-        var selection;
+        "#page-actions-comment",
+
+        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 (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 (selection.toString)
+                selection = selection.toString();
 
-        if (typeof(selection) !== "string" || selection.length < 3)
-            return
+            if (typeof(selection) !== "string" || selection.length < 3)
+                return
 
-        // TODO: wrap long lines before quoting
-        selection = selection.replace(/^/gm, "> ");
-        selection = selection.concat("\n\n");
-        selection = encodeURIComponent(selection);
+            // TODO: wrap long lines before quoting
+            selection = selection.replace(/^/gm, "> ");
+            selection = selection.concat("\n\n");
+            selection = encodeURIComponent(selection);
 
-        link.attr("href", link.attr("href").concat("&UpdateContent=" + selection));
-    });
+            link.attr("href", link.attr("href").concat("&UpdateContent=" + selection));
+        }
+    );
 });

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



More information about the Bps-public-commit mailing list