Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -43,6 +43,35 @@ function removeReference(idx) {
|
|
| 43 |
_scheduleAutosave();
|
| 44 |
}
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
function _renderRefPills() {
|
| 47 |
const container = document.getElementById("refPills");
|
| 48 |
if (_currentReferences.length === 0) {
|
|
@@ -53,7 +82,7 @@ function _renderRefPills() {
|
|
| 53 |
.map(
|
| 54 |
(ref, i) => `
|
| 55 |
<span class="ref-pill">
|
| 56 |
-
${_esc(ref)}
|
| 57 |
<button onclick="removeReference(${i})" title="Xoá">×</button>
|
| 58 |
</span>
|
| 59 |
`,
|
|
|
|
| 43 |
_scheduleAutosave();
|
| 44 |
}
|
| 45 |
|
| 46 |
+
function editReference(idx) {
|
| 47 |
+
const current = _currentReferences[idx];
|
| 48 |
+
const container = document.getElementById("refPills");
|
| 49 |
+
const pill = container.querySelectorAll(".ref-pill")[idx];
|
| 50 |
+
if (!pill) return;
|
| 51 |
+
|
| 52 |
+
const input = document.createElement("input");
|
| 53 |
+
input.className = "ref-pill-edit";
|
| 54 |
+
input.value = current;
|
| 55 |
+
pill.innerHTML = "";
|
| 56 |
+
pill.appendChild(input);
|
| 57 |
+
input.focus();
|
| 58 |
+
input.select();
|
| 59 |
+
|
| 60 |
+
function commit() {
|
| 61 |
+
const val = input.value.trim();
|
| 62 |
+
if (val && val !== current) {
|
| 63 |
+
_currentReferences[idx] = val;
|
| 64 |
+
_scheduleAutosave();
|
| 65 |
+
}
|
| 66 |
+
_renderRefPills();
|
| 67 |
+
}
|
| 68 |
+
input.addEventListener("keydown", (e) => {
|
| 69 |
+
if (e.key === "Enter") { e.preventDefault(); commit(); }
|
| 70 |
+
if (e.key === "Escape") _renderRefPills();
|
| 71 |
+
});
|
| 72 |
+
input.addEventListener("blur", commit);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
function _renderRefPills() {
|
| 76 |
const container = document.getElementById("refPills");
|
| 77 |
if (_currentReferences.length === 0) {
|
|
|
|
| 82 |
.map(
|
| 83 |
(ref, i) => `
|
| 84 |
<span class="ref-pill">
|
| 85 |
+
<span class="ref-pill-text" onclick="editReference(${i})" title="Nhấn để sửa">${_esc(ref)}</span>
|
| 86 |
<button onclick="removeReference(${i})" title="Xoá">×</button>
|
| 87 |
</span>
|
| 88 |
`,
|