打开/关闭菜单
Toggle preferences menu
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Gadget-tikuRenderModule.js:修订间差异

MediaWiki界面页面
无编辑摘要
(导入1个版本)
 
(未显示同一用户的192个中间版本)
第1行: 第1行:
function getdata(){
//设置
    var data = $('.data')
var prefixDic = {
    var dataLength = data.length
    formId:'timuForm-',
     var subjectCon = $('.subjectContainer')
    radioName:'radio-',
     console.log(data)
    radioId:'radio-input-',
     $('<button class="button" id="typeAReset">重置答题状态</button>').prependTo($('#subjectContainer-A'))
    checkBoxName:'checkbox-',
     $('<button class="button" id="typeBReset">重置答题状态</button>').prependTo($('#subjectContainer-B'))
    checkBoxId:'checkbox-input-',
     $('<button class="button" id="typeCReset">重置答题状态</button>').prependTo($('#subjectContainer-C'))
    selectId:'select-',
     $('<button class="button" id="typeXReset">重置答题状态</button>').prependTo($('#subjectContainer-X'))
    selectName:'select-',
     $('#typeAReset').bind("click",function (){
    textInputName:'text-',
         reset(dataLength,"A")
    textInputId:'text-'
}
 
 
//主函数
function renderTimuFromSessionStorage(){
var timuList = gDomTimuList()
// console.log(timuList)
var order = timuList.order
var timu = timuList.timu
var errors = timuList.errors
var repeatSource = timuList.repeatSource
for(var i=0;i<order.length;i++){
if(order[i].isError){
var errorWidget = new OO.ui.MessageWidget( {
type: 'error',
showClose:true,
label: 'id='+i+'的题目加载错误,错误信息:'+errors[i].info.name+':'+errors[i].info.message+'\n'+'对应文本:'+errors[i].dataText
} )
render(i,'A',$('<di></div>').append(errorWidget.$element,'<hr>'))
}else{
var dataJSON = timu[i].dataJSON
            var o = newTimu(i,dataJSON,{})[dataJSON.type]()
            render(i,dataJSON.type,o)
            var needCheck = $('#noRepeatCheck').length<=0
            if(repeatSource[i]!==undefined&&needCheck){
            var warningWidget = new OO.ui.MessageWidget( {
type: 'warning',
label: '本题与本页面id为'+repeatSource[i]+'的题目source参数重复,本参数重复可能引起错误,请检查并修改!'
} )
render(i,'A',warningWidget.$element)
            }
}
}
}
 
 
//题目渲染函数
//生成info
function infoInline(info){
    return $('<div class="info">'+info+'</div>')
}
//单行题干的处理titleInline(type, source, title)
//生成titleGroup
function titlesGroup(titlesList){
     var group = $('<div class="titlesGroup"></div>')
     for(var i=0;i<titlesList.length;i++){
        group.append(titlesList[i])
    }
    return group
}
//生成titleInline
function titleInline(id, type,originalSource, sourceSuffix,title, classes){
    classes = classes===undefined?'':classes
     return $('<div id="title-'+id+'" class="'+classes+'"></div>').append(
            titleInlineType(type),
            titleInlineSource(originalSource,sourceSuffix,type),
            titleInlineTitle(title)
        )
}
function titleInlineType(type){
    var typeChinese = {
        A:'A',
        A2:'A2',
        A3:'A3',
        B:'B',
        C:'C',
        X:'X',
        TK:'填空',
        PD:'判断',
        MJ:'名解'
    }
    return $('<p class="type">'+typeChinese[type]+'</p>')
}
//从有中文的source中提取最后一个连续数字作为真实的source
function getRealSource(source){
    // console.log(source)
var getContinueNumber = source.match(/[0-9]+/g)
var splitContinueNumber = source.split(/[0-9]+/g)
    var realSource = getContinueNumber[getContinueNumber.length-1]*1
    var prefix = ''
    for(var i=0;i<getContinueNumber.length;i++){
    prefix += splitContinueNumber[i]
    }
    return {prefix:prefix,source:realSource}
}
//返回source的obj
function titleInlineSource(originalSource, suffix , type){
    var realSource = type==='A3'?{prefix:'', source:originalSource}: getRealSource(originalSource)
   
    var prefix = realSource.prefix
    var source = realSource.source
    var suffix = suffix === undefined ? '':'-'+suffix
 
    return $('<p class="source">'+prefix+source+suffix+'</p>')
}
//返回sourceRange的obj
function rangeInline(originalSource, sourceRange, type){
    var source = getRealSource(originalSource).source
    var end = source*1+sourceRange*1 -1
 
    var rangeText = '第 '+source +' 到 ' + end + ' 题'
    var suffix = type==='B'?'共用备选答案':'共用题干'
 
    return $('<div class="sourceRange">'+rangeText + suffix +'</div>')
}
//返回title 的 obj
function titleInlineTitle(title){
     return $('<p class="title">'+title+'</p>')
}
//生成buttonGroup
function buttonGroup(showSubmitBtn, showEditBtn, id, type, correctAnswer, hoverTarget){
    // console.log(showEditBtn)
    var buttonGroupObj = $('<div class="buttonGroup"></div>')
    if(showSubmitBtn){buttonGroupObj.append(
        new OO.ui.ButtonWidget( {
            id:'showThisAnswer-'+id,
            label: '提交',
            flags: [
                'progressive'
            ]
        } ).$element.bind("click",function (){
            showThisAnswer(id,type,correctAnswer)
        })
    )}
     if(showEditBtn){
        buttonGroupObj.append(
            // $('<a class="editThisBtn" style="" href="javascript:void(0)"><span class="" id="editThis-' + id + '">题目有误?点击编辑本题</span></a>'),
            new OO.ui.ButtonWidget( {
                id:'editThis-' + id,
                classes:['editThisBtn'],
                framed: false,
                flags: [
                    'progressive'
                ],
                icon: 'edit',
                label: '题目有误?点击编辑本题'
            } ).$element.bind("click",function (){
                editThis(id)
            })
        )
        hoverTarget.hover(function () {
            buttonGroupObj.children('.editThisBtn').fadeIn(10)
        },function (){
            buttonGroupObj.children('.editThisBtn').fadeOut(70)
        })
    }
    return buttonGroupObj
}
//resultGroup: answer和explain的显示框
function resultGroup(id, items, answerInline,explainInline){
     var group = $('<div id="resultGroup-'+id+'" class="resultGroup"></div>')
    for(var i=0;i<items.length;i++){
        group.append(items[i])
    }
    return group
}
//生成answerInline
function answerInline(answer){
    return $('<div class="answerInline"><label>正确答案:</label>'+answer+'</div>')
}
//生成explainInline
function explainInline(explain){
     return $('<div class="explainInline"><label>解析:</label>'+explain+'</div>')
}
 
//生成subject 的form, 顺序items顺序添加 (title, options, buttonGroup)
function subjectFrom(id, type, items){
    var form =  $('<form id="'+prefixDic.formId+id+'" class="subjectForm"></form>')
    //绑定变化事件
    form.change(function(){
    // 如果开启了暂存,则暂存
         if(!gWebPageTimuSettings().noTemp){
            formChangeListener(id, type)
        }
     })
     })
     $('#typeBReset').bind("click",function (){
     for(var i=0;i<items.length;i++){
         reset(dataLength,"B")
         form.append(items[i])
     })
     }
     $('#typeCReset').bind("click",function (){
     return form
        reset(dataLength,"C")
}
    })
function subjectDIV(id,type,items){
     $('#typeXReset').bind("click",function (){
     var div=  $('<div id="'+prefixDic.formId+id+'" class="subjectForm"></div>')
        reset(dataLength,"X")
     for(var i=0;i<items.length;i++){
    })
         div.append(items[i])
     for(var i=0;i<dataLength;i++){
    }
         var singleData = $(data[i]).text()
    return div
        console.log(singleData)
}
        var jsonData = $.parseJSON(singleData)
 
        console.log(jsonData)
//生成填空输入框
        console.log(jsonData.type)
function fillBlank(id, title, pos, classes){
        if(jsonData.type=='A'){
    // console.log(pos)
            typeAModule(i)
    var posReg = new RegExp(pos,'g')
            typeAChoice(jsonData,i)
    var blankLen = title.match(posReg).length
         }else if(jsonData.type=='B'){
    var split = title.split(posReg)
             typeBModule(i)
    // console.log(blankLen)
            typeBChoice(jsonData,i)
    var newTitle = ''
         }else if(jsonData.type=='C'){
    for(var i=0;i<(blankLen+split.length);i++){
            typeCModule(i)
         if(i%2===0){
            typeCChoice(jsonData,i)
             newTitle +=  '<p class="title">'+split[Math.floor(i/2)]+'</div>'
        }else if(jsonData.type=='X'){
         }else{
            typeXModule(i)
            newTitle +=  new OO.ui.TextInputWidget( {
             typeXChoice(jsonData,i)
                name:prefixDic.textInputName+id+'-'+Math.floor(i/2),
                id:prefixDic.textInputId+id+'-'+Math.floor(i/2),
                classes:classes
             } ).$element.prop('outerHTML')
         }
         }
       
    }
    return newTitle
}
//生成B、C型题的选择框
function dropDownInputWidget(id, availabelOptions){
    var options = []
    var select = $('<select class="dorpdown" id="'+prefixDic.selectId+id+'" name="'+prefixDic.selectName+id+'"></select>')
    for(var i=0;i<availabelOptions.length;i++){
        select.append('<option class="dropdown-option" value="'+availabelOptions[i]+'">'+availabelOptions[i]+'</option>')
     }
     }
    return select
}
//生成options(options 是 Map对象)
function optionsGroup(type,id,options){
    var flexClass = (type==='B')||(type==='C') ? 'optionsGroup-flex':''
    var inputType = type==='X' ? 'checkbox':'radio'
    var optionGroupObj = $('<div class="optionsGroup '+flexClass+'"></div>')
    options.forEach(function(value, key, map){
        optionGroupObj.append(optionInline(id, key, value, !((type==='B')||(type==='C')), inputType))
    })
    return optionGroupObj
}
//生成optionInline
function optionInline(id, option, content,input,inputType){
    var idPrefix = inputType === 'checkbox' ? prefixDic.checkBoxId:prefixDic.radioId
    var namePrefix = inputType === 'checkbox' ? prefixDic.checkBoxName:prefixDic.radioName // 这个和外部的div的id一样就共用了


    var input = input ? $('<input id="'+ idPrefix + id+'-'+option+'" name="'+ namePrefix + id + '" type="'+inputType+'" value="' + option + '" />'):''
    var optionLabel = $('<label for="'+ idPrefix + id+'-'+option+'">'+option+'. </label>')
    var contentLabel = $('<label for="'+ idPrefix + id+'-'+option+'">'+content+'</label>')
    return $('<div id="'+ namePrefix +id+'-'+option+'" class="optionInline"></div>').append(input,optionLabel,contentLabel)
}
}
function removeBackground(obj){
//清理json中的choice(清除空项并排序),接收Obj,
    obj.addClass('no-background')
function cleanAndMakeSameLenOptions(options){
//清除空项
var options = filterEmptyEntries(options)
//让所有option长度一样
var maxOptionLen = getStrLength(Object.values(options).sort(function(a,b){return getStrLength(b) - getStrLength(a)})[0])
for(var i in options){
var minus = maxOptionLen - getStrLength(options[i])
for(var n=0;n<minus;n++){
options[i] += '&ensp;'
}
}
// console.log(options)
    return sortDicByKey(options) //返回一个 Map 对象
}
}
function showChoiceAnswer(id,type){
function newTimu(id,json, settings){
     var subjectCon = $('#subjectContainer-'+type).children('#'+id)
     settings = json.settings===undefined||json.isA3 ? settings:json.settings//检测json是否带有settings或者是否为A3子题目
    var titleCon = subjectCon.children('.subject').children('.titleContainer')
    var ansCon = subjectCon.children('.ansContainer')
    var answers = subjectCon.children('.subject').children('.answers')
    var correctAns= ansCon.children('.correctAnswer')
    console.log(id)
    if(type=="A"){
        var correctAnsText = correctAns.text()


        var choice = $('input[name="singelChoice-'+id+'"]:checked').val();
    parent = settings.parent === undefined ? '' : settings.parent
        console.log(choice)
    showHr = settings.showHr == undefined ? true : settings.showHr
        var showCorrect = answers.children('#'+correctAnsText)
    showSubmitBtn = settings.showSubmitBtn === undefined ? true : settings.showSubmitBtn
         var showChoice = answers.children('#'+choice)
    showEditBtn = settings.showEditBtn === undefined ? true : settings.showEditBtn
         var btn = $('#showSingle-'+id).addClass('noDisplay')
    showBtnGroup = settings.showBtnGroup === undefined? true:settings.showBtnGroup
         ansCon.fadeIn(100)
 
         if(choice==correctAnsText){
    var o = new Object()
             showCorrect.addClass('correct')
    o.type = json.type
    o.pos = json.pos
    o.inputBox = json.inputBox
    o.source = json.source
    o.sourceRange = json.sourceRange
    o.info = json.info
    o.title = json.title
    o.options = json.choices
    // console.log(o.options)
    //将choice 统一为Array的转换为obj
    if(typeOfObj(o.options)==='[object Array]'&&o.options.length===1&&o.type!=='A3'){
    o.options = o.options[0]
    }
    o.options = o.options!==undefined? cleanAndMakeSameLenOptions(o.options):''
    // console.log(o.options)
 
    o.answer = json.answer
    o.explain = json.explain
 
    o.temp = {
        main:$('<div name="timu-'+(id+1)+'" id="'+id+'" class="type'+o.type+' timuContainer"><p class="timuID">'+id+'</p></div>'),
    }
 
    o.parent = parent
    // if(this.type==='A3'){
    //    $(this).children('.subject').children('.editThisButton').fadeIn(1)
    //    }
    o.temp.main.hover(function () {
         $('editThis-' + id).fadeIn(10)
    },function (){
         $('editThis-' + id).fadeOut(70)
    })
 
    o.A = function () {
        //subjectForm
        this.type = json.isA3?'A3':'A'
         var optionsGroupObj = optionsGroup(this.type, id, this.options)
         if(json.isA3){
             var titleInlineObj = titleInline(id, 'A3',this.source,undefined,this.title,'titleInline')
         }else{
         }else{
             showCorrect.addClass('correct')
             var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
            showChoice.addClass('wrong')
         }
         }
         setTimeout(function (){
          
            removeBackground(showChoice)
        var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
            removeBackground(showCorrect)
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
         }, 4000);
        //resultGroupObj
        var answerInlineObj = answerInline(this.answer)
        var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
         var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])


         setTimeout(function (){
         this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )
            showCorrect.removeClass('no-background')
 
            showChoice.removeClass('no-background')
        if(showHr){this.temp.main.append('<hr>')}
            showCorrect.removeClass('correct')
        return this.temp.main
            showChoice.removeClass('wrong')
    }
        }, 5000);
     o.A2 = function () {
     }else if(type=="B"){
         //subjectForm
         console.log(titleCon)
         var optionsGroupObj = optionsGroup(this.type, id, this.options)
         titleCon.children('div').each(function (index,i){
        var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
            console.log(i)
        var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)
            var subTitleID = $(i).attr('id')
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
            var ans = $('#ans-'+subTitleID).text().split(':')[1]
        //resultGroupObj
            var choice = $('#'+id+'-'+index).find("option:selected").text();
        var answerInlineObj = answerInline(this.answer)
            console.log(choice)
        var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
            if(choice==ans){
        var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
                $('#'+id+'-'+index).addClass('correct')
 
            }else {
        this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )
                $('#'+id+'-'+index).addClass('wrong')
                $('<p class="answerTip">正确答案:'+ans+'</p>').appendTo($('#'+id+'-'+index))


            }
        if(showHr){this.temp.main.append('<hr>')}
            setTimeout(function (){
         return this.temp.main
                $('#'+id+'-'+index).removeClass('correct')
     }
                $('#'+id+'-'+index).removeClass('wrong')
    o.A3 = function () {
            }, 5000);
        // console.log(settings)
         })
        var realSource = getRealSource(json.source)
     } else if(type=="C"){
        var sourcePrefix = realSource.prefix===''?'':realSource.prefix
        console.log(titleCon)
        //subjectForm
        titleCon.children('div').each(function (index,i){
        var range = rangeInline(this.source, this.sourceRange)
            console.log(i)
        var info = infoInline(this.info)
            var subTitleID = $(i).attr('id')
            var ans = $('#ans-'+subTitleID).text().split(':')[1]
            var choice = $('#'+id+'-'+index).find("option:selected").text();
            console.log(choice)
            if(choice==ans){
                $('#'+id+'-'+index).addClass('correct')
            }else {
                $('#'+id+'-'+index).addClass('wrong')
                $('<p class="answerTip">正确答案:'+ans+'</p>').appendTo($('#'+id+'-'+index))


        var subTitlesList = []
        for(var i=0;i<this.title.length;i++){
            if(this.explain[i]==undefined){
                this.explain[i] = '暂无解析'
             }
             }
             setTimeout(function (){
             var data = {
                 $('#'+id+'-'+index).removeClass('correct')
                 'isA3':true,
                 $('#'+id+'-'+index).removeClass('wrong')
                 "type":"A",
            }, 5000);
                "source":sourcePrefix+realSource.source+'-'+(i+1),
        })
                "title":this.title[i],
    }else if(type=="X"){
                "answer":this.answer[i],
        var correctAnsText = correctAns.text()
                "explain":this.explain[i],
        var choice = ""
                 "choices":this.options.get(i+''),
        $('input[name="singelChoice-'+id+'"]:checked').each(function (){
            choice += $(this).val()
        })
        console.log(choice)
        console.log(correctAnsText)
        var btn = $('#showSingle-'+id).addClass('noDisplay')
        ansCon.fadeIn(100)
        for(var i=0;i<choice.length;i++){
            var showCorrect = answers.children('#'+correctAnsText[i])
            var showChoice = answers.children('#'+choice[i])
            if(correctAnsText.indexOf(choice[i])!=-1){
                 showChoice.addClass('correct')
            }else{
                showChoice.addClass('wrong')
             }
             }
            // console.log(data)
            // console.log(this.options)
            subTitlesList.push(newTimu(id+'-'+i,data,{
                showHr:false,
                showEditBtn:false,
                showSubmitBtn:false,
                showBtnGroup:false
            }).A())
         }
         }
         for(var i=0;i<correctAnsText.length;i++){
       
             var showCorrect = answers.children('#'+correctAnsText[i])
        // console.log(this.answer)
             $('<p class="answerTip">✓</p>').appendTo(showCorrect)
        var buttonGroupObj  = buttonGroup(true, false, id, this.type, this.answer, this.temp.main)
        // console.log(buttonGroupObj)
        var subjectFormObj = subjectDIV(id,this.type, [subTitlesList])
        this.temp.main.append(range,info, subjectFormObj, buttonGroupObj)
 
        this.temp.main.append('<hr>')
        return this.temp.main
    }
    o.B = function () {
        var realSource = getRealSource(json.source)
        var sourcePrefix = realSource.prefix===''?'':realSource.prefix
        //subjectForm
        var range = rangeInline(this.source, this.sourceRange)
        var optionsGroupObj = optionsGroup(this.type, id, this.options)
        var titleInlineList = []
         for(var i=0;i<this.title.length;i++){
             var dropdown = dropDownInputWidget(id+'-'+i, mapKeysList(this.options))
            var titleInlineObj = titleInline(id+'-'+i, this.type, json.source, i, this.title[i],'titleInline')
             titleInlineObj.append(dropdown)
            titleInlineList.push(titleInlineObj)
         }
         }
         answers.children('label').each(function (){
         var titlesGroupObj = titlesGroup(titleInlineList)
             var a = $(this)
        var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)
             setTimeout(function (){
 
                removeBackground(a)
        var subjectForm = subjectFrom(id,this.type, [optionsGroupObj, titlesGroupObj])
            }, 4000);
 
            setTimeout(function (){
        //resultGroupObj
                a.removeClass('no-background')
        var resultGroupList = []
                 a.removeClass('correct')
        for(var i=0;i<this.answer.length;i++){
                a.removeClass('wrong')
             var answerInlineObj = answerInline(this.answer[i])
            }, 5000);
             var explainInlineObj = this.explain[i] === undefined || this.explain[i] === '' ? '暂无解析' : explainInline(this.explain[i])
         })
            resultGroupList.push(
                    '<b>'+sourcePrefix+realSource.source+'-'+i+'</b>',
                    $('<div style="margin-left:10px"></div>').append(answerInlineObj),
                    $('<div style="margin-left:10px"></div>').append(explainInlineObj)
                 )
        }
        var resultGroupObj = resultGroup(id, resultGroupList)
 
        this.temp.main.append(range ,subjectForm,resultGroupObj, buttonGroupObj)
 
        if(showHr){this.temp.main.append('<hr>')}
         return this.temp.main
     }
     }
}
    o.C = function () {
function reset(length,type){
        var realSource = getRealSource(json.source)
    if(type=="A"){
        var sourcePrefix = realSource.prefix===''?'':realSource.prefix
         for(var id=0;id<length;id++){
        //subjectForm
             var choice = $('input:radio').removeAttr('checked')
        var range = rangeInline(this.source, this.sourceRange)
             var subjectCon = $('#subjectContainer-'+type).children('#'+id)
        var optionsGroupObj = optionsGroup(this.type, id, this.options)
            var ansCon = subjectCon.children('.ansContainer')
        var titleInlineList = []
             $('#showSingle-'+id).removeClass('noDisplay')
         for(var i=0;i<this.title.length;i++){
             ansCon.fadeOut(100)
             var dropdown = dropDownInputWidget(id+'-'+i, mapKeysList(this.options))
             var titleInlineObj = titleInline(id+'-'+i, this.type, json.source, i, this.title[i],'titleInline')
             titleInlineObj.append(dropdown)
             titleInlineList.push(titleInlineObj)
         }
         }
    }else if(type=="B"){
        var titlesGroupObj = titlesGroup(titleInlineList)
        $('.answerTip').css('display','none')
         var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)
         var typeBselected=$('#subjectContainer-B').children('.typeB').children('.subject').children('.titleContainer').children('div').children('select')
 
        typeBselected.each(function () {
         var subjectForm = subjectFrom(id,this.type, [titlesGroupObj, optionsGroupObj])
            $(this).children("option").eq(0).prop("selected",true)
 
        })
         //resultGroupObj
    }else if(type=="C"){
        var resultGroupList = []
        $('.answerTip').css('display','none')
         for(var i=0;i<this.answer.length;i++){
         var typeBselected=$('#subjectContainer-C').children('.typeC').children('.subject').children('.titleContainer').children('div').children('select')
             var answerInlineObj = answerInline(this.answer[i])
        typeBselected.each(function () {
            var explainInlineObj = this.explain[i] === undefined || this.explain[i] === '' ? '暂无解析' : explainInline(this.explain[i])
            $(this).children("option").eq(0).prop("selected",true)
             resultGroupList.push(
         })
                    '<b>'+sourcePrefix+realSource.source+'-'+i+'</b>',
    }else if(type=="X") {
                    $('<div style="margin-left:10px"></div>').append(answerInlineObj),
        $('.answerTip').css('display', 'none')
                    $('<div style="margin-left:10px"></div>').append(explainInlineObj)
         for (var id = 0; id < length; id++) {
                )
             var choice = $('input:checkbox').each(function () {
                $(this).prop('checked', false)
             })
            var subjectCon = $('#subjectContainer-' + type).children('#' + id)
            var ansCon = subjectCon.children('.ansContainer')
            $('#showSingle-' + id).removeClass('noDisplay')
            ansCon.fadeOut(100)
         }
         }
        var resultGroupObj = resultGroup(id, resultGroupList)
        this.temp.main.append(range ,subjectForm,resultGroupObj, buttonGroupObj)
        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
     }
     }
    o.X = function () {
        //subjectForm
        var optionsGroupObj = optionsGroup(this.type, id, this.options)
        var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
        var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
        //resultGroupObj
        var answerInlineObj = answerInline(this.answer)
        var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
        var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
        this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )


}
        if(showHr){this.temp.main.append('<hr>')}
//A型题
        return this.temp.main
function typeAChoice(json,id){
    }
    var subjectCon = $('#subjectContainer-A').children('#'+id)
    o.PD = function () {
    var titleCon = subjectCon.children('.subject').children('.titleContainer')
    var dic = {
    var ansCon = subjectCon.children('.ansContainer')
      right: ['', '正确', 't', '', '', '1', 'true'],
    var source = titleCon.children('.source').text(json.source)
      wrong: ['错', '错误', '×', 'x', 'f', 'false', 'wrong', '0']
    var title = titleCon.children('.title').text(json.title)
    }
    var correctAns = ansCon.children('.correctAnswer').text(json.answer)
        var ans = ''
    var exp = ansCon.children('.explain').text(json.explain)
        var ansOption = ''
    var answers = subjectCon.children('.subject').children('.answers')
        if(isInArray(dic.right, json.answer.toLowerCase())){
    var char = ['A: ','B: ','C: ','D: ','E: ',]
            ans = '正确'
    var i = 0
            ansOption = 'A'
    for(var key in json.choices){
         }else if(isInArray(dic.wrong, json.answer.toLowerCase())){
         if(json.choices[key].length>0){
             ans = '错误'
             var label = '<label id="'+key+'"><input name="singelChoice-'+id+'" type="radio" value="'+key+'" />'+char[i]+json.choices[key]+'</label>'
            ansOption = 'B'
            answers.append(label)
        }else {
        ans = '系统错误:该判断题答案不符合标准格式'
         }
         }
         i+=1
 
         //subjectForm
        var option = new Map()
        option.set('A', '正确')
        option.set('B', '错误')
        var optionsGroupObj = optionsGroup(this.type, id, option)
        var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
        var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, 'A', ansOption, this.temp.main):''
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj,optionsGroupObj])
        //resultGroupObj
        var answerInlineObj = answerInline(ans)
        var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
        var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
 
        this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )
 
        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
     }
     }
}
    o.TK = function () {
function typeAModule(id){
        var tkTitle = fillBlank(id, this.title, this.pos, ['text-input-tk'])
    var main = $('<div id="'+id+'" class="typeA"></div>')
        var titleInlineObj = titleInline(id, this.type,this.source,undefined,tkTitle, 'titleInline-no-flex')
    var subject = $('<div class="subject">' +
         titleInlineObj.children('.text-input-tk').each(function(i,v){
        '<div class="titleContainer"><p class="source"></p><p class="title"></p></div>' +
            // console.log(i,v)
        '<div class="answers"></div></div>').appendTo(main)
            $(this).children('input').css(
    var showButton = $('<button class="button" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
                'display','inline'
    var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
            )
        '           <p style="display:inline;"><b>正确答案:</b></p>\n' +
            $(this).children('input').css(
        '            <p class="correctAnswer"></p><br><p><b>解析: </b></p>\n' +
                'width','200px'
         '            <p class="explain"></p></div><hr>').appendTo(main)
             )
    main.appendTo($('#subjectContainer-A'))
    $("#showSingle-"+id).bind("click",function (){
        showChoiceAnswer(id,'A')
    })
}
//B型题
function typeBChoice(json,id){
    var subjectCon = $('#subjectContainer-B').children('#'+id)
    var subject = subjectCon.children('.subject')
    var titleCon = subjectCon.children('.subject').children('.titleContainer')
    var ansCon = subjectCon.children('.ansContainer')
    var source = json.source
    var range = json.sourceRange
    var end = source *1 + range*1 -1
    var title = json.title
    var correctAns = json.answer
    var exp = ansCon.children('.explain').text(json.explain)
    var answers = subjectCon.children('.subject').children('.answers')
    var char = ['A: ','B: ','C: ','D: ','E: ',]
    var sourceRange = subject.children('.sourceRange').text('第 '+source+' 到 '+end+' 题')
    for(var n=0;n<title.length;n++){
        var text = title[n].replace("()",function(a){
             return "(<select class=\"button-small button-rounded button\"> " +
                "<option value ='A'>A</option>" +
                "<option value ='B'>B</option>" +
                "<option value ='C'>C</option>" +
                "<option value ='D'>D</option>" +
                "<option value ='E'>E</option>" +
                "</select>)"
         })
         })
         var div = '<div id="'+id+'-'+n+'"><p class="source">'+'T'+(source*1+n)+'</p>'+text+'</div>'
         var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
         titleCon.append(div)
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj])
 
        this.temp.main.append(subjectForm, buttonGroupObj)
 
        if(showHr){this.temp.main.append('<hr>')}
         return this.temp.main
     }
     }
     var i = 0
     o.MJ = function () {
    for(var key in json.choices){
        var mjTitle = ''
         if(json.choices[key].length>0){
         if(this.inputBox===0){
             var label = '<li id="'+key+'">'+char[i]+json.choices[key]+'</li>'
             mjTitle = json.title + '<span class="blur" tabindex="0" style="display:inline;outline=0;" onclick="">' + json.answer +'</span>'
             answers.append(label)
        }else{
            console.log(label)
             mjTitle = fillBlank(id, this.title+':()', '()', ['text-input-mj'])
         }
         }
         i+=1
         var titleInlineObj = titleInline(id, this.type,this.source,undefined,mjTitle, 'titleInline-no-flex')
    }
        titleInlineObj.children('.text-input-mj').each(function(i,v){
    text = ''
            // console.log(i,v)
    for(var n=0;n<correctAns.length;n++){
            $(this).children('input').css(
        text += '<p id="ans-'+id +'-'+n+'">'+(id*1+n)+''+correctAns[n]+'</p>'
                'display','inline'
         ansCon.children('.correctAnswer').html(text)
            )
            $(this).children('input').css(
                'width','auto'
            )
        })
         var buttonGroupObj = this.inputBox!==0 ? buttonGroup(showSubmitBtn, showEditBtn, id, 'TK', [this.answer], this.temp.main):''
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj])
 
        this.temp.main.append(subjectForm, buttonGroupObj)
        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
     }
     }
    return o
}
}
function typeBModule(id){
 
    var main = $('<div id="'+id+'" class="typeB"></div>')
// // 获取select的选项
    var subject = $('<div class="subject">' +
function getSelectedAnswer(id){
        '<div class="sourceRange"></div>'+
     var data = formToJSON('#'+prefixDic.formId + id,true)
        '<div class="answers"></div>'+
    console.log(data)
        '<div class="titleContainer"></div></div>'
     return data
        ).appendTo(main)
    var showButton = $('<button class="button-tiny button-pill button button-caution" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
     var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
        '            <p style="display:inline;"><b>正确答案:</b></p>\n' +
        '            <p class="correctAnswer"></p><br><p><b>解析: </b></p>\n' +
        '            <p class="explain"></p></div><hr>').appendTo(main)
    main.appendTo($('#subjectContainer-B'))
    $("#showSingle-"+id).bind("click",function (){
        showChoiceAnswer(id,'B')
     })
}
}
//C型题
// // 获取checkbox值
function typeCModule(id){
function getCheckBoxValue(name) {
     var main = $('<div id="'+id+'" class="typeC"></div>')
     var ids = $('input:checkbox[name="'+name+'"]:checked');
     var subject = $('<div class="subject">' +
     var data = [];
        '<div class="sourceRange"></div>'+
    for (var i = 0; i < ids.length; i ++) {
        '<div class="titleContainer"></div>'+
        data.push(ids[i].value)
        '<div class="answers"></div></div>'
    }
    ).appendTo(main)
    return data
    var showButton = $('<button class="button-tiny button-pill button button-caution" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
    var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
        '            <p style="display:inline;"><b>正确答案:</b></p>\n' +
        '            <p class="correctAnswer"></p><br><p><b>解析: </b></p>\n' +
        '            <p class="explain"></p></div><hr>').appendTo(main)
    main.appendTo($('#subjectContainer-C'))
    $("#showSingle-"+id).bind("click",function (){
        showChoiceAnswer(id,'C')
    })
}
}
function typeCChoice(json,id){
function showThisAnswer(id,type,correctAnswer){
     var subjectCon = $('#subjectContainer-C').children('#'+id)
var isRight = false
     var subject = subjectCon.children('.subject')
     var resultGroup = $('#resultGroup-'+id)
     var titleCon = subjectCon.children('.subject').children('.titleContainer')
     resultGroup.fadeIn(100)
     var ansCon = subjectCon.children('.ansContainer')
     $('#showThisAnswer-'+id).fadeOut(1)
    var source = json.source
 
    var range = json.sourceRange
     if(type==="A" || type ==='A2'){
    var end = source *1 + range*1 -1
        var optionGroupName = prefixDic.radioName+id
    var title = json.title
        var optionInlinePrefixID = prefixDic.radioName+id
    var correctAns = json.answer
        var usersChoice = getSelectedAnswer(id)[optionGroupName]
    var exp = ansCon.children('.explain').text(json.explain)
console.log(usersChoice)
    var answers = subjectCon.children('.subject').children('.answers')
        var correctDivObj = $('#'+optionInlinePrefixID + '-' + correctAnswer)
     var char = ['A: ','B: ','C: ','D: ','E: ',]
        var usersChoiceDivObj = $('#'+optionInlinePrefixID + '-' + usersChoice)
     var sourceRange = subject.children('.sourceRange').text(''+source+' 到 '+end+' 题')
       
    for(var n=0;n<title.length;n++){
        if(usersChoice===correctAnswer){
        var text = title[n].replace("()",function(a){
            correctDivObj.addClass('correct')
             return "(<select class=\"button-small button-rounded button\"> " +
            isRight = true
                "<option value ='A'>A</option>" +
        }else{
                 "<option value ='B'>B</option>" +
            correctDivObj.addClass('correct')
                 "<option value ='C'>C</option>" +
            usersChoiceDivObj.addClass('wrong')
                 "<option value ='D'>D</option>" +
        }
                "<option value ='E'>E</option>" +
 
                "</select>)"
     }else if(type==='A3'){
         })
        for(var i=0;i<correctAnswer.length;i++){
        var div = '<div id="'+id+'-'+n+'"><p class="source">'+'T'+(source*1+n)+'</p>'+text+'</div>'
            //以下与A型题时一样的代码,知识用subID替换ID变量
         titleCon.append(div)
            showThisAnswer(id+'-'+i,'A',correctAnswer[i])
    }
        }
    var i = 0
     } else if(type==='B'){
    for(var key in json.choices){
        var dropDownInputPrefix = 'select-'+id +'-'
        if(json.choices[key].length>0){
        var usersChoice = getSelectedAnswer(id)
            var label = '<li id="'+key+'">'+char[i]+json.choices[key]+'</li>'
        // console.log(usersChoice)
 
        for(var i in usersChoice){
            var dorpdownID = i.replace(dropDownInputPrefix,'')//获取子ID
             var subTimuID = id+'-'+dorpdownID
            var thisTimuUsersChoice = usersChoice[i]
            var thisTimuCorrectAnswer = correctAnswer[dorpdownID]
            var subTimuDiv = $('#title-'+subTimuID)
 
            if(thisTimuUsersChoice===thisTimuCorrectAnswer){
                 subTimuDiv.addClass('correct')
            }else{
                 subTimuDiv.addClass('wrong')
                 subTimuDiv.append('<label class="answerTip">正确答案:'+thisTimuCorrectAnswer+'</label>')
            }
        }
    } else if(type=="C"){
        var dropDownInputPrefix = 'select-'+id +'-'
        var usersChoice = getSelectedAnswer(id)
        // console.log(usersChoice)
 
         for(var i in usersChoice){
            var dorpdownID = i.replace(dropDownInputPrefix,'')//获取子ID
            var subTimuID = id+'-'+dorpdownID
            var thisTimuUsersChoice = usersChoice[i]
            var thisTimuCorrectAnswer = correctAnswer[dorpdownID]
            var subTimuDiv = $('#title-'+subTimuID)
 
            if(thisTimuUsersChoice===thisTimuCorrectAnswer){
                subTimuDiv.addClass('correct')
            }else{
                subTimuDiv.addClass('wrong')
                subTimuDiv.append('<label class="answerTip">正确答案:'+thisTimuCorrectAnswer+'</label>')
            }
        }
    }else if(type=="X"){
        var optionGroupName = 'checkbox-'+id
        var optionInlinePrefixID = 'checkbox-'+id
         var usersChoice = getCheckBoxValue(optionGroupName).sort()
        correctAnswer = correctAnswer.match(/[A-Z]/g).sort()
        var lenCorrect = correctAnswer.length
        var lenUser = usersChoice.length
        // console.log(correctAnswer)
        for(var i=0;i<lenUser;i++){
            // console.log(isInArray(correctAnswer, usersChoice[i]),usersChoice[i] ,correctAnswer)
            if(!isInArray(correctAnswer, usersChoice[i])){
                $('#'+optionInlinePrefixID + '-' + usersChoice[i]).addClass('wrong')
            }
        }


             answers.append(label)
        for(var i=0;i<lenCorrect;i++){
             console.log(label)
             if(!isInArray(usersChoice,correctAnswer[i])){
                $('#'+optionInlinePrefixID + '-' + correctAnswer[i]).addClass('notChoiced')
            }else {
                $('#'+optionInlinePrefixID + '-' + correctAnswer[i]).addClass('correct')
            }
        }
 
       
    }else if(type=="TK"){
        var textInputPrefix = prefixDic.textInputId+id+'-'
        var usersChoice = getSelectedAnswer(id)
        for(var i in usersChoice){
            var inputID = i.replace(textInputPrefix,'')
             // console.log('#'+i)
            var corrcetAnswerText = correctAnswer[inputID]===undefined?'暂无答案':correctAnswer[inputID]
            if(usersChoice[i]===correctAnswer[inputID]){
                $('#'+i).html('<label class="answerTip correct">'+corrcetAnswerText+'</label>')
            }else{
                $('#'+i).after('<label class="answerTip wrong">'+corrcetAnswerText+'</label>')
            }
         }
         }
        i+=1
     }
     }
     text = ''
     if(isRight){
    for(var n=0;n<correctAns.length;n++){
    locateTo(id+1)
        text += '<p id="ans-'+id +'-'+n+'">'+(id*1+n)+':'+correctAns[n]+'</p>'
        ansCon.children('.correctAnswer').html(text)
     }
     }
}
}
//X型题
function removeBackground(obj){
function typeXChoice(json,id){
     obj.addClass('no-background')
    var subjectCon = $('#subjectContainer-X').children('#'+id)
    var titleCon = subjectCon.children('.subject').children('.titleContainer')
    var ansCon = subjectCon.children('.ansContainer')
    var source = titleCon.children('.source').text(json.source)
    var title = titleCon.children('.title').text(json.title)
    var correctAns = ansCon.children('.correctAnswer').text(json.answer)
    var exp = ansCon.children('.explain').text(json.explain)
    var answers = subjectCon.children('.subject').children('.answers')
    var char = ['A: ','B: ','C: ','D: ','E: ',]
    var i = 0
    for(var key in json.choices){
        if(json.choices[key].length>0){
            var label = '<label id="'+key+'"><input name="singelChoice-'+id+'" type="checkbox" value="'+key+'" />'+char[i]+json.choices[key]+'</label>'
            answers.append(label)
        }
        i+=1
    }
}
function typeXModule(id){
     var main = $('<div id="'+id+'" class="typeX"></div>')
    var subject = $('<div class="subject">' +
        '<div class="titleContainer"><p class="source"></p><p class="title"></p></div>' +
        '<div class="answers"></div></div>').appendTo(main)
    var showButton = $('<button class="button" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
    var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
        '            <p style="display:inline;"><b>正确答案:</b></p>\n' +
        '            <p class="correctAnswer"></p><br><p><b>解析: </b></p>\n' +
        '            <p class="explain"></p></div><hr>').appendTo(main)
    main.appendTo($('#subjectContainer-X'))
    $("#showSingle-"+id).bind("click",function (){
        showChoiceAnswer(id,'X')
    })
}
}
setTimeout(function (){
getdata();
},0);

2023年6月29日 (四) 15:04的最新版本

//设置
var prefixDic = {
    formId:'timuForm-',
    radioName:'radio-',
    radioId:'radio-input-',
    checkBoxName:'checkbox-',
    checkBoxId:'checkbox-input-',
    selectId:'select-',
    selectName:'select-',
    textInputName:'text-',
    textInputId:'text-'
}


//主函数
function renderTimuFromSessionStorage(){
	var timuList = gDomTimuList()
	// console.log(timuList)
	var order = timuList.order
	var timu = timuList.timu
	var errors = timuList.errors
	var repeatSource = timuList.repeatSource
	for(var i=0;i<order.length;i++){
		if(order[i].isError){
			var errorWidget = new OO.ui.MessageWidget( {
				type: 'error',
				showClose:true,
				label: 'id='+i+'的题目加载错误,错误信息:'+errors[i].info.name+':'+errors[i].info.message+'\n'+'对应文本:'+errors[i].dataText
			} )
			render(i,'A',$('<di></div>').append(errorWidget.$element,'<hr>'))
		}else{
			var dataJSON = timu[i].dataJSON
            var o = newTimu(i,dataJSON,{})[dataJSON.type]()
            render(i,dataJSON.type,o)
            var needCheck = $('#noRepeatCheck').length<=0
            if(repeatSource[i]!==undefined&&needCheck){
            	var warningWidget = new OO.ui.MessageWidget( {
					type: 'warning',
					label: '本题与本页面id为'+repeatSource[i]+'的题目source参数重复,本参数重复可能引起错误,请检查并修改!'
				} )
				render(i,'A',warningWidget.$element)
            }
		}
	}
}


//题目渲染函数
//生成info
function infoInline(info){
    return $('<div class="info">'+info+'</div>')
}
//单行题干的处理titleInline(type, source, title)
//生成titleGroup
function titlesGroup(titlesList){
    var group = $('<div class="titlesGroup"></div>')
    for(var i=0;i<titlesList.length;i++){
        group.append(titlesList[i])
    }
    return group
}
//生成titleInline
function titleInline(id, type,originalSource, sourceSuffix,title, classes){
    classes = classes===undefined?'':classes
    return $('<div id="title-'+id+'" class="'+classes+'"></div>').append(
            titleInlineType(type),
            titleInlineSource(originalSource,sourceSuffix,type),
            titleInlineTitle(title)
        )
}
function titleInlineType(type){
    var typeChinese = {
        A:'A',
        A2:'A2',
        A3:'A3',
        B:'B',
        C:'C',
        X:'X',
        TK:'填空',
        PD:'判断',
        MJ:'名解'
    }
    return $('<p class="type">'+typeChinese[type]+'</p>')
}
//从有中文的source中提取最后一个连续数字作为真实的source
function getRealSource(source){
    // console.log(source)
	var getContinueNumber = source.match(/[0-9]+/g)
	var splitContinueNumber = source.split(/[0-9]+/g)
    var realSource = getContinueNumber[getContinueNumber.length-1]*1
    var prefix = ''
    for(var i=0;i<getContinueNumber.length;i++){
    	prefix += splitContinueNumber[i]
    }
    return {prefix:prefix,source:realSource}
}
//返回source的obj
function titleInlineSource(originalSource, suffix , type){
    var realSource = type==='A3'?{prefix:'', source:originalSource}: getRealSource(originalSource)
    
    var prefix = realSource.prefix
    var source = realSource.source
    var suffix = suffix === undefined ? '':'-'+suffix

    return $('<p class="source">'+prefix+source+suffix+'</p>')
}
//返回sourceRange的obj
function rangeInline(originalSource, sourceRange, type){
    var source = getRealSource(originalSource).source
    var end = source*1+sourceRange*1 -1

    var rangeText = '第 '+source +' 到 ' + end + ' 题'
    var suffix = type==='B'?'共用备选答案':'共用题干'

    return $('<div class="sourceRange">'+rangeText + suffix +'</div>')
}
//返回title 的 obj
function titleInlineTitle(title){
    return $('<p class="title">'+title+'</p>')
}
//生成buttonGroup
function buttonGroup(showSubmitBtn, showEditBtn, id, type, correctAnswer, hoverTarget){
    // console.log(showEditBtn)
    var buttonGroupObj = $('<div class="buttonGroup"></div>')
    if(showSubmitBtn){buttonGroupObj.append(
        new OO.ui.ButtonWidget( {
            id:'showThisAnswer-'+id,
            label: '提交',
            flags: [
                'progressive'
            ]
        } ).$element.bind("click",function (){
            showThisAnswer(id,type,correctAnswer)
        })
    )}
    if(showEditBtn){
        buttonGroupObj.append(
            // $('<a class="editThisBtn" style="" href="javascript:void(0)"><span class="" id="editThis-' + id + '">题目有误?点击编辑本题</span></a>'),
            new OO.ui.ButtonWidget( {
                id:'editThis-' + id,
                classes:['editThisBtn'],
                framed: false,
                flags: [
                    'progressive'
                ],
                icon: 'edit',
                label: '题目有误?点击编辑本题'
            } ).$element.bind("click",function (){
                editThis(id)
            })
        )
        hoverTarget.hover(function () {
            buttonGroupObj.children('.editThisBtn').fadeIn(10)
        },function (){
            buttonGroupObj.children('.editThisBtn').fadeOut(70)
        })
    }
    return buttonGroupObj
}
//resultGroup: answer和explain的显示框
function resultGroup(id, items, answerInline,explainInline){
    var group = $('<div id="resultGroup-'+id+'" class="resultGroup"></div>')
    for(var i=0;i<items.length;i++){
        group.append(items[i])
    }
    return group
}
//生成answerInline
function answerInline(answer){
    return $('<div class="answerInline"><label>正确答案:</label>'+answer+'</div>')
}
//生成explainInline
function explainInline(explain){
    return $('<div class="explainInline"><label>解析:</label>'+explain+'</div>')
}

//生成subject 的form, 顺序items顺序添加 (title, options, buttonGroup)
function subjectFrom(id, type, items){
    var form =  $('<form id="'+prefixDic.formId+id+'" class="subjectForm"></form>')
    //绑定变化事件
    form.change(function(){
    	// 如果开启了暂存,则暂存
        if(!gWebPageTimuSettings().noTemp){
            formChangeListener(id, type)
        }
    })
    for(var i=0;i<items.length;i++){
        form.append(items[i])
    }
    return form
}
function subjectDIV(id,type,items){
    var div=  $('<div id="'+prefixDic.formId+id+'" class="subjectForm"></div>')
    for(var i=0;i<items.length;i++){
        div.append(items[i])
    }
    return div
}

//生成填空输入框
function fillBlank(id, title, pos, classes){
    // console.log(pos)
    var posReg = new RegExp(pos,'g')
    var blankLen = title.match(posReg).length
    var split = title.split(posReg)
    // console.log(blankLen)
    var newTitle = ''
    for(var i=0;i<(blankLen+split.length);i++){
        if(i%2===0){
            newTitle +=  '<p class="title">'+split[Math.floor(i/2)]+'</div>'
        }else{
            newTitle +=  new OO.ui.TextInputWidget( {
                name:prefixDic.textInputName+id+'-'+Math.floor(i/2),
                id:prefixDic.textInputId+id+'-'+Math.floor(i/2),
                classes:classes
            } ).$element.prop('outerHTML')
        }
        
    }
    return newTitle
}
//生成B、C型题的选择框
function dropDownInputWidget(id, availabelOptions){
    var options = []
    var select = $('<select class="dorpdown" id="'+prefixDic.selectId+id+'" name="'+prefixDic.selectName+id+'"></select>')
    for(var i=0;i<availabelOptions.length;i++){
        select.append('<option class="dropdown-option" value="'+availabelOptions[i]+'">'+availabelOptions[i]+'</option>')
    }
    return select
}
//生成options(options 是 Map对象)
function optionsGroup(type,id,options){
    var flexClass = (type==='B')||(type==='C') ? 'optionsGroup-flex':''
    var inputType = type==='X' ? 'checkbox':'radio'
    var optionGroupObj = $('<div class="optionsGroup '+flexClass+'"></div>')
    options.forEach(function(value, key, map){
        optionGroupObj.append(optionInline(id, key, value, !((type==='B')||(type==='C')), inputType))
    })
    return optionGroupObj
}
//生成optionInline
function optionInline(id, option, content,input,inputType){
    var idPrefix = inputType === 'checkbox' ? prefixDic.checkBoxId:prefixDic.radioId
    var namePrefix = inputType === 'checkbox' ? prefixDic.checkBoxName:prefixDic.radioName // 这个和外部的div的id一样就共用了

    var input = input ? $('<input id="'+ idPrefix + id+'-'+option+'" name="'+ namePrefix + id + '" type="'+inputType+'" value="' + option + '" />'):''
    var optionLabel = $('<label for="'+ idPrefix + id+'-'+option+'">'+option+'. </label>')
    var contentLabel = $('<label for="'+ idPrefix + id+'-'+option+'">'+content+'</label>')
    return $('<div id="'+ namePrefix +id+'-'+option+'" class="optionInline"></div>').append(input,optionLabel,contentLabel)
}
//清理json中的choice(清除空项并排序),接收Obj,
function cleanAndMakeSameLenOptions(options){
	//清除空项
	var options = filterEmptyEntries(options)
	//让所有option长度一样
	var maxOptionLen = getStrLength(Object.values(options).sort(function(a,b){return getStrLength(b) - getStrLength(a)})[0])
	for(var i in options){
		var minus = maxOptionLen - getStrLength(options[i])
		for(var n=0;n<minus;n++){
			options[i] += '&ensp;'
		}
	}
	// console.log(options)
    return sortDicByKey(options) //返回一个 Map 对象
}
function newTimu(id,json, settings){
    settings = json.settings===undefined||json.isA3 ? settings:json.settings//检测json是否带有settings或者是否为A3子题目

    parent = settings.parent === undefined ? '' : settings.parent
    showHr = settings.showHr == undefined ? true : settings.showHr
    showSubmitBtn = settings.showSubmitBtn === undefined ? true : settings.showSubmitBtn
    showEditBtn = settings.showEditBtn === undefined ? true : settings.showEditBtn
    showBtnGroup = settings.showBtnGroup === undefined? true:settings.showBtnGroup

    var o = new Object()
    o.type = json.type
    o.pos = json.pos
    o.inputBox = json.inputBox
    o.source = json.source
    o.sourceRange = json.sourceRange
    o.info = json.info
    o.title = json.title
    o.options = json.choices
    // console.log(o.options)
    //将choice 统一为Array的转换为obj
    if(typeOfObj(o.options)==='[object Array]'&&o.options.length===1&&o.type!=='A3'){
    	o.options = o.options[0]
    }
    o.options = o.options!==undefined? cleanAndMakeSameLenOptions(o.options):''
    // console.log(o.options)

    o.answer = json.answer
    o.explain = json.explain

    o.temp = {
        main:$('<div name="timu-'+(id+1)+'" id="'+id+'" class="type'+o.type+' timuContainer"><p class="timuID">'+id+'</p></div>'),
    }

    o.parent = parent
    // if(this.type==='A3'){
    //     	$(this).children('.subject').children('.editThisButton').fadeIn(1)
    //     }
    o.temp.main.hover(function () {
        $('editThis-' + id).fadeIn(10)
    },function (){
        $('editThis-' + id).fadeOut(70)
    })

    o.A = function () {
        //subjectForm 
        this.type = json.isA3?'A3':'A'
        var optionsGroupObj = optionsGroup(this.type, id, this.options)
        if(json.isA3){
            var titleInlineObj = titleInline(id, 'A3',this.source,undefined,this.title,'titleInline')
        }else{
            var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
        }
        
        var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
        //resultGroupObj
        var answerInlineObj = answerInline(this.answer)
        var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
        var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])

        this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )

        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.A2 = function () {
        //subjectForm 
        var optionsGroupObj = optionsGroup(this.type, id, this.options)
        var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
        var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
        //resultGroupObj
        var answerInlineObj = answerInline(this.answer)
        var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
        var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])

        this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )

        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.A3 = function () {
        // console.log(settings)
        var realSource = getRealSource(json.source)
        var sourcePrefix = realSource.prefix===''?'':realSource.prefix
        //subjectForm 
        var range = rangeInline(this.source, this.sourceRange)
        var info = infoInline(this.info)

        var subTitlesList = []
        for(var i=0;i<this.title.length;i++){
            if(this.explain[i]==undefined){
                this.explain[i] = '暂无解析'
            }
            var data = {
                'isA3':true,
                "type":"A",
                "source":sourcePrefix+realSource.source+'-'+(i+1),
                "title":this.title[i],
                "answer":this.answer[i],
                "explain":this.explain[i],
                "choices":this.options.get(i+''),
            }
            // console.log(data)
            // console.log(this.options)
            subTitlesList.push(newTimu(id+'-'+i,data,{
                showHr:false,
                showEditBtn:false,
                showSubmitBtn:false,
                showBtnGroup:false
            }).A())
        }
        
        // console.log(this.answer)
        var buttonGroupObj  = buttonGroup(true, false, id, this.type, this.answer, this.temp.main)
        // console.log(buttonGroupObj)
        var subjectFormObj = subjectDIV(id,this.type, [subTitlesList])
        this.temp.main.append(range,info, subjectFormObj, buttonGroupObj)

        this.temp.main.append('<hr>')
        return this.temp.main
    }
    o.B = function () {
        var realSource = getRealSource(json.source)
        var sourcePrefix = realSource.prefix===''?'':realSource.prefix
        //subjectForm 
        var range = rangeInline(this.source, this.sourceRange)
        var optionsGroupObj = optionsGroup(this.type, id, this.options)
        var titleInlineList = []
        for(var i=0;i<this.title.length;i++){
            var dropdown = dropDownInputWidget(id+'-'+i, mapKeysList(this.options))
            var titleInlineObj = titleInline(id+'-'+i, this.type, json.source, i, this.title[i],'titleInline')
            titleInlineObj.append(dropdown)
            titleInlineList.push(titleInlineObj)
        }
        var titlesGroupObj = titlesGroup(titleInlineList)
        var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)

        var subjectForm = subjectFrom(id,this.type, [optionsGroupObj, titlesGroupObj])

        //resultGroupObj
        var resultGroupList = []
        for(var i=0;i<this.answer.length;i++){
            var answerInlineObj = answerInline(this.answer[i])
            var explainInlineObj = this.explain[i] === undefined || this.explain[i] === '' ? '暂无解析' : explainInline(this.explain[i])
            resultGroupList.push(
                    '<b>'+sourcePrefix+realSource.source+'-'+i+'</b>',
                    $('<div style="margin-left:10px"></div>').append(answerInlineObj),
                    $('<div style="margin-left:10px"></div>').append(explainInlineObj)
                )
        }
        var resultGroupObj = resultGroup(id, resultGroupList)

        this.temp.main.append(range ,subjectForm,resultGroupObj, buttonGroupObj)

        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.C = function () {
        var realSource = getRealSource(json.source)
        var sourcePrefix = realSource.prefix===''?'':realSource.prefix
        //subjectForm 
        var range = rangeInline(this.source, this.sourceRange)
        var optionsGroupObj = optionsGroup(this.type, id, this.options)
        var titleInlineList = []
        for(var i=0;i<this.title.length;i++){
            var dropdown = dropDownInputWidget(id+'-'+i, mapKeysList(this.options))
            var titleInlineObj = titleInline(id+'-'+i, this.type, json.source, i, this.title[i],'titleInline')
            titleInlineObj.append(dropdown)
            titleInlineList.push(titleInlineObj)
        }
        var titlesGroupObj = titlesGroup(titleInlineList)
        var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)

        var subjectForm = subjectFrom(id,this.type, [titlesGroupObj, optionsGroupObj])

        //resultGroupObj
        var resultGroupList = []
        for(var i=0;i<this.answer.length;i++){
            var answerInlineObj = answerInline(this.answer[i])
            var explainInlineObj = this.explain[i] === undefined || this.explain[i] === '' ? '暂无解析' : explainInline(this.explain[i])
            resultGroupList.push(
                    '<b>'+sourcePrefix+realSource.source+'-'+i+'</b>',
                    $('<div style="margin-left:10px"></div>').append(answerInlineObj),
                    $('<div style="margin-left:10px"></div>').append(explainInlineObj)
                )
        }
        var resultGroupObj = resultGroup(id, resultGroupList)

        this.temp.main.append(range ,subjectForm,resultGroupObj, buttonGroupObj)

        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.X = function () {
        //subjectForm 
        var optionsGroupObj = optionsGroup(this.type, id, this.options)
        var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
        var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
        //resultGroupObj
        var answerInlineObj = answerInline(this.answer)
        var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
        var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])

        this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )

        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.PD = function () {
    	var dic = {
		      right: ['对', '正确', 't', '✓', '√', '1', 'true'],
		      wrong: ['错', '错误', '×', 'x', 'f', 'false', 'wrong', '0']
		    }
        var ans = ''
        var ansOption = ''
        if(isInArray(dic.right, json.answer.toLowerCase())){
            ans = '正确'
            ansOption = 'A'
        }else if(isInArray(dic.wrong, json.answer.toLowerCase())){
            ans = '错误'
            ansOption = 'B'
        }else {
        	ans = '系统错误:该判断题答案不符合标准格式'
        }

        //subjectForm 
        var option = new Map()
        option.set('A', '正确')
        option.set('B', '错误')
        var optionsGroupObj = optionsGroup(this.type, id, option)
        var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
        var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, 'A', ansOption, this.temp.main):''
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj,optionsGroupObj])
        //resultGroupObj
        var answerInlineObj = answerInline(ans)
        var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
        var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])

        this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )

        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.TK = function () {
        var tkTitle = fillBlank(id, this.title, this.pos, ['text-input-tk'])
        var titleInlineObj = titleInline(id, this.type,this.source,undefined,tkTitle, 'titleInline-no-flex')
        titleInlineObj.children('.text-input-tk').each(function(i,v){
            // console.log(i,v)
            $(this).children('input').css(
                'display','inline'
            )
            $(this).children('input').css(
                'width','200px'
            )
        })
        var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj])

        this.temp.main.append(subjectForm, buttonGroupObj)

        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.MJ = function () {
        var mjTitle = ''
        if(this.inputBox===0){
            mjTitle = json.title + ':<span class="blur" tabindex="0" style="display:inline;outline=0;" onclick="">' + json.answer +'</span>'
        }else{
            mjTitle = fillBlank(id, this.title+':()', '()', ['text-input-mj'])
        }
        var titleInlineObj = titleInline(id, this.type,this.source,undefined,mjTitle, 'titleInline-no-flex')
        titleInlineObj.children('.text-input-mj').each(function(i,v){
            // console.log(i,v)
            $(this).children('input').css(
                'display','inline'
            )
            $(this).children('input').css(
                'width','auto'
            )
        })
        var buttonGroupObj = this.inputBox!==0 ? buttonGroup(showSubmitBtn, showEditBtn, id, 'TK', [this.answer], this.temp.main):''
        var subjectForm = subjectFrom(id,this.type, [titleInlineObj])

        this.temp.main.append(subjectForm, buttonGroupObj)
        if(showHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    return o
}

// // 获取select的选项
function getSelectedAnswer(id){
    var data = formToJSON('#'+prefixDic.formId + id,true)
    console.log(data)
    return data
}
// // 获取checkbox值
function  getCheckBoxValue(name) {
    var  ids = $('input:checkbox[name="'+name+'"]:checked');
    var data = [];
     for (var i = 0; i < ids.length; i ++) {
         data.push(ids[i].value)
     }
     return data
}
function showThisAnswer(id,type,correctAnswer){
	var isRight = false
    var resultGroup = $('#resultGroup-'+id)
    resultGroup.fadeIn(100)
    $('#showThisAnswer-'+id).fadeOut(1)

    if(type==="A" || type ==='A2'){
        var optionGroupName = prefixDic.radioName+id
        var optionInlinePrefixID = prefixDic.radioName+id
        var usersChoice = getSelectedAnswer(id)[optionGroupName]
		console.log(usersChoice)
        var correctDivObj = $('#'+optionInlinePrefixID + '-' + correctAnswer)
        var usersChoiceDivObj = $('#'+optionInlinePrefixID + '-' + usersChoice)
        
        if(usersChoice===correctAnswer){
            correctDivObj.addClass('correct')
            isRight = true
        }else{
            correctDivObj.addClass('correct')
            usersChoiceDivObj.addClass('wrong')
        }

    }else if(type==='A3'){
        for(var i=0;i<correctAnswer.length;i++){
            //以下与A型题时一样的代码,知识用subID替换ID变量
            showThisAnswer(id+'-'+i,'A',correctAnswer[i])
        }
    } else if(type==='B'){
        var dropDownInputPrefix = 'select-'+id +'-'
        var usersChoice = getSelectedAnswer(id)
        // console.log(usersChoice)

        for(var i in usersChoice){
            var dorpdownID = i.replace(dropDownInputPrefix,'')//获取子ID
            var subTimuID = id+'-'+dorpdownID
            var thisTimuUsersChoice = usersChoice[i]
            var thisTimuCorrectAnswer = correctAnswer[dorpdownID]
            var subTimuDiv = $('#title-'+subTimuID)

            if(thisTimuUsersChoice===thisTimuCorrectAnswer){
                subTimuDiv.addClass('correct')
            }else{
                subTimuDiv.addClass('wrong')
                subTimuDiv.append('<label class="answerTip">正确答案:'+thisTimuCorrectAnswer+'</label>')
            }
        }
    } else if(type=="C"){
        var dropDownInputPrefix = 'select-'+id +'-'
        var usersChoice = getSelectedAnswer(id)
        // console.log(usersChoice)

        for(var i in usersChoice){
            var dorpdownID = i.replace(dropDownInputPrefix,'')//获取子ID
            var subTimuID = id+'-'+dorpdownID
            var thisTimuUsersChoice = usersChoice[i]
            var thisTimuCorrectAnswer = correctAnswer[dorpdownID]
            var subTimuDiv = $('#title-'+subTimuID)

            if(thisTimuUsersChoice===thisTimuCorrectAnswer){
                subTimuDiv.addClass('correct')
            }else{
                subTimuDiv.addClass('wrong')
                subTimuDiv.append('<label class="answerTip">正确答案:'+thisTimuCorrectAnswer+'</label>')
            }
        }
    }else if(type=="X"){
        var optionGroupName = 'checkbox-'+id
        var optionInlinePrefixID = 'checkbox-'+id
        var usersChoice = getCheckBoxValue(optionGroupName).sort()
        correctAnswer = correctAnswer.match(/[A-Z]/g).sort()
        var lenCorrect = correctAnswer.length
        var lenUser = usersChoice.length
        // console.log(correctAnswer)
        for(var i=0;i<lenUser;i++){
            // console.log(isInArray(correctAnswer, usersChoice[i]),usersChoice[i] ,correctAnswer)
            if(!isInArray(correctAnswer, usersChoice[i])){
                $('#'+optionInlinePrefixID + '-' + usersChoice[i]).addClass('wrong')
            }
        }

        for(var i=0;i<lenCorrect;i++){
            if(!isInArray(usersChoice,correctAnswer[i])){
                $('#'+optionInlinePrefixID + '-' + correctAnswer[i]).addClass('notChoiced')
            }else {
                $('#'+optionInlinePrefixID + '-' + correctAnswer[i]).addClass('correct')
            }
        }

        
    }else if(type=="TK"){
        var textInputPrefix = prefixDic.textInputId+id+'-'
        var usersChoice = getSelectedAnswer(id)
        for(var i in usersChoice){
            var inputID = i.replace(textInputPrefix,'')
            // console.log('#'+i)
            var corrcetAnswerText = correctAnswer[inputID]===undefined?'暂无答案':correctAnswer[inputID]
            if(usersChoice[i]===correctAnswer[inputID]){
                $('#'+i).html('<label class="answerTip correct">'+corrcetAnswerText+'</label>')
            }else{
                $('#'+i).after('<label class="answerTip wrong">'+corrcetAnswerText+'</label>')
            }
        }
    }
    if(isRight){
    	locateTo(id+1)
    }
}
function removeBackground(obj){
    obj.addClass('no-background')
}