다른 명령
편집 요약 없음 태그: 수동 되돌리기 |
편집 요약 없음 |
||
| 7번째 줄: | 7번째 줄: | ||
*/ | */ | ||
(function () { | (function () { | ||
function focusSearchInput() { | |||
const input = | |||
document.querySelector('.citizen-search__input') || | |||
document.querySelector('#searchInput') || | |||
document.querySelector('input[type="search"]'); | |||
if (!input) return false; | |||
// | // iOS는 visible/enable 상태 아니면 focus 무시하는 경우 많음 | ||
document. | input.focus({ preventScroll: true }); | ||
// | |||
const isSearchButton = | // 어떤 iOS 버전/스킨 조합에서는 click이 키보드 트리거에 도움됨 | ||
input.click(); | |||
return document.activeElement === input; | |||
} | |||
// "유저 제스처"로 인정받기 좋은 이벤트들 | |||
const EVENTS = ['touchend', 'pointerup', 'mouseup', 'click']; | |||
EVENTS.forEach((evt) => { | |||
document.addEventListener( | |||
evt, | |||
function (e) { | |||
// 검색 버튼/아이콘 후보들(필요하면 여기 셀렉터만 너 환경에 맞게 좁히면 됨) | |||
const isSearchButton = e.target.closest( | |||
'.citizen-search__button, .mw-ui-icon-search, .search-toggle, a[title="Search"], button[title="Search"]' | |||
); | |||
if (!isSearchButton) return; | if (!isSearchButton) return; | ||
// | // 1) 즉시 시도 (가장 iOS 친화적) | ||
requestAnimationFrame(() => requestAnimationFrame( | if (focusSearchInput()) return; | ||
// 2) UI가 한 프레임 늦게 뜨면 1~2 프레임 양보 | |||
requestAnimationFrame(() => { | |||
if (focusSearchInput()) return; | |||
requestAnimationFrame(() => focusSearchInput()); | |||
}); | |||
}, | |||
true // 캡처링: 스킨/확장이 stopPropagation 해도 이쪽이 먼저 받을 확률 ↑ | |||
); | |||
}); | |||
})(); | })(); | ||
2026년 1월 17일 (토) 18:40 판
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
/**
* Autofocus search input on mobile
* Triggered when MobileFrontend search UI opens
* Improves UX by immediately opening the virtual keyboard
*/
(function () {
function focusSearchInput() {
const input =
document.querySelector('.citizen-search__input') ||
document.querySelector('#searchInput') ||
document.querySelector('input[type="search"]');
if (!input) return false;
// iOS는 visible/enable 상태 아니면 focus 무시하는 경우 많음
input.focus({ preventScroll: true });
// 어떤 iOS 버전/스킨 조합에서는 click이 키보드 트리거에 도움됨
input.click();
return document.activeElement === input;
}
// "유저 제스처"로 인정받기 좋은 이벤트들
const EVENTS = ['touchend', 'pointerup', 'mouseup', 'click'];
EVENTS.forEach((evt) => {
document.addEventListener(
evt,
function (e) {
// 검색 버튼/아이콘 후보들(필요하면 여기 셀렉터만 너 환경에 맞게 좁히면 됨)
const isSearchButton = e.target.closest(
'.citizen-search__button, .mw-ui-icon-search, .search-toggle, a[title="Search"], button[title="Search"]'
);
if (!isSearchButton) return;
// 1) 즉시 시도 (가장 iOS 친화적)
if (focusSearchInput()) return;
// 2) UI가 한 프레임 늦게 뜨면 1~2 프레임 양보
requestAnimationFrame(() => {
if (focusSearchInput()) return;
requestAnimationFrame(() => focusSearchInput());
});
},
true // 캡처링: 스킨/확장이 stopPropagation 해도 이쪽이 먼저 받을 확률 ↑
);
});
})();