메뉴 여닫기
환경 설정 메뉴 여닫기
개인 메뉴 여닫기
로그인하지 않음
만약 지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

미디어위키:Common.js

novawiki
Demian (토론 | 기여)님의 2026년 1월 17일 (토) 18:52 판

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.

  • 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
  • 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
  • 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
  • 오페라: Ctrl-F5를 입력.
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */

/**
 * Citizen search: open + focus immediately on user gesture (iOS-friendly)
 * - Intercepts tap on the <summary> so focus stays within the gesture stack
 * - Manually opens <details> and focuses #searchInput right away
 */
(function () {
  const DETAILS_ID = 'citizen-search-details';
  const TOGGLE_SEL = '#citizen-search-details > summary.citizen-dropdown-summary';
  const INPUT_ID = 'searchInput';

  function openAndFocus() {
    const details = document.getElementById(DETAILS_ID);
    const input = document.getElementById(INPUT_ID);

    if (!details || !input) return;

    // Open immediately (within the same user gesture)
    if (!details.open) details.open = true;

    // Force a tiny layout sync so iOS is less flaky about focus
    // (Reading offsetHeight triggers reflow; yes it's old-school, yes it works)
    void input.offsetHeight;

    input.focus({ preventScroll: true });
    input.click(); // helps some mobile engines trigger the keyboard
  }

  // Use the earliest possible gesture event
  document.addEventListener(
    'touchstart',
    function (e) {
      const toggle = e.target.closest(TOGGLE_SEL);
      if (!toggle) return;

      // Stop the default summary toggle so we control timing
      e.preventDefault();
      e.stopPropagation();

      openAndFocus();
    },
    { capture: true, passive: false } // passive:false is REQUIRED for preventDefault on iOS
  );

  // Fallback for non-touch / weird cases
  document.addEventListener(
    'click',
    function (e) {
      const toggle = e.target.closest(TOGGLE_SEL);
      if (!toggle) return;

      e.preventDefault();
      e.stopPropagation();

      openAndFocus();
    },
    true
  );
})();