✨ feat: 更新问题页面和提交页面,集成Vditor适配器,优化Markdown渲染
This commit is contained in:
@@ -246,74 +246,93 @@
|
||||
}
|
||||
} );
|
||||
}
|
||||
function getFrameSourceValue(frameWindow) {
|
||||
if (frameWindow.editor && typeof frameWindow.editor.getValue === "function") {
|
||||
return frameWindow.editor.getValue();
|
||||
}
|
||||
return frameWindow.$("#source").text();
|
||||
}
|
||||
function setFrameSourceValue(frameWindow, value) {
|
||||
if (frameWindow.editor && typeof frameWindow.editor.setValue === "function") {
|
||||
frameWindow.editor.setValue(value);
|
||||
return;
|
||||
}
|
||||
frameWindow.$("#source").text(value);
|
||||
}
|
||||
function selectOne( num, answer){
|
||||
let editor = $("iframe")[0].contentWindow.$("#source");
|
||||
let old=editor.text();
|
||||
let frameWindow = $("iframe")[0].contentWindow;
|
||||
let old=getFrameSourceValue(frameWindow);
|
||||
let key= num+".*";
|
||||
console.log(key);
|
||||
let rep=old.replace(new RegExp(key),num+" "+answer);
|
||||
editor.text(rep);
|
||||
setFrameSourceValue(frameWindow, rep);
|
||||
}
|
||||
function selectMulti( num, answer){
|
||||
let editor = $("iframe")[0].contentWindow.$("#source");
|
||||
let old=editor.text();
|
||||
let frameWindow = $("iframe")[0].contentWindow;
|
||||
let old=getFrameSourceValue(frameWindow);
|
||||
let key= num+".*";
|
||||
console.log(key);
|
||||
let rep=old.replace(new RegExp(key),num+" "+answer);
|
||||
editor.text(rep);
|
||||
setFrameSourceValue(frameWindow, rep);
|
||||
}
|
||||
function renderProblemMarkdown() {
|
||||
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
|
||||
return HustOJVditor.renderMarkdownBlocks('.md');
|
||||
<?php } ?>
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
function initializeProblemChoices() {
|
||||
$('span[class=auto_select]').each(function(){
|
||||
let i=1;
|
||||
let start=0;
|
||||
let raw=$(this).html();
|
||||
let options=['A','B','C','D'];
|
||||
while(start>=0){
|
||||
start=raw.indexOf(i+".",start);
|
||||
if(start<0) break;
|
||||
let end=start;
|
||||
let type="radio"
|
||||
for(let j=0;j<4;j++){
|
||||
let option=options[j];
|
||||
end=raw.indexOf(option+".",start);
|
||||
if(j==0&&raw.substring(start,end).indexOf("多选")>0) type="checkbox";
|
||||
if (end<0) break;
|
||||
let disp="<input type=\""+type+"\" name=\""+i+"\" value=\""+option+"\" />"+option+".";
|
||||
raw= raw.substring(0,end-1)+disp+raw.substring(end+2);
|
||||
start+=disp.length;
|
||||
}
|
||||
start=end+1;
|
||||
i++;
|
||||
}
|
||||
$(this).html(raw);
|
||||
});
|
||||
$('input[type="radio"]').click(function(){
|
||||
if ($(this).is(':checked'))
|
||||
{
|
||||
selectOne($(this).attr("name"),$(this).val());
|
||||
}
|
||||
});
|
||||
$('input[type="checkbox"]').click(function(){
|
||||
let num=$(this).attr("name");
|
||||
let answer="";
|
||||
$("input[type=checkbox][name="+num+"]").each(function(){
|
||||
if ($(this).is(':checked'))
|
||||
answer+=$(this).val();
|
||||
});
|
||||
selectMulti(num,answer);
|
||||
});
|
||||
<?php if ($row['spj']>1 || isset($_GET['sid']) || (isset($OJ_AUTO_SHOW_OFF)&&$OJ_AUTO_SHOW_OFF)){ ?>
|
||||
transform();
|
||||
<?php }?>
|
||||
}
|
||||
window.renderProblemMarkdown = renderProblemMarkdown;
|
||||
$( document ).ready( function () {
|
||||
$( "#creator" ).load( "problem-ajax.php?pid=<?php echo $id?>" );
|
||||
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
|
||||
$(".md").each(function(){
|
||||
$(this).html(marked.parse($(this).html()));
|
||||
});
|
||||
<?php } ?>
|
||||
//单纯文本1. A. B. C. D. 自动变控件
|
||||
$('span[class=auto_select]').each(function(){
|
||||
let i=1;
|
||||
let start=0;
|
||||
let raw=$(this).html();
|
||||
let options=['A','B','C','D'];
|
||||
while(start>=0){
|
||||
start=raw.indexOf(i+".",start);
|
||||
if(start<0) break;
|
||||
let end=start;
|
||||
let type="radio"
|
||||
for(let j=0;j<4;j++){
|
||||
let option=options[j];
|
||||
end=raw.indexOf(option+".",start);
|
||||
if(j==0&&raw.substring(start,end).indexOf("多选")>0) type="checkbox";
|
||||
if (end<0) break;
|
||||
let disp="<input type=\""+type+"\" name=\""+i+"\" value=\""+option+"\" />"+option+".";
|
||||
//console.log(disp);
|
||||
raw= raw.substring(0,end-1)+disp+raw.substring(end+2);
|
||||
start+=disp.length;
|
||||
}
|
||||
start=end+1;
|
||||
i++;
|
||||
}
|
||||
//console.log(raw);
|
||||
$(this).html(raw);
|
||||
});
|
||||
$('input[type="radio"]').click(function(){
|
||||
if ($(this).is(':checked'))
|
||||
{
|
||||
selectOne($(this).attr("name"),$(this).val());
|
||||
}
|
||||
});
|
||||
$('input[type="checkbox"]').click(function(){
|
||||
let num=$(this).attr("name");
|
||||
let answer="";
|
||||
$("input[type=checkbox][name="+num+"]").each(function(){
|
||||
if ($(this).is(':checked'))
|
||||
answer+=$(this).val();
|
||||
});
|
||||
selectMulti(num,answer);
|
||||
});
|
||||
<?php if ($row['spj']>1 || isset($_GET['sid']) || (isset($OJ_AUTO_SHOW_OFF)&&$OJ_AUTO_SHOW_OFF)){ ?>
|
||||
transform();
|
||||
<?php }?>
|
||||
renderProblemMarkdown().catch(function (error) {
|
||||
console.error('Failed to render problem markdown.', error);
|
||||
}).then(function () {
|
||||
initializeProblemChoices();
|
||||
});
|
||||
|
||||
|
||||
} );
|
||||
|
||||
Reference in New Issue
Block a user