mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-15 22:11:36 +01:00
move of function showValueWithCopyPasteButton in function.lib.php
This commit is contained in:
@@ -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> ';
|
||||
$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;
|
||||
}
|
||||
Reference in New Issue
Block a user