mirror of
https://github.com/Coldsmiles/infstarweb.git
synced 2026-04-23 02:30:41 +08:00
feat: enhance contributor input handling to allow space for adding names
This commit is contained in:
@@ -256,7 +256,7 @@
|
|||||||
<label>贡献/维护人员</label>
|
<label>贡献/维护人员</label>
|
||||||
<div class="tags-input-wrapper" id="editor-contributors-wrapper">
|
<div class="tags-input-wrapper" id="editor-contributors-wrapper">
|
||||||
<div class="tags-list" id="editor-contributors-tags"></div>
|
<div class="tags-list" id="editor-contributors-tags"></div>
|
||||||
<input type="text" id="editor-contributor-input" placeholder="输入名称后按回车添加...">
|
<input type="text" id="editor-contributor-input" placeholder="输入名称后按回车或空格添加...">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|||||||
@@ -485,6 +485,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function commitContributorInput() {
|
||||||
|
const contributorInput = document.getElementById('editor-contributor-input');
|
||||||
|
const value = contributorInput.value.trim();
|
||||||
|
|
||||||
|
if (value && !editorContributors.includes(value)) {
|
||||||
|
editorContributors.push(value);
|
||||||
|
renderContributorTags();
|
||||||
|
updatePreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
contributorInput.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('editor-contributors-tags').addEventListener('click', (e) => {
|
document.getElementById('editor-contributors-tags').addEventListener('click', (e) => {
|
||||||
const removeBtn = e.target.closest('.editor-tag-remove');
|
const removeBtn = e.target.closest('.editor-tag-remove');
|
||||||
if (removeBtn) {
|
if (removeBtn) {
|
||||||
@@ -496,16 +509,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('editor-contributor-input').addEventListener('keydown', (e) => {
|
document.getElementById('editor-contributor-input').addEventListener('keydown', (e) => {
|
||||||
if (e.key === 'Enter') {
|
if (e.isComposing) {
|
||||||
e.preventDefault();
|
return;
|
||||||
const val = e.target.value.trim();
|
|
||||||
if (val && !editorContributors.includes(val)) {
|
|
||||||
editorContributors.push(val);
|
|
||||||
renderContributorTags();
|
|
||||||
updatePreview();
|
|
||||||
}
|
|
||||||
e.target.value = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.key === 'Enter' || e.key === ' ' || e.code === 'Space') {
|
||||||
|
e.preventDefault();
|
||||||
|
commitContributorInput();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('editor-contributor-input').addEventListener('blur', () => {
|
||||||
|
commitContributorInput();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Click on wrapper focuses input
|
// Click on wrapper focuses input
|
||||||
|
|||||||
Reference in New Issue
Block a user