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