1
0
mirror of https://github.com/24eme/signaturepdf.git synced 2023-08-25 09:33:08 +02:00

metadata: autofocus on first input

This commit is contained in:
Vincent LAURENT 2023-04-20 15:43:20 +02:00
parent b30be5b344
commit 4965d7878b

View File

@ -34,14 +34,14 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) {
pdf.getMetadata().then(function(metadata) { pdf.getMetadata().then(function(metadata) {
console.log(metadata); console.log(metadata);
for(fieldKey in defaultFields) { for(fieldKey in defaultFields) {
addMetadata(fieldKey, null, defaultFields[fieldKey]['type']); addMetadata(fieldKey, null, defaultFields[fieldKey]['type'], false);
} }
for(metaKey in metadata.info) { for(metaKey in metadata.info) {
if(metaKey == "Custom" || metaKey == "PDFFormatVersion" || metaKey.match(/^Is/) || metaKey == "Trapped") { if(metaKey == "Custom" || metaKey == "PDFFormatVersion" || metaKey.match(/^Is/) || metaKey == "Trapped") {
continue; continue;
} }
addMetadata(metaKey, metadata.info[metaKey], "text"); addMetadata(metaKey, metadata.info[metaKey], "text", false);
} }
for(metaKey in metadata.info.Custom) { for(metaKey in metadata.info.Custom) {
@ -49,7 +49,7 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) {
continue; continue;
} }
addMetadata(metaKey, metadata.info.Custom[metaKey], "text"); addMetadata(metaKey, metadata.info.Custom[metaKey], "text", false);
} }
for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) { for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) {
@ -59,6 +59,9 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) {
pageRender(pageIndex); pageRender(pageIndex);
}); });
} }
if(document.querySelector('.input-metadata input')) {
document.querySelector('.input-metadata input').focus();
}
}); });
}, function (reason) { }, function (reason) {
console.error(reason); console.error(reason);
@ -94,16 +97,16 @@ var pageRender = async function(pageIndex) {
}); });
} }
var addMetadata = function(key, value, type) { var addMetadata = function(key, value, type, focus) {
let input = document.querySelector('.input-metadata input[name="'+key+'"]'); let input = document.querySelector('.input-metadata input[name="'+key+'"]');
if(input && input.value === null) { if(input && input.value === null) {
input.value = value; input.value = value;
return;
} }
if(input && focus) {
if(input) {
input.focus(); input.focus();
}
if(input) {
return; return;
} }
@ -128,8 +131,10 @@ var addMetadata = function(key, value, type) {
div.appendChild(deleteButton); div.appendChild(deleteButton);
document.getElementById('form-metadata-container').appendChild(div); document.getElementById('form-metadata-container').appendChild(div);
if(focus) {
input.focus(); input.focus();
} }
}
const deleteMetadata = function(el) { const deleteMetadata = function(el) {
if (confirm("Souhaitez-vous supprimer ce champ ?") === false) return; if (confirm("Souhaitez-vous supprimer ce champ ?") === false) return;
@ -164,7 +169,7 @@ const save = async function () {
var createEventsListener = function() { var createEventsListener = function() {
document.getElementById('form_metadata_add').addEventListener('submit', function(e) { document.getElementById('form_metadata_add').addEventListener('submit', function(e) {
let formData = new FormData(this); let formData = new FormData(this);
addMetadata(formData.get('metadata_key'), ""); addMetadata(formData.get('metadata_key'), "", "text", true);
this.classList.add('invisible'); this.classList.add('invisible');
setTimeout(function() { document.getElementById('form_metadata_add').classList.remove('invisible'); }, 400); setTimeout(function() { document.getElementById('form_metadata_add').classList.remove('invisible'); }, 400);
this.reset(); this.reset();