diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index 9f4e69dcadf..66a57502bb1 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -210,3 +210,25 @@ 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 ) { + + selection = window.getSelection(); + + range = document.createRange(); + range.selectNodeContents( this.firstChild ); + + selection.removeAllRanges(); + selection.addRange( range ); + + } + document.execCommand( \'copy\' ); + window.getSelection().removeAllRanges(); + var lastchild = this.lastChild + var tmp =lastchild.innerHTML + lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\'; + setTimeout(() => { lastchild.innerHTML = tmp; }, 1000); + })'."\n"; \ No newline at end of file diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d8a1614cfdc..d90e70a1e0c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9239,34 +9239,9 @@ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1) * @param Translate $langs the $langs variable * @return string the string to print for the button */ -function showValueWithCopyAndPasteButton($valuetoprint, $spanid, $langs) +function showValueWithCopyAndPasteButton($valuetoprint) { - $stringtoprint= ''; - $stringtoprint.= $valuetoprint .' '; - $stringtoprint.= ''; - $stringtoprint.=''; - $stringtoprint.=""; - return $stringtoprint; + return ''.dol_escape_js($valuetoprint).' + '; + } diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 0014e4b8ebe..caf3b62bd02 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2426,7 +2426,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print $langs->trans('CustomerCode'); print ''; print ''; - print showValueWithCopyAndPasteButton($object->code_client, 'code_client', $langs); + print showValueWithCopyAndPasteButton($object->code_client); print ''; $tmpcheck = $object->check_codeclient(); if ($tmpcheck != 0 && $tmpcheck != -5) {