From b5ee5fa33f3e4bdf19434cc2edb4a84217ab387c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 26 Oct 2017 23:22:59 +0200 Subject: [PATCH] Avoid timeout issue in Chrome on Android when pasting --- .../redactor2/plugins/WoltLabPaste.js | 64 ++++++++++++++++--- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js index ccd68afde9..b4a12353e8 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js @@ -1,6 +1,8 @@ $.Redactor.prototype.WoltLabPaste = function() { "use strict"; + var _environment = null; + return { init: function () { var clipboardData = null; @@ -11,6 +13,41 @@ $.Redactor.prototype.WoltLabPaste = function() { var pastedHtml = null, pastedPlainText = null; + // special `init()` implementation for Chrome on Android which seems to have + // some serious issues with `setTimeout()` during a `paste` event + var mpInitChromeOnAndroid = (function (e) { + this.rtePaste = true; + var pre = !!(this.opts.type === 'pre' || this.utils.isCurrentOrParent('pre')); + + this.utils.saveScroll(); + this.selection.save(); + this.paste.createPasteBox(pre); + + var html = this.paste.getPasteBoxCode(pre); + + // buffer + this.buffer.set(); + this.selection.restore(); + + this.utils.restoreScroll(); + + // paste info + var data = this.clean.getCurrentType(html); + + // clean + html = this.clean.onPaste(html, data); + + // callback + var returned = this.core.callback('paste', html); + html = (typeof returned === 'undefined') ? html : returned; + + this.paste.insert(html, data); + this.rtePaste = false; + + // clean pre breaklines + if (pre) this.clean.cleanPre(); + }).bind(this); + var mpInit = this.paste.init; this.paste.init = (function (e) { pastedPlainText = pastedHtml = null; @@ -71,20 +108,18 @@ $.Redactor.prototype.WoltLabPaste = function() { e.preventDefault(); } - mpInit.call(this, e); - }).bind(this); - - var mpCreatePasteBox = this.paste.createPasteBox; - this.paste.createPasteBox = (function (pre) { - if (pastedHtml === null && pastedPlainText === null) { - mpCreatePasteBox.call(this, pre); + if (_environment.platform() === 'android' && _environment.browser() === 'chrome') { + mpInitChromeOnAndroid(e); + } + else { + mpInit.call(this, e); } - - // do nothing }).bind(this); require(['Environment'], (function(Environment) { - if (Environment.platform() === 'ios' && Environment.browser() === 'safari') { + _environment = Environment; + + if (_environment.platform() === 'ios') { var mpAppendPasteBox = this.paste.appendPasteBox; this.paste.appendPasteBox = (function() { // iOS doesn't like `position: fixed` and font-sizes below 16px that much @@ -103,6 +138,15 @@ $.Redactor.prototype.WoltLabPaste = function() { } }).bind(this)); + var mpCreatePasteBox = this.paste.createPasteBox; + this.paste.createPasteBox = (function (pre) { + if (pastedHtml === null && pastedPlainText === null) { + mpCreatePasteBox.call(this, pre); + } + + // do nothing + }).bind(this); + var mpGetPasteBoxCode = this.paste.getPasteBoxCode; this.paste.getPasteBoxCode = (function (pre) { if (pastedHtml !== null || pastedPlainText !== null) { -- 2.20.1