Repository URL to install this package:
|
Version:
3.12.2 ▾
|
/**
* Copies any text passed to the parameter with showing confirmation message in case of success
* or showing an prompt for handling the copy manually if the browser doesn't support auto copy
*
* @returns {boolean}
*
* @param {string} text -- The string to be copied
* @param {Function} i18n -- The translation function for translating the shown confirmation message - eg. plugin.i18n
* @param {Function} logInfo -- The filerobot info function for showing confirmation message - eg. plugin.filerobot.info
*/
export default (function (text) {
var i18n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var logInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var tempLinkElem = document.createElement('input');
tempLinkElem.value = text;
tempLinkElem.style = 'position: absolute; z-index: -1111; left: -11111px; top: -111111px';
document.body.appendChild(tempLinkElem);
tempLinkElem.select();
tempLinkElem.setSelectionRange(0, 99999); // For phones
var isCopied = document.execCommand('copy');
document.body.removeChild(tempLinkElem);
if (isCopied) {
if (logInfo && i18n) {
logInfo(i18n('mutualizedFileLinkCopiedInfo', 'Copied successfully!'), 'success', 3000);
}
return true;
} else {
prompt(i18n('linkCopyFailed', 'Copy failure!'), text);
return false;
}
});