From 42aa357cb49505608c6a6b1490e64c2e968ac60b Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 7 Jun 2023 16:32:54 +0200 Subject: [PATCH] wait #6003 @0.5 --- .../linkeditor/js/linkeditor.clipboard.js | 30 ++++++++++++++++--- resources/linkeditor/js/linkeditor.utils.js | 8 +++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/resources/linkeditor/js/linkeditor.clipboard.js b/resources/linkeditor/js/linkeditor.clipboard.js index f624f2843..2bdd603b3 100644 --- a/resources/linkeditor/js/linkeditor.clipboard.js +++ b/resources/linkeditor/js/linkeditor.clipboard.js @@ -1,6 +1,7 @@ function LinkeditorClipboard(linkeditor) { this.linkeditor = linkeditor; this.content = ''; + this.blocked = true; this._isEmpty = true; this.init(); @@ -8,25 +9,46 @@ function LinkeditorClipboard(linkeditor) { LinkeditorClipboard.prototype = { init: function () { - if (!this.enabled()) { + let $this = this; + if (!this.support()) { + return; + } + $(document).on('touchstart click', function () { + if (document.hasFocus()) { + $this.checkBlocked(); + } + return true; + }); + + }, + + checkBlocked: function () { + if (!this.blocked) { return; } let $this = this; + this.get(function (c) { + }, true); }, enabled: function () { - return !this.linkeditor.utils.isFirefox(); + return !this.blocked && this.support(); + }, + + support: function () { + return this.linkeditor.utils.isWindows() && !this.linkeditor.utils.isFirefox(); }, empty: function () { this.set(''); }, - get: function (callback) { + get: function (callback, force) { let $this = this; - if (this.enabled()) { + if (force || this.enabled()) { navigator.clipboard.read() .then(items => { + $this.blocked = false; items[0].getType('text/html') .then(blob => { blob.text() diff --git a/resources/linkeditor/js/linkeditor.utils.js b/resources/linkeditor/js/linkeditor.utils.js index 36890b479..7995da433 100644 --- a/resources/linkeditor/js/linkeditor.utils.js +++ b/resources/linkeditor/js/linkeditor.utils.js @@ -151,6 +151,14 @@ LinkeditorUtils.prototype = { isFirefox: function () { return navigator.userAgent.search("Firefox") >= 0; }, + + isSafari: function () { + return /^((?!chrome|android).)*safari/i.test(navigator.userAgent); + }, + + isWindows: function () { + return navigator.userAgent.search('Windows') >= 0; + } }; module.exports = LinkeditorUtils; -- 2.39.5