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

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

MediaWiki界面页面
无编辑摘要
(导入1个版本)
 
(未显示同一用户的5个中间版本)
第1行: 第1行:
/*<%-- [PAGE_INFO]
//设置
     comment = #Please do not remove this struct. It's record contains some important information of edit. This struct will be removed automatically after you push edits.#
var prefixDic = {
     pageTitle = #MediaWiki:Gadget-tikuRenderModule.js#
    formId:'timuForm-',
     pageID = #3426#
    radioName:'radio-',
     revisionID = #69839#
     radioId:'radio-input-',
     contentModel = #javascript#
     checkBoxName:'checkbox-',
     contentFormat = #text/javascript#
     checkBoxId:'checkbox-input-',
[END_PAGE_INFO] --%>*/
     selectId:'select-',
     selectName:'select-',
     textInputName:'text-',
    textInputId:'text-'
}
 
 
//主函数
//主函数
function renderTimuFromSessionStorage(){
function renderTimuFromSessionStorage(){
var timuList = gDomTimuList()
var timuList = gDomTimuList()
console.log(timuList)
// console.log(timuList)
var order = timuList.order
var order = timuList.order
var timu = timuList.timu
var timu = timuList.timu
第79行: 第85行:
//从有中文的source中提取最后一个连续数字作为真实的source
//从有中文的source中提取最后一个连续数字作为真实的source
function getRealSource(source){
function getRealSource(source){
     console.log(source)
     // console.log(source)
var getContinueNumber = source.match(/[0-9]+/g)
var getContinueNumber = source.match(/[0-9]+/g)
var splitContinueNumber = source.split(/[0-9]+/g)
var splitContinueNumber = source.split(/[0-9]+/g)
第113行: 第119行:
     return $('<p class="title">'+title+'</p>')
     return $('<p class="title">'+title+'</p>')
}
}
//生成B、C型题的选择框
function dropDownInputWidget(id, availabelOptions){
    var options = []
    for(var i=0;i<availabelOptions.length;i++){
        options.push({
            data:availabelOptions[i],
            label:availabelOptions[i]
        })
    }
    return new OO.ui.DropdownInputWidget( {
        name:'dropdown-input-'+id,
        options: options,
        classes:['dorpdown']
    } ).$element
}
//生成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){
    console.log(input)
    var input = input ? $('<input id="option-input-'+id+'-'+option+'" name="optionsGroup-' + id + '" type="'+inputType+'" value="' + option + '" />'):''
    var optionLabel = $('<label for="option-input-'+id+'-'+option+'">'+option+'. </label>')
    var contentLabel = $('<label for="option-input-'+id+'-'+option+'">'+content+'</label>')
    return $('<div id="option-'+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] += '&#160;'
}
}
    return sortDicByKey() //返回一个 Map 对象
}
//生成buttonGroup
//生成buttonGroup
function buttonGroup(showSubmitBtn, showEditBtn, id, type, correctAnswer, hoverTarget){
function buttonGroup(showSubmitBtn, showEditBtn, id, type, correctAnswer, hoverTarget){
     console.log(showEditBtn)
     // console.log(showEditBtn)
     var buttonGroupObj = $('<div class="buttonGroup"></div>')
     var buttonGroupObj = $('<div class="buttonGroup"></div>')
     if(showSubmitBtn){buttonGroupObj.append(
     if(showSubmitBtn){buttonGroupObj.append(
第202行: 第158行:
     return buttonGroupObj
     return buttonGroupObj
}
}
//生成subject 的form, 顺序items顺序添加 (title, options, buttonGroup)
function subjectFrom(id, items, title, options, buttonGroup){
    var form =  $('<form id="timuFrom-'+id+'" class="subjectForm"></form>')
    for(var i=0;i<items.length;i++){
        form.append(items[i])
    }
    return form
}
//resultGroup: answer和explain的显示框
//resultGroup: answer和explain的显示框
function resultGroup(id, items, answerInline,explainInline){
function resultGroup(id, items, answerInline,explainInline){
第227行: 第174行:
     return $('<div class="explainInline"><label>解析:</label>'+explain+'</div>')
     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){
function fillBlank(id, title, pos, classes){
     console.log(pos)
     // console.log(pos)
     var posReg = new RegExp(pos,'g')
     var posReg = new RegExp(pos,'g')
     var blankLen = title.match(posReg).length
     var blankLen = title.match(posReg).length
     var split = title.split(posReg)
     var split = title.split(posReg)
     console.log(blankLen)
     // console.log(blankLen)
     var newTitle = ''
     var newTitle = ''
     for(var i=0;i<(blankLen+split.length);i++){
     for(var i=0;i<(blankLen+split.length);i++){
第240行: 第211行:
         }else{
         }else{
             newTitle +=  new OO.ui.TextInputWidget( {
             newTitle +=  new OO.ui.TextInputWidget( {
                 name:'textInput-'+id+'-'+Math.floor(i/2),
                 name:prefixDic.textInputName+id+'-'+Math.floor(i/2),
                 id:'textInput-'+id+'-'+Math.floor(i/2),
                 id:prefixDic.textInputId+id+'-'+Math.floor(i/2),
                 classes:classes
                 classes:classes
             } ).$element.prop('outerHTML')
             } ).$element.prop('outerHTML')
第249行: 第220行:
     return newTitle
     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){
function newTimu(id,json, settings){
     settings = json.settings===undefined||json.isA3 ? settings:json.settings//检测json是否带有settings或者是否为A3子题目
     settings = json.settings===undefined||json.isA3 ? settings:json.settings//检测json是否带有settings或者是否为A3子题目
第268行: 第282行:
     o.title = json.title
     o.title = json.title
     o.options = json.choices
     o.options = json.choices
     console.log(o.options)
     // console.log(o.options)
     //将choice 统一为Array的转换为obj
     //将choice 统一为Array的转换为obj
     if(typeOfObj(o.options)==='[object Array]'&&o.options.length===1&&o.type!=='A3'){
     if(typeOfObj(o.options)==='[object Array]'&&o.options.length===1&&o.type!=='A3'){
第274行: 第288行:
     }
     }
     o.options = o.options!==undefined? cleanAndMakeSameLenOptions(o.options):''
     o.options = o.options!==undefined? cleanAndMakeSameLenOptions(o.options):''
     console.log(o.options)
     // console.log(o.options)


     o.answer = json.answer
     o.answer = json.answer
第281行: 第295行:
     o.temp = {
     o.temp = {
         main:$('<div name="timu-'+(id+1)+'" id="'+id+'" class="type'+o.type+' timuContainer"><p class="timuID">'+id+'</p></div>'),
         main:$('<div name="timu-'+(id+1)+'" id="'+id+'" class="type'+o.type+' timuContainer"><p class="timuID">'+id+'</p></div>'),
        subject:$('<form class="subject"></form>'),
        range:$('<div class="sourceRange"></div>'),
        info:$('<div class="info"></div>'),
        titleCon:$('<div class="titleContainer"></div>'),
        type:$('<p class="source"></p>'),
        source:$('<p class="source"></p>'),
        title:$('<p class="title"></p>'),
        options:$('<div class="options"></div>'),
        btn:$('<button type="button" class="button-small button-pill button button-caution" id="showSingle-' + id + '" class="showSingleBtn">提交</button>'),
        editBtn:$('<a class="editThisButton" style="display:none;font-size: 14px;margin-left: 5px" href="javascript:void(0)"><span class="" id="editThis-' + id + '">题目有误?点击编辑本题</span></a>'),
        ansCon:$('<div id="ansContainer" class="ansContainer noDisplay"></div>'),
        correct:$('<p style="display:inline;"><b>正确答案:</b></p><p class="correctAnswer"></p><br>'),
        explain:$('<p style="display:inline;"><b>解析: </b></p><p class="explain"></p><br>'),
        select:$('<select class="button-small button-rounded button"></select>'),
        subTitle:$('<div id=""></div>')
     }
     }


第310行: 第309行:
     o.A = function () {
     o.A = function () {
         //subjectForm  
         //subjectForm  
        this.type = json.isA3?'A3':'A'
         var optionsGroupObj = optionsGroup(this.type, id, this.options)
         var optionsGroupObj = optionsGroup(this.type, id, this.options)
         if(json.isA3){
         if(json.isA3){
第318行: 第318行:
          
          
         var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
         var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
         var subjectForm = subjectFrom(id, [titleInlineObj, optionsGroupObj, buttonGroupObj])
         var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
         //resultGroupObj
         //resultGroupObj
         var answerInlineObj = answerInline(this.answer)
         var answerInlineObj = answerInline(this.answer)
第324行: 第324行:
         var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
         var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])


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


         if(showHr){this.temp.main.append('<hr>')}
         if(showHr){this.temp.main.append('<hr>')}
第334行: 第334行:
         var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
         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 buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)
         var subjectForm = subjectFrom(id, [titleInlineObj, optionsGroupObj, buttonGroupObj])
         var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
         //resultGroupObj
         //resultGroupObj
         var answerInlineObj = answerInline(this.answer)
         var answerInlineObj = answerInline(this.answer)
第340行: 第340行:
         var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
         var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])


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


         if(showHr){this.temp.main.append('<hr>')}
         if(showHr){this.temp.main.append('<hr>')}
第346行: 第346行:
     }
     }
     o.A3 = function () {
     o.A3 = function () {
         console.log(settings)
         // console.log(settings)
         var realSource = getRealSource(json.source)
         var realSource = getRealSource(json.source)
         var sourcePrefix = realSource.prefix===''?'':realSource.prefix
         var sourcePrefix = realSource.prefix===''?'':realSource.prefix
第367行: 第367行:
                 "choices":this.options.get(i+''),
                 "choices":this.options.get(i+''),
             }
             }
             console.log(data)
             // console.log(data)
             console.log(this.options)
             // console.log(this.options)
             subTitlesList.push(newTimu(id+'-'+i,data,{
             subTitlesList.push(newTimu(id+'-'+i,data,{
                 showHr:false,
                 showHr:false,
第377行: 第377行:
         }
         }
          
          
         console.log(this.answer)
         // console.log(this.answer)
         var buttonGroupObj  = buttonGroup(true, false, id, this.type, this.answer, this.temp.main)
         var buttonGroupObj  = buttonGroup(true, false, id, this.type, this.answer, this.temp.main)
         console.log(buttonGroupObj)
         // console.log(buttonGroupObj)
         var subjectFormObj = subjectFrom(id, [subTitlesList,buttonGroupObj])
         var subjectFormObj = subjectDIV(id,this.type, [subTitlesList])
         this.temp.main.append(range,info, subjectFormObj)
         this.temp.main.append(range,info, subjectFormObj, buttonGroupObj)


         this.temp.main.append('<hr>')
         this.temp.main.append('<hr>')
第402行: 第402行:
         var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)
         var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)


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


         //resultGroupObj
         //resultGroupObj
第417行: 第417行:
         var resultGroupObj = resultGroup(id, resultGroupList)
         var resultGroupObj = resultGroup(id, resultGroupList)


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


         if(showHr){this.temp.main.append('<hr>')}
         if(showHr){this.temp.main.append('<hr>')}
第438行: 第438行:
         var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)
         var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)


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


         //resultGroupObj
         //resultGroupObj
第453行: 第453行:
         var resultGroupObj = resultGroup(id, resultGroupList)
         var resultGroupObj = resultGroup(id, resultGroupList)


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


         if(showHr){this.temp.main.append('<hr>')}
         if(showHr){this.temp.main.append('<hr>')}
第463行: 第463行:
         var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
         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 buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
         var subjectForm = subjectFrom(id, [titleInlineObj, optionsGroupObj, buttonGroupObj])
         var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
         //resultGroupObj
         //resultGroupObj
         var answerInlineObj = answerInline(this.answer)
         var answerInlineObj = answerInline(this.answer)
第469行: 第469行:
         var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
         var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])


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


         if(showHr){this.temp.main.append('<hr>')}
         if(showHr){this.temp.main.append('<hr>')}
第479行: 第479行:
      wrong: ['错', '错误', '×', 'x', 'f', 'false', 'wrong', '0']
      wrong: ['错', '错误', '×', 'x', 'f', 'false', 'wrong', '0']
    }
    }
        this.temp.type.text('判断')
        this.temp.source.text(json.source)
        this.temp.title.html(json.title)
        this.temp.explain.nextAll('.explain').html(json.explain)
         var ans = ''
         var ans = ''
         var ansOption = ''
         var ansOption = ''
第502行: 第498行:
         var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
         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 buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, 'A', ansOption, this.temp.main):''
         var subjectForm = subjectFrom(id, [titleInlineObj, optionsGroupObj, buttonGroupObj])
         var subjectForm = subjectFrom(id,this.type, [titleInlineObj,optionsGroupObj])
         //resultGroupObj
         //resultGroupObj
         var answerInlineObj = answerInline(ans)
         var answerInlineObj = answerInline(ans)
第508行: 第504行:
         var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
         var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])


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


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


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


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


         this.temp.main.append(subjectForm)
         this.temp.main.append(subjectForm, buttonGroupObj)
         if(showHr){this.temp.main.append('<hr>')}
         if(showHr){this.temp.main.append('<hr>')}
         return this.temp.main
         return this.temp.main
第560行: 第556行:
}
}


// // 获取select的选项
function getSelectedAnswer(id){
function getSelectedAnswer(id){
     var data = formToJSON('#timuFrom-'+id,true)
     var data = formToJSON('#'+prefixDic.formId + id,true)
    console.log(data)
     return 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){
function showThisAnswer(id,type,correctAnswer){
    var subjectCon = $('#'+id)
var isRight = false
    var titleCon = subjectCon.children('.subject').children('.titleContainer')
     var resultGroup = $('#resultGroup-'+id)
     var resultGroup = $('#resultGroup-'+id)
     resultGroup.fadeIn(100)
     resultGroup.fadeIn(100)
    var answers = subjectCon.children('.subject').children('.options')
     $('#showThisAnswer-'+id).fadeOut(1)
     $('#showThisAnswer-'+id).fadeOut(1)


     if(type==="A" || type ==='A2'){
     if(type==="A" || type ==='A2'){
         var optionGroupID = 'optionsGroup-'+id
         var optionGroupName = prefixDic.radioName+id
         var optionInlinePrefixID = 'option-'+id
         var optionInlinePrefixID = prefixDic.radioName+id
         var usersChoice = getSelectedAnswer(id)[optionGroupID]
         var usersChoice = getSelectedAnswer(id)[optionGroupName]
 
console.log(usersChoice)
         var correctDivObj = $('#'+optionInlinePrefixID + '-' + correctAnswer)
         var correctDivObj = $('#'+optionInlinePrefixID + '-' + correctAnswer)
         var usersChoiceDivObj = $('#'+optionInlinePrefixID + '-' + usersChoice)
         var usersChoiceDivObj = $('#'+optionInlinePrefixID + '-' + usersChoice)
第583行: 第587行:
         if(usersChoice===correctAnswer){
         if(usersChoice===correctAnswer){
             correctDivObj.addClass('correct')
             correctDivObj.addClass('correct')
            isRight = true
         }else{
         }else{
             correctDivObj.addClass('correct')
             correctDivObj.addClass('correct')
第594行: 第599行:
         }
         }
     } else if(type==='B'){
     } else if(type==='B'){
         var dropDownInputPrefix = 'dropdown-input-'+id +'-'
         var dropDownInputPrefix = 'select-'+id +'-'
         var usersChoice = getSelectedAnswer(id)
         var usersChoice = getSelectedAnswer(id)
         console.log(usersChoice)
         // console.log(usersChoice)


         for(var i in usersChoice){
         for(var i in usersChoice){
第613行: 第618行:
         }
         }
     } else if(type=="C"){
     } else if(type=="C"){
         var dropDownInputPrefix = 'dropdown-input-'+id +'-'
         var dropDownInputPrefix = 'select-'+id +'-'
         var usersChoice = getSelectedAnswer(id)
         var usersChoice = getSelectedAnswer(id)
         console.log(usersChoice)
         // console.log(usersChoice)


         for(var i in usersChoice){
         for(var i in usersChoice){
第632行: 第637行:
         }
         }
     }else if(type=="X"){
     }else if(type=="X"){
         var optionGroupID = 'optionsGroup-'+id
         var optionGroupName = 'checkbox-'+id
         var optionInlinePrefixID = 'option-'+id
         var optionInlinePrefixID = 'checkbox-'+id
         var usersChoice = getCheckBoxValue(optionGroupID).sort()
         var usersChoice = getCheckBoxValue(optionGroupName).sort()
         correctAnswer = correctAnswer.match(/[A-Z]/g).sort()
         correctAnswer = correctAnswer.match(/[A-Z]/g).sort()
         var lenCorrect = correctAnswer.length
         var lenCorrect = correctAnswer.length
         var lenUser = usersChoice.length
         var lenUser = usersChoice.length
         console.log(correctAnswer)
         // console.log(correctAnswer)
         for(var i=0;i<lenUser;i++){
         for(var i=0;i<lenUser;i++){
             console.log(isInArray(correctAnswer, usersChoice[i]),usersChoice[i] ,correctAnswer)
             // console.log(isInArray(correctAnswer, usersChoice[i]),usersChoice[i] ,correctAnswer)
             if(!isInArray(correctAnswer, usersChoice[i])){
             if(!isInArray(correctAnswer, usersChoice[i])){
                 $('#'+optionInlinePrefixID + '-' + usersChoice[i]).addClass('wrong')
                 $('#'+optionInlinePrefixID + '-' + usersChoice[i]).addClass('wrong')
第656行: 第661行:
          
          
     }else if(type=="TK"){
     }else if(type=="TK"){
         var textInputPrefix = 'textInput-'+id+'-'
         var textInputPrefix = prefixDic.textInputId+id+'-'
         var usersChoice = getSelectedAnswer(id)
         var usersChoice = getSelectedAnswer(id)
         for(var i in usersChoice){
         for(var i in usersChoice){
             var inputID = i.replace(textInputPrefix,'')
             var inputID = i.replace(textInputPrefix,'')
             console.log('#'+i)
             // console.log('#'+i)
             var corrcetAnswerText = correctAnswer[inputID]===undefined?'暂无答案':correctAnswer[inputID]
             var corrcetAnswerText = correctAnswer[inputID]===undefined?'暂无答案':correctAnswer[inputID]
             if(usersChoice[i]===correctAnswer[inputID]){
             if(usersChoice[i]===correctAnswer[inputID]){
第668行: 第673行:
             }
             }
         }
         }
    }
    if(isRight){
    locateTo(id+1)
     }
     }
}
}
function removeBackground(obj){
function removeBackground(obj){
     obj.addClass('no-background')
     obj.addClass('no-background')
}
//DOM操作
//获取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 addAfterIDData(id,content) {
    var data = $('.data')
    content.insertAfter(data[id])
}
//渲染题目
function render(id,type,obj,parent,isAfter){
    parent =parent !==undefined ?parent : '#subjectContainer-'+type
    if(typeof(parent)!=='object'){
        parent = $(parent)
    }
    if(isObjExist(parent)){
        if(isAfter){
            parent.after(obj)
        }else {
            obj.appendTo(parent)
        }
    }else {
        addAfterIDData(id,obj)
    }
}
//基础函数
//判断函数
function isObjExist(t){
    return $(t).length>0
}
function isInArray (arr, value) {
  for (var i = 0; i < arr.length; i++) {
    if (value === arr[i]) {
      return true
    }
  }
  return false
}
//数据查询函数
function dicLen(dic){
    var count=0;
    for(var key in dic){
        console.log(key+'='+dic[key]);
        count++;
    }
    return count
}
//html操作函数
function entityToString(entity){
    var div=$('<div></div>');
    div.html(entity)
    var res=div.html();
    console.log(entity,'->',res);
    return res;
}
//获取map中键的列表
function mapKeysList(map){
    return Array.from(map.keys())
}
//获取字符串真实长度
function getStrLength(str) {
    //1、定义计数器
    var len=0,code=0;
    //2、遍历该字符串
    for(var i=0;i<str.length;i++)
    {
        code=str.charCodeAt(i)
        if (code>=0&&code<=127) {
            len+=1;
        }else{
            len+=2;
        }
    }
    return len
}
//数据清理
//去除字典中的空值
function filterEmptyEntries(dic){
    console.log(Object.fromEntries(
        Object.entries(dic).filter(function(key, value){return value !== null && value !== undefined && value.length !== 0})
    ))
    return Object.fromEntries(
        Object.entries(dic).filter(function(key, value){return value !== null && value !== undefined && value.length !== 0})
    )
}
//排序字典并返回一个map对象
function sortDicByKey(dic){
    var sort = Object.keys(dic).sort()
    var map = new Map()
    for(var i=0;i<sort.length;i++){
        map.set(sort[i],dic[sort[i]])
    }
    return map
}
}

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')
}