mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: simplify
This commit is contained in:
1 parent
00bdea78d2
commit
df85677ea5
1 file changed
+17
-31
@@ -176,51 +176,37 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
|
|||||||
async function loadObjective() {
|
async function loadObjective() {
|
||||||
$('.outer-loader-container').show();
|
$('.outer-loader-container').show();
|
||||||
const ans = {};
|
const ans = {};
|
||||||
let objNum = 0;
|
let cnt = 0;
|
||||||
const reg = /{{ (input|select|multiselect)\(\d+(-\d+)?\) }}/g;
|
const reg = /{{ (input|select|multiselect)\(\d+(-\d+)?\) }}/g;
|
||||||
$('.problem-content .typo').children().each((i, e) => {
|
$('.problem-content .typo').children().each((i, e) => {
|
||||||
if (e.tagName === 'PRE' && !e.children[0].className.includes('#input')) return;
|
if (e.tagName === 'PRE' && !e.children[0].className.includes('#input')) return;
|
||||||
const objQuestions = [];
|
const questions = [];
|
||||||
let objQuestion = reg.exec(e.innerText);
|
let q;
|
||||||
while (objQuestion != null) {
|
while (q = reg.exec(e.innerText)) questions.push(q); // eslint-disable-line no-cond-assign
|
||||||
objQuestions.push(objQuestion);
|
for (const [info, type] of questions) {
|
||||||
objQuestion = reg.exec(e.innerText);
|
cnt++;
|
||||||
}
|
const id = info.replace(/{{ (input|select|multiselect)\((\d+(-\d+)?)\) }}/, '$2');
|
||||||
objQuestions.forEach((obj) => {
|
if (type === 'input') {
|
||||||
objNum++;
|
$(e).html($(e).html().replace(info, `
|
||||||
const [objData, objType] = obj;
|
<div class="objective_${id} medium-3" style="display: inline-block;">
|
||||||
const objID = objData.replace(/{{ (input|select|multiselect)\((\d+(-\d+)?)\) }}/, '$2');
|
<input type="text" name="${id}" class="textbox objective-input">
|
||||||
if (objType === 'input') {
|
|
||||||
$(e).html($(e).html().replace(objData, `
|
|
||||||
<div class="objective_${objID} medium-3" style="display: inline-block;">
|
|
||||||
<input type="text" placeholder="Question${objNum} ${objID}" name="${objID}" class="textbox objective-input">
|
|
||||||
</div>
|
</div>
|
||||||
`));
|
`));
|
||||||
} else if (objType === 'select') {
|
} else {
|
||||||
$(e).html($(e).html().replace(objData, `Question${objNum}_${objID}:`));
|
$(e).html($(e).html().replace(info, ''));
|
||||||
$(e).next('ul').children().each((j, ele) => {
|
$(e).next('ul').children().each((j, ele) => {
|
||||||
$(ele).after(`
|
$(ele).after(`
|
||||||
<div class="objective_${objID} radiobox">
|
<div class="objective_${id} radiobox">
|
||||||
<input type="radio" name="${objID}" class="objective-input" value="${String.fromCharCode(65 + j)}">
|
<input type="${type === 'select' ? 'radio' : 'checkbox'}" name="${id}" class="objective-input" value="${String.fromCharCode(65 + j)}">
|
||||||
${String.fromCharCode(65 + j)}. ${ele.innerHTML}
|
|
||||||
</div>`);
|
|
||||||
$(ele).remove();
|
|
||||||
});
|
|
||||||
} else if (objType === 'multiselect') {
|
|
||||||
$(e).html($(e).html().replace(objData, `Question${objNum}_${objID}:`));
|
|
||||||
$(e).next('ul').children().each((j, ele) => {
|
|
||||||
$(ele).after(`
|
|
||||||
<div class="objective_${objID} radiobox">
|
|
||||||
<input type="checkbox" name="${objID}" class="objective-input" value="${String.fromCharCode(65 + j)}">
|
|
||||||
${String.fromCharCode(65 + j)}. ${ele.innerHTML}
|
${String.fromCharCode(65 + j)}. ${ele.innerHTML}
|
||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
$(ele).remove();
|
$(ele).remove();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
if (objNum) {
|
if (cnt) {
|
||||||
$('.problem-content .typo').append(document.getElementsByClassName('nav__item--round').length
|
$('.problem-content .typo').append(document.getElementsByClassName('nav__item--round').length
|
||||||
? '<input type="submit" disabled class="button rounded primary" value="登录后提交" />'
|
? '<input type="submit" disabled class="button rounded primary" value="登录后提交" />'
|
||||||
: '<input type="submit" class="button rounded primary" value="提交" />');
|
: '<input type="submit" class="button rounded primary" value="提交" />');
|
||||||
|
|||||||
Reference in new issue
Block a user