From: Alexander Ebert Date: Tue, 2 Dec 2014 13:55:08 +0000 (+0100) Subject: Attempt to fix formatting on iOS X-Git-Tag: 2.1.0_Beta_1~104 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d8a358ee74349f1c862e2f9f7b106f0a3530b5e6;p=GitHub%2FWoltLab%2FWCF.git Attempt to fix formatting on iOS --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index 2d5495971f..b553b4ad2e 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -35,6 +35,7 @@ RedactorPlugins.wmonkeypatch = function() { this.wmonkeypatch.code(); this.wmonkeypatch.dropdown(); this.wmonkeypatch.image(); + this.wmonkeypatch.inline(); this.wmonkeypatch.insert(); this.wmonkeypatch.keydown(); this.wmonkeypatch.link(); @@ -64,6 +65,23 @@ RedactorPlugins.wmonkeypatch = function() { } }, + /** + * Restores saved selection. + */ + restoreSelection: function() { + if (document.activeElement !== this.$editor[0]) { + this.$editor.focus(); + } + + if (this.wmonkeypatch._range !== null) { + var $selection = window.getSelection(); + $selection.removeAllRanges(); + $selection.addRange(this.wmonkeypatch._range); + + this.wmonkeypatch._range = null; + } + }, + /** * Setups event listeners and callbacks. */ @@ -331,6 +349,7 @@ RedactorPlugins.wmonkeypatch = function() { * Partially overwrites the 'dropdown' module. * * - emulate WCF-like dropdowns. + * - save text selection on iOS (#2003) */ dropdown: function() { // dropdown.build @@ -373,6 +392,10 @@ RedactorPlugins.wmonkeypatch = function() { var $dropdown = this.button.get(key).data('dropdown'); $fixDropdown($dropdown); + if ($.browser.iOS) { + this.wmonkeypatch.saveSelection(); + } + $mpShow.call(this, e, key); $dropdown.off('mouseover mouseout'); @@ -458,6 +481,31 @@ RedactorPlugins.wmonkeypatch = function() { }).bind(this); }, + /** + * Partially overwrites the 'inline' module. + * + * - restore the text selection on iOS (#2003) + */ + inline: function() { + var $mpFormat = this.inline.format; + this.inline.format = (function(tag, type, value) { + if ($.browser.iOS) { + this.wmonkeypatch.restoreSelection(); + } + + $mpFormat.call(this, tag, type, value); + }).bind(this); + + var $mpRemoveStyleRule = this.inline.removeStyleRule; + this.inline.removeStyleRule = (function(name) { + if ($.browser.iOS) { + this.wmonkeypatch.restoreSelection(); + } + + $mpRemoveStyleRule.call(this, name); + }).bind(this); + }, + /** * Partially overwrites the 'insert' module. *