편집 요약 없음 |
편집 요약 없음 |
||
21번째 줄: | 21번째 줄: | ||
.dict-card {padding:0px 16px 8px; border:1px solid light-dark(#ccc, #555);border-radius:8px; | .dict-card {padding:0px 16px 8px; border:1px solid light-dark(#ccc, #555);border-radius:8px; | ||
background:light-dark(#f9f9f9, HSL(200, 5%, 17%)); padding-top: } | background:light-dark(#f9f9f9, HSL(200, 5%, 17%)); padding-top: } | ||
.dict-card .term{font-weight:600;font-size:1.2em;margin-right:.4em; padding:8px; padding-bottom: | .dict-card .term{font-weight:600;font-size:1.2em;margin-right:.4em; padding:8px; padding-bottom: 3px;} | ||
.dict-card .def{padding-left:8px; padding-right:8px; padding-bottom: 8px;} | .dict-card .def{padding-left:8px; padding-right:8px; padding-bottom: 8px;} | ||
.dict-none {padding:8px;color:light-dark(#d33, HSL(0, 71%, 75%));} | .dict-none {padding:8px;color:light-dark(#d33, HSL(0, 71%, 75%));} | ||
59번째 줄: | 59번째 줄: | ||
if (dict.hasOwnProperty(key)) { | if (dict.hasOwnProperty(key)) { | ||
$result.html( | $result.html( | ||
'<div class="term">' + mw.html.escape(q) + '</div>' + | '<div class="term">' + mw.html.escape(q) + '</div><hr>' + | ||
'<div class="def">' + mw.html.escape(dict[key]) + '</div>' | '<div class="def">' + mw.html.escape(dict[key]) + '</div>' | ||
); | ); |
2025년 6월 29일 (일) 03:27 판
/* ▣ Dictionary “검색 전용” 가젯 ▣
- 페이지에 .dictionary-container 가 있을 때만 동작
- 표 없이: 검색 → 결과 카드 or “없음” 메시지
-------------------------------------------------- */
mw.loader.using(
['oojs-ui-core', 'oojs-ui.styles.icons-interactions'],
function () {
/* 사전 JSON 로드 */
var jsonNode = document.getElementById('dictionary-json');
if (!jsonNode) return; // 사전 없는 페이지
var dictRaw = JSON.parse(jsonNode.textContent);
var dict = {}; // 소문자 키 → 정의
Object.keys(dictRaw).forEach(function (k) {
dict[k.toLowerCase()] = dictRaw[k];
});
/* 한 번만 카드/없음 CSS 삽입 */
if (!document.getElementById('dict-card-style')) {
mw.util.addCSS(`
.dict-card {padding:0px 16px 8px; border:1px solid light-dark(#ccc, #555);border-radius:8px;
background:light-dark(#f9f9f9, HSL(200, 5%, 17%)); padding-top: }
.dict-card .term{font-weight:600;font-size:1.2em;margin-right:.4em; padding:8px; padding-bottom: 3px;}
.dict-card .def{padding-left:8px; padding-right:8px; padding-bottom: 8px;}
.dict-none {padding:8px;color:light-dark(#d33, HSL(0, 71%, 75%));}
`).id = 'dict-card-style';
}
/* 콘텐츠 훅: 컨테이너마다 UI 주입 */
mw.hook('wikipage.content').add(function ($content) {
$content.find('.dictionary-container').each(function () {
var $box = $(this);
if ($box.children().length) return; // 중복 방지
/* 1) 입력창 + 버튼 */
var input = new OO.ui.TextInputWidget({
placeholder: '단어 입력…', icons:['search']
});
var button = new OO.ui.ButtonWidget({
label:'검색', icon:'search', flags:['progressive']
});
var field = new OO.ui.ActionFieldLayout(input, button, {align:'top'})
.$element.css('margin-bottom','10px');
/* 2) 결과 영역 */
var $result = $('<div class="dict-result"></div>');
$box.append(field, $result);
/* 3) 검색 실행 */
function run() {
var q = input.getValue().trim();
var key = q.toLowerCase();
if (!q) {
$result.empty();
return;
}
if (dict.hasOwnProperty(key)) {
$result.html(
'<div class="term">' + mw.html.escape(q) + '</div><hr>' +
'<div class="def">' + mw.html.escape(dict[key]) + '</div>'
);
} else {
$result.html('<div class="dict-none">해당 단어가 없습니다.</div>');
}
}
button.on('click', run);
input.on('enter', run);
});
});
}
);