Fix mobile search and update resale prices
This commit is contained in:
143
script/nsw.js
143
script/nsw.js
@@ -1,5 +1,7 @@
|
||||
import NSW_DB from '../db/nsw.resale.db.js';
|
||||
|
||||
window.NSW_APP_VERSION = '20260519-mobile-search';
|
||||
|
||||
const SHOW_SOLD_BY_DEFAULT = false;
|
||||
const SHOW_RECOMMENDED_PRICE_RANGE_BY_DEFAULT = false;
|
||||
|
||||
@@ -816,7 +818,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
cero: [],
|
||||
};
|
||||
filterState.searchText = '';
|
||||
document.getElementById('search-input').value = '';
|
||||
document.querySelectorAll('[data-search-input]').forEach(input => {
|
||||
input.value = '';
|
||||
});
|
||||
|
||||
// 게임 목록 다시 렌더링
|
||||
renderGames();
|
||||
@@ -827,25 +831,136 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
// 필터 체크박스 이벤트 리스너 설정
|
||||
function setupFilterListeners() {
|
||||
const searchInput = document.getElementById('search-input');
|
||||
const searchForm = document.getElementById('searchForm');
|
||||
const resetSearch = document.getElementById('reset-search');
|
||||
const searchInputs = [
|
||||
document.getElementById('search-input'),
|
||||
document.getElementById('mobile-search-input'),
|
||||
].filter(Boolean);
|
||||
const searchForms = [document.getElementById('searchForm')].filter(Boolean);
|
||||
const resetSearchButtons = [
|
||||
document.getElementById('reset-search'),
|
||||
document.getElementById('mobile-reset-search'),
|
||||
].filter(Boolean);
|
||||
|
||||
searchForm.addEventListener('submit', event => {
|
||||
event.preventDefault();
|
||||
filterState.searchText = searchInput.value.trim().toLowerCase();
|
||||
function updateSearchText(value) {
|
||||
filterState.searchText = value.trim().toLowerCase();
|
||||
searchInputs.forEach(input => {
|
||||
if (input.value !== value) input.value = value;
|
||||
});
|
||||
renderGames();
|
||||
}
|
||||
|
||||
window.updateNswSearch = value => {
|
||||
updateSearchText(value || '');
|
||||
};
|
||||
|
||||
window.clearNswSearch = () => {
|
||||
updateSearchText('');
|
||||
};
|
||||
|
||||
function updateSearchFromInput(input, options = {}) {
|
||||
window.setTimeout(() => {
|
||||
updateSearchText(input.value);
|
||||
if (options.blur) input.blur();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function isSearchInput(target) {
|
||||
return target instanceof HTMLInputElement && target.matches('[data-search-input]');
|
||||
}
|
||||
|
||||
document.addEventListener(
|
||||
'submit',
|
||||
event => {
|
||||
if (!event.target.querySelector?.('[data-search-input]')) return;
|
||||
event.preventDefault();
|
||||
if (event.stopImmediatePropagation) event.stopImmediatePropagation();
|
||||
event.stopPropagation();
|
||||
const searchInput = event.target.querySelector('[data-search-input]');
|
||||
if (searchInput) updateSearchFromInput(searchInput, { blur: true });
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
document.addEventListener(
|
||||
'input',
|
||||
event => {
|
||||
if (!isSearchInput(event.target)) return;
|
||||
updateSearchText(event.target.value);
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
document.addEventListener(
|
||||
'change',
|
||||
event => {
|
||||
if (!isSearchInput(event.target)) return;
|
||||
updateSearchFromInput(event.target);
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
document.addEventListener(
|
||||
'focusout',
|
||||
event => {
|
||||
if (!isSearchInput(event.target)) return;
|
||||
updateSearchFromInput(event.target);
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
searchForms.forEach(form => {
|
||||
form.addEventListener(
|
||||
'submit',
|
||||
event => {
|
||||
event.preventDefault();
|
||||
if (event.stopImmediatePropagation) event.stopImmediatePropagation();
|
||||
event.stopPropagation();
|
||||
const searchInput = form.querySelector('[data-search-input]');
|
||||
if (searchInput) updateSearchFromInput(searchInput, { blur: true });
|
||||
},
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
searchInput.addEventListener('input', event => {
|
||||
filterState.searchText = event.target.value.trim().toLowerCase();
|
||||
renderGames();
|
||||
searchInputs.forEach(input => {
|
||||
let isComposing = false;
|
||||
|
||||
input.addEventListener('compositionstart', () => {
|
||||
isComposing = true;
|
||||
});
|
||||
|
||||
input.addEventListener('blur', event => {
|
||||
updateSearchFromInput(event.target);
|
||||
});
|
||||
|
||||
input.addEventListener('compositionend', event => {
|
||||
isComposing = false;
|
||||
updateSearchFromInput(event.target);
|
||||
});
|
||||
|
||||
input.addEventListener('keydown', event => {
|
||||
if (event.key !== 'Enter') return;
|
||||
if (isComposing || event.isComposing || event.keyCode === 229) return;
|
||||
event.preventDefault();
|
||||
updateSearchFromInput(event.target, { blur: true });
|
||||
});
|
||||
|
||||
input.addEventListener('keyup', event => {
|
||||
if (isComposing || event.isComposing || event.keyCode === 229) return;
|
||||
updateSearchFromInput(event.target, { blur: event.key === 'Enter' });
|
||||
});
|
||||
});
|
||||
|
||||
resetSearch.addEventListener('click', () => {
|
||||
filterState.searchText = '';
|
||||
searchInput.value = '';
|
||||
renderGames();
|
||||
resetSearchButtons.forEach(button => {
|
||||
function clearSearch(event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
updateSearchText('');
|
||||
}
|
||||
|
||||
button.addEventListener('pointerdown', clearSearch);
|
||||
button.addEventListener('touchstart', clearSearch);
|
||||
button.addEventListener('click', clearSearch);
|
||||
});
|
||||
|
||||
// 언어 필터
|
||||
|
||||
Reference in New Issue
Block a user