1
0
forked from ScoDoc/ScoDoc

Copié/collé notes: fix #990

This commit is contained in:
Emmanuel Viennet 2024-09-09 21:23:20 +02:00
parent 368914ebf7
commit a3a71a3f4f

View File

@ -6,12 +6,7 @@ document.addEventListener("DOMContentLoaded", function () {
input.addEventListener("input", function() { input.addEventListener("input", function() {
this.setAttribute("data-modified", "true"); this.setAttribute("data-modified", "true");
}); });
input.addEventListener("blur", function() { input.addEventListener("blur", input.addEventListener("blur", function(event){write_on_blur(event.currentTarget)} ));
if (this.getAttribute("data-modified") === "true" && this.value !== this.getAttribute("data-last-saved-value")) {
valid_note.call(this);
this.setAttribute("data-modified", "false"); // Reset the modified flag
}
});
}); });
var formInputs = document.querySelectorAll("#formnotes input"); var formInputs = document.querySelectorAll("#formnotes input");
@ -23,6 +18,13 @@ document.addEventListener("DOMContentLoaded", function () {
masquerBtn.addEventListener("click", masquer_DEM); masquerBtn.addEventListener("click", masquer_DEM);
}); });
function write_on_blur(elt) {
if (elt.getAttribute("data-modified") === "true" && elt.value !== elt.getAttribute("data-last-saved-value")) {
valid_note.call(elt);
elt.setAttribute("data-modified", "false"); // Reset the modified flag
}
}
function is_valid_note(v) { function is_valid_note(v) {
if (!v) return true; if (!v) return true;
@ -143,11 +145,10 @@ function change_history(e) {
// Contribution S.L.: copier/coller des notes // Contribution S.L.: copier/coller des notes
function paste_text(e) { function paste_text(event) {
var event = e.originalEvent;
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
var clipb = e.originalEvent.clipboardData; var clipb = event.clipboardData;
var data = clipb.getData("Text"); var data = clipb.getData("Text");
var list = data.split(/\r\n|\r|\n|\t| /g); var list = data.split(/\r\n|\r|\n|\t| /g);
var currentInput = event.currentTarget; var currentInput = event.currentTarget;
@ -159,9 +160,11 @@ function paste_text(e) {
if (!currentInput.disabled) { // skip DEM if (!currentInput.disabled) { // skip DEM
currentInput.value = list[i]; currentInput.value = list[i];
} }
var evt = document.createEvent("HTMLEvents"); // --- trigger blur
evt.initEvent("blur", false, true); currentInput.setAttribute("data-modified", "true");
var evt = new Event("blur", { bubbles: true, cancelable: true});
currentInput.dispatchEvent(evt); currentInput.dispatchEvent(evt);
// --- next input
var sibbling = currentInput.parentElement.parentElement.nextElementSibling; var sibbling = currentInput.parentElement.parentElement.nextElementSibling;
while ( while (
sibbling && sibbling &&