diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index c277beefe70..13e5226eaa6 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -212,23 +212,34 @@ print ' });'."\n"; print "\n/* JS CODE TO ENABLE ClipBoard copy paste*/\n"; -print 'jQuery(\'.clipboardCopyPaste\').click(function() { - console.log(this.firstChild.innerText); - if ( window.getSelection ) { - +print 'jQuery(\'.clipboardCPShowOnHover\').hover( + function() { + console.log("We hover a value with a copy paste feature"); + $(this).children(".clipboardCPButton, .clipboardCPText").show(); + }, + function() { + console.log("We hover out the value with a copy paste feature"); + $(this).children(".clipboardCPButton, .clipboardCPText").hide(); + } + );'; +print 'jQuery(\'.clipboardCPButton\').click(function() { + /* console.log(this.parentNode); */ + console.log("We click on a clipboardCPButton tag"); + if (window.getSelection) { selection = window.getSelection(); - + range = document.createRange(); - range.selectNodeContents( this.firstChild ); - + range.selectNodeContents(this.parentNode.firstChild); + selection.removeAllRanges(); selection.addRange( range ); - } document.execCommand( \'copy\' ); window.getSelection().removeAllRanges(); - var lastchild = this.lastChild - var tmp =lastchild.innerHTML + + /* Show message */ + var lastchild = this.parentNode.lastChild; + var tmp = lastchild.innerHTML lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\'; setTimeout(() => { lastchild.innerHTML = tmp; }, 1000); })'."\n"; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index ec866514272..1bdd1cd1d2f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9243,11 +9243,13 @@ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1) /** * Create a button to copy $valuetoprint in the clipboard - * @param string $valuetoprint the value to print - * @return string the string to print for the button + * + * @param string $valuetoprint The value to print + * @param int $showonlyonhover Show the copypaste button only on hover + * @return string The string to print for the button */ -function showValueWithCopyAndPasteButton($valuetoprint) +function showValueWithCopyAndPasteButton($valuetoprint, $showonlyonhover = 1) { - $result = ''.$valuetoprint.''; + $result = ''.$valuetoprint.''; return $result; } diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index e0381d6fdef..99bed13179f 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -467,4 +467,3 @@ RestOfEurope=Rest of Europe (EEC) OutOfEurope=Out of Europe (EEC) CurrentOutstandingBillLate=Current outstanding bill late BecarefullChangeThirdpartyBeforeAddProductToInvoice=Be carefull, depending on your product price settings, you should change thirdparty before adding product to POS. -CopiedToClipboard = Copied to clipboard \ No newline at end of file diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 5cdb042f933..a5cd750e3d6 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1119,4 +1119,5 @@ Civility=Civility AffectTag=Affect Tag ConfirmAffectTag=Bulk Tag Affect ConfirmAffectTagQuestion=Are you sure you want to affect tags to the %s selected record(s)? -CategTypeNotFound=No tag type found for type of records \ No newline at end of file +CategTypeNotFound=No tag type found for type of records +CopiedToClipboard=Copied to clipboard diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index c4f862863e1..ee60348454e 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -6562,6 +6562,15 @@ div.phpdebugbar-widgets-templates a.phpdebugbar-widgets-editor-link:before } +/* ============================================================================== */ +/* For copypaste feature */ +/* ============================================================================== */ + +.clipboardCPShowOnHover .clipboardCPButton { + display: none; +} + + /* ============================================================================== */ /* CSS style used for small screen */ /* ============================================================================== */