From bdf7e4d29d954c3d2c137948577b6872c3de4656 Mon Sep 17 00:00:00 2001 From: maTh Date: Mon, 14 Mar 2022 23:05:47 +0100 Subject: Improved: Show URL button (#4238) * done * fix extra.js * click event * URL input does not extend anymore * fix * improved the i18n key * Update app/i18n/fr/gen.php Co-authored-by: Alexandre Alapetite --- p/scripts/extra.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'p/scripts') diff --git a/p/scripts/extra.js b/p/scripts/extra.js index 505b05110..d89342720 100644 --- a/p/scripts/extra.js +++ b/p/scripts/extra.js @@ -123,6 +123,29 @@ function init_password_observers() { }); } +// overwrites the href attribute from the url input +function updateHref(ev) { + const urlField = document.getElementById(this.getAttribute('data-input')); + const url = urlField.value; + if (url.length > 0) { + this.href = url; + return true; + } else { + urlField.focus(); + this.removeAttribute('href'); + ev.preventDefault(); + return false; + } +} + +// set event listener on "show url" buttons +function init_url_observers() { + document.querySelectorAll('.open-url').forEach(function (btn) { + btn.addEventListener('mouseover', updateHref); + btn.addEventListener('click', updateHref); + }); +} + function init_select_observers() { document.querySelectorAll('.select-change').forEach(function (s) { s.onchange = function (ev) { @@ -266,6 +289,7 @@ function init_extra() { } init_crypto_form(); init_password_observers(); + init_url_observers(); init_select_observers(); init_slider_observers(); init_configuration_alert(); -- cgit v1.2.3