2
0
forked from Wavyzz/dolibarr

NEW Add function showValueWithCopyAndPasteButton() to add a copy/paste

button on a text.
This commit is contained in:
Laurent Destailleur
2021-01-28 12:34:54 +01:00
parent 1a7f3938f2
commit ce3279c462
5 changed files with 38 additions and 16 deletions

View File

@@ -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";

View File

@@ -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 = '<span class="clipboardCopyPaste"><span class="clipboardCopyPasteValue">'.$valuetoprint.'</span><span class="far fa-clipboard clipboardCopyPasteButton opacitymedium paddingleft paddingright"></span></span>';
$result = '<span class="clipboardCP'.($showonlyonhover ? ' clipboardCPShowOnHover' : '').'"><span class="clipboardCPValue">'.$valuetoprint.'</span><span class="clipboardCPButton far fa-clipboard opacitymedium paddingleft paddingright"></span><span class="clipboardCPText opacitymedium"></span></span>';
return $result;
}

View File

@@ -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

View File

@@ -1120,3 +1120,4 @@ 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
CopiedToClipboard=Copied to clipboard

View File

@@ -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 */
/* ============================================================================== */