$(function () { var converter = new showdown.Converter(); var phpUnitCode = ""; var javascriptCode = ""; var theType = ""; var no = ""; var isLoading = false; require(["vs/editor/editor.main"], function () { window.editor = monaco.editor.create(document.getElementById('container'), { value: [ ' 0) { window.location.href = '/page/run.php?id=' + r.id; } else if (r.id == 0){ alert('恭喜你!已经做完最后一题!'); window.location.href = '/index.php'; } else { window.location.href = '/index.php'; } } else { alert('很抱歉,获取下一题数据失败,请重试。') } }, error: function () { alert('很抱歉,出错了,请重试!'); } }) } } else { alert('很抱歉,保存数据失败,请重试。') } }, error: function () { alert('很抱歉,出错了,请重试!'); } }) } var printText = function (text) { resultBody.appendChild(document.createTextNode(text)); }; // Ensure the document has a body for IE9 resultDocument.write(''); resultDocument.close(); resultBody = resultDocument.body; clear(); try { /*jshint evil: true */ new Function('phpCode, print, resultBody, pass', javascriptCode)(phpCode, print, resultBody, pass); } catch (error) { printText(' ' + error.toString()); } } function exec(test) { // var start = (new Date()).getTime() var phpCode = window.editor.getValue(); var oldCode = phpCode; if (!test) { if (isLoading) return; isLoading = true; if (phpCode.indexOf('// --------- 测试区域') !== -1) { phpCode = phpCode.substring(0, phpCode.lastIndexOf('// --------- 测试区域')) + phpUnitCode.replace('' + r.result.name + '(' + difficultyStr + ')' + ' - ' + typeStr + '' + converter.makeHtml(r.result.describe)); $('#answerView .cont').html(converter.makeHtml(r.result.answer)); if (r.result.isAnswer !== '1') { $('#answerViewButton').hide(); } window.editor.setValue(r.result.phpCode); phpUnitCode = r.result.phpUnitCode; javascriptCode = r.result.javascriptCode; var testCase = r.result.testCase; var expectedResult = r.result.expectedResult; $('.testCaseContent').html(converter.makeHtml(testCase)); $('.expectedResultContent').html(converter.makeHtml(expectedResult)); $('#rightPane pre code').each(function(i, block) { hljs.highlightBlock(block); }); theType = r.result.type; no = r.result.no; $.ajax({ type: "POST", url: "/api.php?action=getRecord", dataType: "json", cache: !1, timeout: 6e4, data: { user_id: window.localStorage.id, problemset_id: GetQueryString('id'), }, success: function (r) { if (r.status === 1) { window.editor.setValue(r.code); } $('.tabs').tabslet({ controls: { prev: '.prevTab', next: '.nextTab' } }); $('#loading').hide(); }, error: function () { alert('很抱歉,出错了,请稍后刷新重试!'); $('#loading').hide(); } }); } else { alert('很抱歉,获取数据失败,请稍后刷新重试。') } $('#loading').hide(); }, error: function () { alert('很抱歉,出错了,请稍后刷新重试!'); $('#loading').hide(); } }) } else { $('#loading').hide(); $('.tabs').tabslet({ controls: { prev: '.prevTab', next: '.nextTab' } }); } }); });