keeweb/app/scripts/util/copy-paste.js

27 lines
676 B
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;
}
},
createHiddenInput: function(text) {
var hiddenInput = $('<input/>')
.attr({ type: 'text', readonly: true, 'class': 'hide-by-pos' })
.val(text)
.appendTo(document.body)
.focus();
hiddenInput[0].select();
hiddenInput.on({
'copy': function() { setTimeout(function() { hiddenInput.blur(); }, 0); },
blur: function() { hiddenInput.remove(); }
});
}
};
module.exports = CopyPaste;