diff --git a/assets/js/legal-analysis.js b/assets/js/legal-analysis.js index f1b0425..ab8712e 100644 --- a/assets/js/legal-analysis.js +++ b/assets/js/legal-analysis.js @@ -56,9 +56,21 @@ handleFiles(e.dataTransfer.files); } }); + // Stop label-for and the input itself from bubbling into the zone click + // handler — otherwise the picker opens twice (native + programmatic). + var browseLabel = uploadZone.querySelector('label[for="' + (uploadInput && uploadInput.id) + '"]'); + if (browseLabel) { + browseLabel.addEventListener('click', function (e) { e.stopPropagation(); }); + } + if (uploadInput) { + uploadInput.addEventListener('click', function (e) { e.stopPropagation(); }); + } uploadZone.addEventListener('click', function (e) { if (e.target === uploadClear || (uploadClear && uploadClear.contains(e.target))) return; - if (e.target.tagName === 'LABEL') return; + if (e.target === uploadInput) return; + // Any label or descendant of a label-for=uploadInput already triggered the input + var lbl = e.target.closest && e.target.closest('label'); + if (lbl && lbl.getAttribute('for') === uploadInput.id) return; if (uploadInput) uploadInput.click(); }); } diff --git a/assets/js/summarize.js b/assets/js/summarize.js index c80df93..2bb2d81 100644 --- a/assets/js/summarize.js +++ b/assets/js/summarize.js @@ -73,9 +73,20 @@ handleFiles(e.dataTransfer.files); } }); + // Stop label-for and the input itself from bubbling into the zone click + // handler — otherwise the picker opens twice (native + programmatic). + var browseLabel = uploadZone.querySelector('label[for="' + (uploadInput && uploadInput.id) + '"]'); + if (browseLabel) { + browseLabel.addEventListener('click', function (e) { e.stopPropagation(); }); + } + if (uploadInput) { + uploadInput.addEventListener('click', function (e) { e.stopPropagation(); }); + } uploadZone.addEventListener('click', function (e) { if (e.target === uploadClear || (uploadClear && uploadClear.contains(e.target))) return; - if (e.target.tagName === 'LABEL') return; + if (e.target === uploadInput) return; + var lbl = e.target.closest && e.target.closest('label'); + if (lbl && lbl.getAttribute('for') === uploadInput.id) return; if (uploadInput) uploadInput.click(); }); }