From 6a26e868ed2f4c81df9cb77cef54c57569b82c03 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 22 Jan 2015 00:23:06 +0100 Subject: [PATCH] Improved click handler --- .../3rdParty/redactor/plugins/wmonkeypatch.js | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index ec8117b516..fa32860867 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -123,16 +123,44 @@ RedactorPlugins.wmonkeypatch = function() { } }).bind(this); + var $editorPadding = null; this.$editor.on('click.wmonkeypatch', (function(event) { if (event.target === this.$editor[0]) { var $range = (window.getSelection().rangeCount) ? window.getSelection().getRangeAt(0) : null; if ($range && $range.collapsed) { var $current = $range.startContainer; + + // this can occur if click occurs within the editor padding + var $offsets = this.$editor.offset(); + if ($editorPadding === null) { + $editorPadding = { + left: this.$editor.cssAsNumber('padding-left'), + top: this.$editor.cssAsNumber('padding-top') + }; + } + + if (event.pageY <= $offsets.top + $editorPadding.top) { + var $firstChild = this.$editor[0].children[0]; + if ($firstChild.tagName !== 'BLOCKQUOTE' && ($firstChild.tagName !== 'DIV' || !/\bcodeBox\b/.test($firstChild.className))) { + return; + } + } + else { + if (event.pageX <= $offsets.left + $editorPadding.left) { + return; + } + else { + if (event.pageX > $offsets.left + this.$editor.width()) { + return; + } + } + } + while ($current !== null && $current !== this.$editor[0]) { if ($current.nodeType === Node.ELEMENT_NODE) { if ($current.tagName === 'BLOCKQUOTE' || ($current.tagName === 'DIV' && /\bcodeBox\b/.test($current.className))) { - var $offset = $(element).offset(); + var $offset = $($current).offset(); if (event.pageY <= $offset.top) { $setCaretBeforeOrAfter($current, true); } -- 2.20.1