1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-27 07:45:08 +02:00
keeweb/app/scripts/util/copy-paste.js

33 lines
1.0 KiB
JavaScript
Raw Normal View History

2015-10-17 23:49:24 +02:00
'use strict';
var CopyPaste = {
tryCopy: function() {
try {
return document.execCommand('copy');
} catch (e) {
return false;
}
},
2015-10-27 22:57:56 +01:00
createHiddenInput: function(text, pos) {
2015-10-17 23:49:24 +02:00
var hiddenInput = $('<input/>')
.val(text)
2015-10-27 22:57:56 +01:00
.attr({ type: 'text', readonly: true, 'class': pos ? '' : 'hide-by-pos' })
.appendTo(document.body);
if (pos) {
hiddenInput.css({ position: 'absolute', zIndex: 100, padding: 0,
border: 'none', background: 'transparent', color: 'transparent',
left: pos.left, top: pos.top, width: pos.width, height: pos.height });
}
hiddenInput.focus();
hiddenInput[0].selectionStart = 0;
hiddenInput[0].selectionEnd = text.length;
2015-10-17 23:49:24 +02:00
hiddenInput.on({
'copy': function() { setTimeout(function() { hiddenInput.blur(); }, 0); },
blur: function() { hiddenInput.remove(); }
});
}
};
module.exports = CopyPaste;