2017-01-31 07:50:28 +01:00
|
|
|
const Launcher = require('./launcher');
|
|
|
|
const AppSettingsModel = require('../models/app-settings-model');
|
2015-10-29 22:13:15 +01:00
|
|
|
|
2017-01-31 07:50:28 +01:00
|
|
|
const CopyPaste = {
|
2016-01-22 18:51:36 +01:00
|
|
|
simpleCopy: !!Launcher,
|
|
|
|
|
|
|
|
copy: function(text) {
|
|
|
|
if (Launcher) {
|
|
|
|
Launcher.setClipboardText(text);
|
2017-01-31 07:50:28 +01:00
|
|
|
const clipboardSeconds = AppSettingsModel.instance.get('clipboardSeconds');
|
2016-01-22 18:51:36 +01:00
|
|
|
if (clipboardSeconds > 0) {
|
2016-07-17 13:30:38 +02:00
|
|
|
setTimeout(() => {
|
2016-01-22 18:51:36 +01:00
|
|
|
if (Launcher.getClipboardText() === text) {
|
|
|
|
Launcher.clearClipboardText();
|
|
|
|
}
|
|
|
|
}, clipboardSeconds * 1000);
|
2015-11-16 21:36:07 +01:00
|
|
|
}
|
2016-01-22 18:51:36 +01:00
|
|
|
return {success: true, seconds: clipboardSeconds};
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
if (document.execCommand('copy')) {
|
|
|
|
return {success: true};
|
|
|
|
}
|
|
|
|
} catch (e) { }
|
2015-10-17 23:49:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-04-15 16:57:37 +02:00
|
|
|
createHiddenInput: function(text) {
|
2017-01-31 07:50:28 +01:00
|
|
|
const hiddenInput = $('<input/>')
|
2015-10-17 23:49:24 +02:00
|
|
|
.val(text)
|
2017-04-15 16:57:37 +02:00
|
|
|
.attr({ type: 'text', 'class': 'hide-by-pos' })
|
2015-10-27 22:57:56 +01:00
|
|
|
.appendTo(document.body);
|
|
|
|
hiddenInput[0].selectionStart = 0;
|
|
|
|
hiddenInput[0].selectionEnd = text.length;
|
2015-10-29 22:13:15 +01:00
|
|
|
hiddenInput.focus();
|
2015-10-17 23:49:24 +02:00
|
|
|
hiddenInput.on({
|
2016-07-17 13:30:38 +02:00
|
|
|
'copy cut paste': function() { setTimeout(() => hiddenInput.blur(), 0); },
|
2015-10-17 23:49:24 +02:00
|
|
|
blur: function() { hiddenInput.remove(); }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = CopyPaste;
|