move of function showValueWithCopyPasteButton in function.lib.php

This commit is contained in:
lmarcouiller
2021-01-22 09:09:46 +01:00
parent 5e94cf09ef
commit 64d08544b2
2 changed files with 39 additions and 37 deletions

View File

@@ -9231,3 +9231,42 @@ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1)
fclose($handle2);
}
}
/**
* Create a button to copy $valuetoprint in the clipboard
* @param string $valuetoprint the value to print
* @param string $spanid unique id for a span
* @param Translate $langs the $langs variable
* @return string the string to print for the button
*/
function showValueWithCopyAndPasteButton($valuetoprint, $spanid, $langs)
{
$stringtoprint= '<span id="'.$spanid.'">';
$stringtoprint.= $valuetoprint .'</span>&ensp;';
$stringtoprint.= '</span>';
$stringtoprint.='<span class="opacitymedium" id="'.dol_escape_json($spanid).'clipboardChar" onclick="'.dol_escape_json($spanid).'clipBoardCopy()"><i " class="far fa-clipboard"></i></span>';
$stringtoprint.="<script>
function ".dol_escape_json($spanid)."clipBoardCopy() {
var copied_text = document.getElementById( \"".dol_escape_json($spanid)."\" );
if ( window.getSelection ) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents( copied_text );
selection.removeAllRanges();
selection.addRange( range );
}
document.execCommand( 'copy' );
window.getSelection().removeAllRanges();
var span = document.getElementById( \"".dol_escape_json($spanid)."clipboardChar\" );
var tmp = span.innerHTML
span.innerHTML = '".dol_escape_js($langs->trans('CopiedToClipboard'))."';
setTimeout(() => { span.innerHTML = tmp; }, 1000);
}
</script>";
return $stringtoprint;
}