From 320c81492eef6a6a7a251c67f3513ef75b45276d Mon Sep 17 00:00:00 2001 From: Nils Gabriel Date: Tue, 20 Apr 2021 09:10:21 +0200 Subject: [PATCH] Add option to open links on first click. --- www/common/translations/messages.de.json | 3 ++ www/common/translations/messages.json | 3 ++ www/pad/inner.js | 4 ++- www/pad/links.js | 11 +++++-- www/settings/inner.js | 38 ++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/www/common/translations/messages.de.json b/www/common/translations/messages.de.json index 992213969..6a0a42748 100644 --- a/www/common/translations/messages.de.json +++ b/www/common/translations/messages.de.json @@ -420,6 +420,9 @@ "settings_padSpellcheckTitle": "Rechtschreibprüfung", "settings_padSpellcheckHint": "Mit dieser Option kann die Rechtschreibprüfung in Rich-Text-Pads aktiviert werden. Rechtschreibfehler werden rot unterstrichen. Halte die Strg- oder Meta-Taste gedrückt, um Verbesserungsvorschläge anzuzeigen.", "settings_padSpellcheckLabel": "Rechtschreibprüfung in Rich-Text-Pads aktivieren", + "settings_padOpenLinkTitle": "Links direkt öffnen", + "settings_padOpenLinkHint": "Mit dieser Optione werden externe Links direkt über Klick in einem neuem Fenster geöffnet.", + "settings_padOpenLinkLabel": "Aktiviert Links direkt über Klick zu öffnen", "settings_ownDriveTitle": "Account aktualisieren", "settings_ownDriveHint": "Aus technischen Gründen sind nicht alle neue Funktionen für ältere Konten verfügbar. Eine kostenlose Aktualisierung wird die neuen Funktionen aktivieren und dein CryptDrive für zukünftige Aktualisierungen vorbereiten.", "settings_ownDriveButton": "Upgrade deines Accounts", diff --git a/www/common/translations/messages.json b/www/common/translations/messages.json index ceec7b35f..d3d0ffe71 100644 --- a/www/common/translations/messages.json +++ b/www/common/translations/messages.json @@ -437,6 +437,9 @@ "settings_padSpellcheckTitle": "Spellcheck", "settings_padSpellcheckHint": "This option allows you to enable spellcheck in rich text pads. Spelling errors will be underlined in red and you'll have to hold your Ctrl or Meta key while right-clicking to see the correct options.", "settings_padSpellcheckLabel": "Enable spell check in rich text pads", + "settings_padOpenLinkTitle": "Open links on first click", + "settings_padOpenLinkHint": "With this option you can open embedded links on click without the preview popup", + "settings_padOpenLinkLabel": "Enable direct link opening rich text pads", "settings_ownDriveTitle": "Update Account", "settings_ownDriveHint": "Older accounts do not have access to the latest features, due to technical reasons. A free update will enable current features, and prepare your CryptDrive for future updates.", "settings_ownDriveButton": "Upgrade your account", diff --git a/www/pad/inner.js b/www/pad/inner.js index 793d57b72..5a8356eb2 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -1433,7 +1433,9 @@ define([ editor.setKeystroke( CKEDITOR.CTRL + CKEDITOR.ALT + styleKeys[tag], tag); }); - Links.init(Ckeditor, editor); + var privateData = framework._.cpNfInner.metadataMgr.getPrivateData(); + var openLinkSetting = Util.find(privateData, ['settings', 'pad', 'openLink']); + Links.init(Ckeditor, editor, openLinkSetting); }).nThen(function() { // Move ckeditor parts to have a structure like the other apps var $contentContainer = $('#cke_1_contents'); diff --git a/www/pad/links.js b/www/pad/links.js index 779257dfb..479a3671b 100644 --- a/www/pad/links.js +++ b/www/pad/links.js @@ -5,7 +5,7 @@ define([ '/customize/messages.js' ], function ($, h, UIElements, Messages) { - var onLinkClicked = function (e, inner) { + var onLinkClicked = function (e, inner, openLinkSetting) { var $target = $(e.target); if (!$target.is('a')) { $target = $target.closest('a'); @@ -25,6 +25,11 @@ define([ return; } + if(openLinkSetting) { + window.open(href, '_blank', 'noreferrer'); + return; + } + var $iframe = $('html').find('iframe').contents(); var rect = e.target.getBoundingClientRect(); @@ -61,7 +66,7 @@ define([ }; return { - init : function (Ckeditor, editor) { + init : function (Ckeditor, editor, openLinkSetting) { if (!Ckeditor.plugins.link) { return; } var inner = editor.document.$.body; @@ -70,7 +75,7 @@ define([ $inner.click(function (e) { removeClickedLink($inner); if (e.target.nodeName.toUpperCase() === 'A' || $(e.target).closest('a').length) { - return void onLinkClicked(e, inner); + return void onLinkClicked(e, inner, openLinkSetting); } }); diff --git a/www/settings/inner.js b/www/settings/inner.js index 38969f823..5a47a7507 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -84,6 +84,7 @@ define([ 'cp-settings-pad-width', 'cp-settings-pad-spellcheck', 'cp-settings-pad-notif', + 'cp-settings-pad-openlink', ], 'code': [ // Msg.settings_cat_code 'cp-settings-code-indent-unit', @@ -1328,6 +1329,43 @@ define([ cb($cbox); }, true); + create['pad-openlink'] = function() { + var $div = $('
', { + 'class': 'cp-settings-pad-openlink cp-sidebarlayout-element' + }); + $('