From d2c6ca6d003befe301eb600df89ddc0208345c8a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 5 Sep 2016 12:37:39 +0200 Subject: [PATCH] Taking care of caret position on edit click --- .../install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js | 7 ++++++- .../files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js | 7 ++++++- .../files/js/WoltLabSuite/Core/Ui/Redactor/Spoiler.js | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js index e3c209a9e2..c509424b09 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js @@ -67,7 +67,7 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di */ _observeLoad: function() { elBySelAll('pre', this._editor.$editor[0], (function(pre) { - pre.addEventListener(WCF_CLICK_EVENT, this._callbackEdit); + pre.addEventListener('mousedown', this._callbackEdit); this._setTitle(pre); }).bind(this)); }, @@ -90,6 +90,7 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di if (event.pageY > offset.top && event.pageY < (offset.top + _headerHeight)) { event.preventDefault(); + this._editor.selection.save(); this._pre = pre; UiDialog.open(this); @@ -150,6 +151,10 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di return { id: id, options: { + onClose: (function () { + this._editor.selection.restore(); + }).bind(this), + onSetup: (function() { elById(idButtonSave).addEventListener(WCF_CLICK_EVENT, this._save.bind(this)); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js index 86b7e3aff2..9da1fd53fe 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js @@ -118,7 +118,7 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util' for (var i = 0, length = this._quotes.length; i < length; i++) { quote = this._quotes[i]; - quote.addEventListener(WCF_CLICK_EVENT, this._callbackEdit); + quote.addEventListener('mousedown', this._callbackEdit); this._setTitle(quote); } }, @@ -141,6 +141,7 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util' if (event.pageY > offset.top && event.pageY < (offset.top + _headerHeight)) { event.preventDefault(); + this._editor.selection.save(); this._quote = quote; UiDialog.open(this); @@ -209,6 +210,10 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util' return { id: id, options: { + onClose: (function () { + this._editor.selection.restore(); + }).bind(this), + onSetup: (function() { elById(idButtonSave).addEventListener(WCF_CLICK_EVENT, this._save.bind(this)); }).bind(this), diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Spoiler.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Spoiler.js index 744f1d4c56..4b6b6d5a14 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Spoiler.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Spoiler.js @@ -65,7 +65,7 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di */ _observeLoad: function() { elBySelAll('woltlab-spoiler', this._editor.$editor[0], (function(spoiler) { - spoiler.addEventListener(WCF_CLICK_EVENT, this._callbackEdit); + spoiler.addEventListener('mousedown', this._callbackEdit); this._setTitle(spoiler); }).bind(this)); }, @@ -88,6 +88,7 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di if (event.pageY > offset.top && event.pageY < (offset.top + _headerHeight)) { event.preventDefault(); + this._editor.selection.save(); this._spoiler = spoiler; UiDialog.open(this); @@ -133,6 +134,10 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di return { id: id, options: { + onClose: (function () { + this._editor.selection.restore(); + }).bind(this), + onSetup: (function() { elById(idButtonSave).addEventListener(WCF_CLICK_EVENT, this._save.bind(this)); }).bind(this), -- 2.20.1