미디어위키:Gadget-quickpage.js: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
1번째 줄: 1번째 줄:
/* ▣ QuickEdit “문서 생성 및 편집” 가젯 ▣ */
mw.loader.using(
mw.loader.using(
   ['oojs-ui-core', 'oojs-ui.styles.icons-editing'],
   ['oojs-ui-core', 'oojs-ui.styles.icons-interactions', 'mediawiki.util'],
   function () {
   function () {


     /* ────────── CSS (1회 삽입) ────────── */
     /* ────────── Ⅰ. CSS 스타일 (기존 디자인 유지) ────────── */
if (!document.getElementById('qp-style')) {
    // 기존 사전 모듈과 스타일을 공유하거나, 중복 방지를 위해 ID 체크 후 삽입
  var style = document.createElement('style');
    if (!document.getElementById('quick-edit-style')) {
  style.id = 'qp-style';
      mw.util.addCSS(`
  style.textContent = `
        .oo-ui-inputWidget-input, .oo-ui-buttonElement-button {
.qp-card {
            background: light-dark(#fff, rgb(30,30,30)) !important;
  padding:16px;
            color: var(--text) !important;
  border:1px solid light-dark(#ccc,#555);
            border: 1px solid light-dark(#ccc, #555) !important;
  border-radius:8px;
            height: 36px !important;
  background:light-dark(#f9f9f9,#222);
        }
}
        .oo-ui-inputWidget-input {
  `;
            border-radius: 5px 0 0 5px !important;
  document.head.appendChild(style);
            padding-left: 11px !important;
}
        }
        .oo-ui-buttonElement-button {
            border-radius: 0 5px 5px 0 !important;
            padding-top: 6px;
            padding-bottom: 6px;
        }
        .dict-card {
            padding: 20px 16px 20px; /* 하단 패딩 조정 */
            border: 1px solid light-dark(#ccc, #555);
            border-radius: 8px;
            background: light-dark(#f9f9f9, HSL(200, 5%, 17%));
            margin-bottom: 1em;
        }
      `).id = 'quick-edit-style';
    }


     /* ────────── UI 주입 ────────── */
     /* ────────── Ⅱ. 페이지 로드 시 UI 주입 ────────── */
     mw.hook('wikipage.content').add(function ($content) {
     mw.hook('wikipage.content').add(function ($content) {
       $content.find('.quickpage-container').each(function () {
       $content.find('.quick-edit-container').each(function () {
         var $box = $(this);
         var $box = $(this);
         if ($box.children().length) return;
         if ($box.children().length) return; // 이미 UI가 생성되었으면 중단


         var input = new OO.ui.TextInputWidget({
        // Lua에서 전달한 data 속성 값 가져오기
          placeholder: '문서 제목 입력…'
        var placeholderText = $box.attr('data-placeholder') || '문서 제목...';
        var labelText      = $box.attr('data-label') || '이동';
 
        /* 1) 입력창 + 버튼 생성 (OOUI) */
         var input = new OO.ui.TextInputWidget({  
            placeholder: placeholderText,
            icons: ['article'] // 문서 아이콘
         });
         });
 
         var button = new OO.ui.ButtonWidget({  
         var button = new OO.ui.ButtonWidget({
            label: labelText,  
          label: '문서 생성',
            icon: 'edit',  
          icon: 'edit',
            flags: ['progressive']  
          flags: ['progressive']
         });
         });
 
       
         var field = new OO.ui.ActionFieldLayout(
        // 레이아웃 구성 (Input 옆에 Button)
          input, button, { align: 'top' }
         var field = new OO.ui.ActionFieldLayout(input, button, {align: 'top'});
         );
          
 
        // 컨테이너에 추가
         $box.append(field.$element);
         $box.append(field.$element);


         function go() {
        /* 2) 실행 로직: 편집 URL로 이동 */
          var title = input.getValue().trim();
         function goEdit() {
          if (!title) return;
            var title = input.getValue().trim();
 
            if (!title) return; // 빈 값일 경우 무시
          var encoded = mw.util.wikiUrlencode(title);


          // MediaWiki는 존재 여부와 상관없이 edit로 가면
            // 미디어위키 유틸리티를 사용해 올바른 URL 생성
          // 없으면 생성, 있으면 편집
            // 예: /index.php?title=제목&action=edit
          var url = mw.util.getUrl(encoded, { action: 'edit' });
            var editUrl = mw.util.getUrl(title, { action: 'edit' });
          window.location.href = url;
           
            // 페이지 이동
            window.location.href = editUrl;
         }
         }


         button.on('click', go);
        // 클릭 및 엔터 키 이벤트 연결
         input.on('enter', go);
         button.on('click', goEdit);
         input.on('enter', goEdit);
       });
       });
     });
     });
   }
   }
);
);

2026년 1월 24일 (토) 18:19 판

/* ▣ QuickEdit “문서 생성 및 편집” 가젯 ▣ */
mw.loader.using(
  ['oojs-ui-core', 'oojs-ui.styles.icons-interactions', 'mediawiki.util'],
  function () {

    /* ────────── Ⅰ. CSS 스타일 (기존 디자인 유지) ────────── */
    // 기존 사전 모듈과 스타일을 공유하거나, 중복 방지를 위해 ID 체크 후 삽입
    if (!document.getElementById('quick-edit-style')) {
      mw.util.addCSS(`
        .oo-ui-inputWidget-input, .oo-ui-buttonElement-button {
            background: light-dark(#fff, rgb(30,30,30)) !important;
            color: var(--text) !important;
            border: 1px solid light-dark(#ccc, #555) !important;
            height: 36px !important;
        }
        .oo-ui-inputWidget-input {
            border-radius: 5px 0 0 5px !important;
            padding-left: 11px !important;
        }
        .oo-ui-buttonElement-button {
            border-radius: 0 5px 5px 0 !important;
            padding-top: 6px;
            padding-bottom: 6px;
        }
        .dict-card {
            padding: 20px 16px 20px; /* 하단 패딩 조정 */
            border: 1px solid light-dark(#ccc, #555);
            border-radius: 8px;
            background: light-dark(#f9f9f9, HSL(200, 5%, 17%));
            margin-bottom: 1em;
        }
      `).id = 'quick-edit-style';
    }

    /* ────────── Ⅱ. 페이지 로드 시 UI 주입 ────────── */
    mw.hook('wikipage.content').add(function ($content) {
      $content.find('.quick-edit-container').each(function () {
        var $box = $(this);
        if ($box.children().length) return; // 이미 UI가 생성되었으면 중단

        // Lua에서 전달한 data 속성 값 가져오기
        var placeholderText = $box.attr('data-placeholder') || '문서 제목...';
        var labelText       = $box.attr('data-label') || '이동';

        /* 1) 입력창 + 버튼 생성 (OOUI) */
        var input  = new OO.ui.TextInputWidget({ 
            placeholder: placeholderText, 
            icons: ['article'] // 문서 아이콘
        });
        var button = new OO.ui.ButtonWidget({ 
            label: labelText, 
            icon: 'edit', 
            flags: ['progressive'] 
        });
        
        // 레이아웃 구성 (Input 옆에 Button)
        var field  = new OO.ui.ActionFieldLayout(input, button, {align: 'top'});
        
        // 컨테이너에 추가
        $box.append(field.$element);

        /* 2) 실행 로직: 편집 URL로 이동 */
        function goEdit() {
            var title = input.getValue().trim();
            if (!title) return; // 빈 값일 경우 무시

            // 미디어위키 유틸리티를 사용해 올바른 URL 생성
            // 예: /index.php?title=제목&action=edit
            var editUrl = mw.util.getUrl(title, { action: 'edit' });
            
            // 페이지 이동
            window.location.href = editUrl;
        }

        // 클릭 및 엔터 키 이벤트 연결
        button.on('click', goEdit);
        input.on('enter', goEdit);
      });
    });
  }
);