1
0
Fork 0
mirror of https://github.com/Alamantus/Lexiconga.git synced 2025-06-06 01:06:36 +02:00

Fix event problem

This commit is contained in:
Robbie Antenesse 2024-12-13 23:24:30 -07:00
parent 68b97e2267
commit 89fa069d42
3 changed files with 21 additions and 18 deletions

View file

@ -148,8 +148,8 @@ export function renderWords() {
// } // }
// } // }
export function renderEditForm(wordId = false) { export function renderEditForm(event = false) {
wordId = typeof wordId.target === 'undefined' ? wordId : parseInt(this.id.replace('edit_', '')); const wordId = typeof event.target === 'undefined' ? event : parseInt(event.target.id.replace('edit_', ''));
const word = window.currentDictionary.words.find(w => w.wordId === wordId); const word = window.currentDictionary.words.find(w => w.wordId === wordId);
if (word) { if (word) {
const escapeQuotes = (value) => value.replace(/"/g, '"'); const escapeQuotes = (value) => value.replace(/"/g, '"');

View file

@ -3,7 +3,7 @@ import { enableHotKeys } from '../hotkeys';
import { dismiss } from '../announcements'; import { dismiss } from '../announcements';
import { handleDetailClicks, setupEditFormInteractions } from './details'; import { handleDetailClicks, setupEditFormInteractions } from './details';
import { setupWordForm, handleWordFormClicks, handleWordOptionClicks, handleWordEditFormButtonClicks } from './words'; import { setupWordForm, handleWordFormClicks, handleWordOptionClicks, handleWordEditFormButtonClicks } from './words';
import { setupInfoButtons, handleIPAButtonClicks, handleMaximizeButtonClicks, handleInfoButtonClicks, handleHeaderButtonClicks } from './buttons'; import { handleIPAButtonClicks, handleMaximizeButtonClicks, handleInfoButtonClicks, handleHeaderButtonClicks } from './buttons';
import { setupTemplateChangeEvents, setupTemplateSelectOptions } from './settings'; import { setupTemplateChangeEvents, setupTemplateSelectOptions } from './settings';
import { setupSearchBarEvents } from './search'; import { setupSearchBarEvents } from './search';
@ -15,7 +15,6 @@ export default function setupListeners() {
setupSearchBarEvents(); setupSearchBarEvents();
setupWordForm(); setupWordForm();
setupInfoButtons();
setupTemplateSelectOptions(); setupTemplateSelectOptions();
if (window.settings.useHotkeys) { if (window.settings.useHotkeys) {
enableHotKeys(); enableHotKeys();

View file

@ -164,17 +164,21 @@ export function getWordReferenceMarkdown(reference) {
return reference; return reference;
} }
export function expandAdvancedForm(id = false) { let expandAdvancedFormTimeout = null;
const wordId = typeof id.target !== 'undefined' ? this.id.replace('expandAdvancedForm', '') : id; export function expandAdvancedForm(event = false) {
const button = typeof id.target !== 'undefined' ? this : document.getElementById('expandAdvancedForm' + (!wordId ? '' : wordId)), const wordId = typeof event.target !== 'undefined' ? event.target.id.replace('expandAdvancedForm', '') : event;
const button = typeof event.target !== 'undefined' ? event.target : document.getElementById('expandAdvancedForm' + (!wordId ? '' : wordId)),
form = document.getElementById('advancedForm' + (!wordId ? '' : wordId)); form = document.getElementById('advancedForm' + (!wordId ? '' : wordId));
if (form.style.display !== 'block') { clearTimeout(expandAdvancedFormTimeout);
button.innerText = 'Hide Advanced Fields'; expandAdvancedFormTimeout = setTimeout(() => {
form.style.display = 'block'; if (form.style.display !== 'block') {
} else { button.innerText = 'Hide Advanced Fields';
button.innerText = 'Show Advanced Fields'; form.style.display = 'block';
form.style.display = 'none'; } else {
} button.innerText = 'Show Advanced Fields';
form.style.display = 'none';
}
}, 10)
} }
export function submitWordForm() { export function submitWordForm() {
@ -305,8 +309,8 @@ export function updateWord(word, wordId) {
} }
} }
export function confirmEditWord(id) { export function confirmEditWord(event) {
const wordId = typeof id.target !== 'undefined' ? parseInt(this.id.replace('editWordButton_', '')) : id; const wordId = typeof event.target !== 'undefined' ? parseInt(event.target.id.replace('editWordButton_', '')) : event;
const name = document.getElementById('wordName_' + wordId).value, const name = document.getElementById('wordName_' + wordId).value,
pronunciation = document.getElementById('wordPronunciation_' + wordId).value, pronunciation = document.getElementById('wordPronunciation_' + wordId).value,
partOfSpeech = document.getElementById('wordPartOfSpeech_' + wordId).value, partOfSpeech = document.getElementById('wordPartOfSpeech_' + wordId).value,
@ -345,8 +349,8 @@ export function confirmEditWord(id) {
} }
} }
export function cancelEditWord() { export function cancelEditWord(event) {
const wordId = parseInt(this.parentElement.id.replace('editForm_', '')); const wordId = parseInt(event.target.parentElement.id.replace('editForm_', ''));
if (confirm(`Are you sure you want to cancel?\n(Any changes will be lost!)`)) { if (confirm(`Are you sure you want to cancel?\n(Any changes will be lost!)`)) {
document.getElementById('editForm_' + wordId).classList.add('done'); document.getElementById('editForm_' + wordId).classList.add('done');
renderWords(); renderWords();