From 2de07302cc72084a7b16a6c4767934ad675e363b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Wed, 3 May 2023 13:53:20 +0200 Subject: [PATCH] refactor/Avoid JavaScript warning --- src/main/webapp/media/js/website.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/webapp/media/js/website.js b/src/main/webapp/media/js/website.js index 68b8ce52..a7ccc417 100644 --- a/src/main/webapp/media/js/website.js +++ b/src/main/webapp/media/js/website.js @@ -274,12 +274,15 @@ function filterMessageDocs(element) { // when we press a copy icon in top left corner. // In case that action is successful the icon is changed for a 2 seconds in order to notify a user about it. function copyJsonResultToClipboard(element) { - var id = String(element.id).replace('result_copy_icon_','result_'); + var id = String(element.id).replace("result_copy_icon_", "result_"); var r = document.createRange(); r.selectNode(document.getElementById(id)); window.getSelection().removeAllRanges(); window.getSelection().addRange(r); - navigator.clipboard.writeText(window.getSelection().toString()); + navigator.clipboard.writeText(window.getSelection().toString()).then( + () => console.log("clipboard successfully set"), + () => console.log("clipboard write failed") + ); window.getSelection().removeAllRanges(); // Store original values var titleText = document.getElementById(element.id).title; @@ -287,25 +290,25 @@ function copyJsonResultToClipboard(element) { // and then change hey document.getElementById(element.id).title = ""; document.getElementById(element.id).className = "fa-regular fa-copy"; - + // Below code is GUI related i.e. to notify a user that text is copied to clipboard // -------------------------------------------------------------------------------- - + // It delays the call by ms milliseconds function defer(f, ms) { - return function() { + return function () { setTimeout(() => f.apply(this, arguments), ms); }; } - + // Function which revert icon and text to the initial state. function revertTextAndClass(titleText, iconClass) { document.getElementById(element.id).title = titleText; - document.getElementById(element.id).className = iconClass + document.getElementById(element.id).className = iconClass; } - + var revertTextAndClassDeferred = defer(revertTextAndClass, 2000); // Revert the original values of text and icon after 2 seconds - revertTextAndClassDeferred(titleText, iconClass); - + revertTextAndClassDeferred(titleText, iconClass); } +