From 7505e2a1abdbefb9508df21616357c68883c222e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 25 Jul 2022 10:26:27 +0200 Subject: [PATCH] Debug v16 --- htdocs/core/js/lib_foot.js.php | 42 ++++++++++++++++++------------- htdocs/core/lib/functions.lib.php | 12 +++++---- htdocs/theme/eldy/global.inc.php | 2 +- htdocs/theme/md/style.css.php | 2 +- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index 9167e08e599..3310554e530 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -231,33 +231,41 @@ print ' ); jQuery(\'.clipboardCPValue, .clipboardCPButton, .clipboardCPValueToPrint\').click(function() { - /* console.log(this.parentNode); */ console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class and we want to copy content of clipboardCPValue class"); if (window.getSelection) { - range = document.createRange(); - - /* We select value to print using the parent. */ - /* We should use the class clipboardCPValue but it may have several element with copy/paste so class to select is not enough */ - range.selectNodeContents(this.parentNode.firstChild); + jqobj=$(this).parent().children(".clipboardCPValue"); + console.log(jqobj.html()); selection = window.getSelection(); /* get the object used for selection */ selection.removeAllRanges(); /* clear current selection */ + + /* We select the value to print using the parentNode.firstChild */ + /* We should use the class clipboardCPValue but it may have several element with copy/paste so class to select is not enough */ + range = document.createRange(); + range.selectNodeContents(this.parentNode.firstChild); selection.addRange(range); /* make the new selection with the value to copy */ + + /* copy selection into clipboard */ + var succeed; + try { + console.log("We set the style display to unset for the span so the copy will work"); + jqobj.css("display", "unset"); /* Because copy does not work on "block" object */ + + succeed = document.execCommand(\'copy\'); + + console.log("We set the style display back to inline-block"); + jqobj.css("display", "inline-block"); + } catch(e) { + succeed = false; + } + + /* Remove the selection to avoid to see the hidden field to copy selected */ + window.getSelection().removeAllRanges(); } - /* copy selection into clipboard */ - var succeed; - try { - succeed = document.execCommand(\'copy\'); - } catch(e) { - succeed = false; - } - - /* Remove the selection to avoid to see the hidden field to copy selected */ - window.getSelection().removeAllRanges(); - /* Show message */ + /* TODO Show message into a top left corner or center of screen */ var lastchild = this.parentNode.lastChild; /* .parentNode is clipboardCP and last child is clipboardCPText */ var tmp = lastchild.innerHTML if (succeed) { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 316d4f79a6d..9b75313d73d 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -11030,12 +11030,12 @@ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1) } /** - * Create a button to copy $valuetocopy in the clipboard. - * Code that handle the click is inside lib_foot.jsp.php. + * Create a button to copy $valuetocopy in the clipboard (for copy and paste feature). + * Code that handle the click is inside core/js/lib_foot.js.php. * * @param string $valuetocopy The value to print * @param int $showonlyonhover Show the copy-paste button only on hover - * @param string $texttoshow Replace the value to show with this text + * @param string $texttoshow Replace the value to show with this text. Use 'none' to show no text (only the copy-paste picto) * @return string The string to print for the button */ function showValueWithClipboardCPButton($valuetocopy, $showonlyonhover = 1, $texttoshow = '') @@ -11047,8 +11047,10 @@ function showValueWithClipboardCPButton($valuetocopy, $showonlyonhover = 1, $tex $showonlyonhover = 0; }*/ - $tag = 'span'; // Using div does not work when using the js copy code. - if ($texttoshow) { + $tag = 'span'; // Using div (like any style of type 'block') does not work when using the js copy code. + if ($texttoshow === 'none') { + $result = '<'.$tag.' class="clipboardCPValue hidewithsize">'.dol_escape_htmltag($valuetocopy, 1, 1).''; + } elseif ($texttoshow) { $result = '<'.$tag.' class="clipboardCPValue hidewithsize">'.dol_escape_htmltag($valuetocopy, 1, 1).''.dol_escape_htmltag($texttoshow, 1, 1).''; } else { $result = '<'.$tag.' class="clipboardCPValue">'.dol_escape_htmltag($valuetocopy, 1, 1).''; diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index 1e37d372e86..ba67bf5fdcf 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -7260,7 +7260,7 @@ span.clipboardCPValueToPrint, div.clipboardCPValueToPrint { } span.clipboardCPValue.hidewithsize { width: 0 !important; - display: inline-block; + display: inline-block; /* this will be modifiy on the fly by the copy-paste js code in lib_foot.js.php to have copy feature working */ color: transparent; white-space: nowrap; overflow-x: hidden; diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index bc201f7da68..a710e8417ec 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -7026,7 +7026,7 @@ span.clipboardCPValueToPrint, div.clipboardCPValueToPrint { } span.clipboardCPValue.hidewithsize { width: 0 !important; - display: inline-block; + display: inline-block; /* this will be modifiy on the fly by the copy-paste js code in lib_foot.js.php to have copy feature working */ color: transparent; white-space: nowrap; overflow-x: hidden;