Improved clicks on quote margins for nested quotes
authorAlexander Ebert <ebert@woltlab.com>
Mon, 23 Feb 2015 13:48:14 +0000 (14:48 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 23 Feb 2015 13:48:14 +0000 (14:48 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index ba21de8d9120751ee36037b11cbab28ec2067ce0..73cbe5f173c2e9e74030a3162f37bb51c6fd4d91 100644 (file)
@@ -227,6 +227,32 @@ RedactorPlugins.wmonkeypatch = function() {
                                                this.caret.setEnd($firstChild);
                                        }
                                }
+                               else if (event.target.tagName === 'BLOCKQUOTE') {
+                                       var $range = (window.getSelection().rangeCount) ? window.getSelection().getRangeAt(0) : null;
+                                       if ($range !== null && $range.collapsed) {
+                                               // check if caret is now inside a quote
+                                               var $blockquote = null;
+                                               var $current = ($range.startContainer.nodeType === Node.TEXT_NODE) ? $range.startContainer.parentElement : $range.startContainer;
+                                               while ($current !== null && $current !== this.$editor[0]) {
+                                                       if ($current.tagName === 'BLOCKQUOTE') {
+                                                               $blockquote = $current;
+                                                               break;
+                                                       }
+                                                       
+                                                       $current = $current.parentElement;
+                                               }
+                                               
+                                               if ($blockquote !== null && $blockquote !== event.target) {
+                                                       // click occured within inner quote margin, check if click happened before inner quote
+                                                       if (event.pageY <= $($blockquote).offset().top) {
+                                                               $setCaretBeforeOrAfter($blockquote, true);
+                                                       }
+                                                       else {
+                                                               $setCaretBeforeOrAfter($blockquote, false);
+                                                       }
+                                               }
+                                       }
+                               }
                        }).bind(this));
                },