Remove content editable element

Non longer necessary. It works on Safari, Chrome and Firefox
This commit is contained in:
Frédéric Guillot
2023-05-17 21:17:47 -07:00
committed by Frédéric Guillot
parent 26b6eebb78
commit c9c1872067
2 changed files with 5 additions and 74 deletions

View File

@@ -1,5 +1,4 @@
KB.component('screenshot', function (containerElement) {
var pasteCatcher = null;
var inputElement = null;
function onFileLoaded(e) {
@@ -7,7 +6,6 @@ KB.component('screenshot', function (containerElement) {
}
function onPaste(e) {
// Firefox doesn't have the property e.clipboardData.items (only Chrome)
if (e.clipboardData && e.clipboardData.items) {
var items = e.clipboardData.items;
@@ -24,69 +22,13 @@ KB.component('screenshot', function (containerElement) {
}
}
}
} else {
// Handle Firefox
setTimeout(checkInput, 100);
}
}
function initialize() {
destroy();
if (! window.Clipboard) {
// Insert the content editable at the top to avoid scrolling down in the board view
pasteCatcher = document.createElement('template');
pasteCatcher.id = 'screenshot-pastezone';
pasteCatcher.contentEditable = true;
pasteCatcher.style.opacity = 0;
pasteCatcher.style.position = 'fixed';
pasteCatcher.style.top = 0;
pasteCatcher.style.right = 0;
pasteCatcher.style.width = 0;
document.body.insertBefore(pasteCatcher, document.body.firstChild);
pasteCatcher.focus();
// Set the focus when clicked anywhere in the document
document.addEventListener('click', setFocus);
// Set the focus when clicked in screenshot dropzone
document.getElementById('screenshot-zone').addEventListener('click', setFocus);
}
window.addEventListener('paste', onPaste, false);
}
function destroy() {
if (KB.exists('#screenshot-pastezone')) {
KB.find('#screenshot-pastezone').remove();
}
document.removeEventListener('click', setFocus);
pasteCatcher = null;
}
function setFocus() {
if (pasteCatcher !== null) {
pasteCatcher.focus();
}
}
function checkInput() {
var child = pasteCatcher.childNodes[0];
if (child) {
// If the user pastes an image, the src attribute
// will represent the image as a base64 encoded string.
if (child.tagName === 'IMG') {
createImage(child.src);
}
}
pasteCatcher.innerHTML = '';
}
function createImage(blob) {
var pastedImage = new Image();
pastedImage.src = blob;
@@ -102,14 +44,9 @@ KB.component('screenshot', function (containerElement) {
zone.className = 'screenshot-pasted';
zone.appendChild(pastedImage);
destroy();
initialize();
}
KB.on('modal.close', function () {
destroy();
});
this.render = function () {
inputElement = KB.dom('input')
.attr('type', 'hidden')