Commit 35de1d9db6d316bc3761e989bf1aed7d97efc025

Authored by ykxie
1 parent b8f443cd

add compile

src/live/js/main.js
@@ -70,6 +70,10 @@ $(function(){ @@ -70,6 +70,10 @@ $(function(){
70 liveCompileFun: function(){} 70 liveCompileFun: function(){}
71 } 71 }
72 72
  73 + // 禁止关闭浏览器
  74 + // window.onbeforeunload = function(){
  75 + // return ('你确定要结束教学吗?请确认保存内容');
  76 + // }
73 77
74 LiveTeacher.init(); 78 LiveTeacher.init();
75 79
@@ -123,41 +127,14 @@ $(function(){ @@ -123,41 +127,14 @@ $(function(){
123 }); 127 });
124 } 128 }
125 129
  130 + function liveOutFun(){
  131 + window.onbeforeunload = function(){
  132 + return ('你确定要结束教学吗?')
  133 + }
  134 + }
126 135
127 136
128 137
129 - // $('#CompileBtn').on('click', function(){  
130 - // console.log('编译' + teacher.getValue());  
131 - // var el = document.querySelector('#CompileBtn')  
132 - // var l = Ladda.create(el);  
133 - // l.start();  
134 -  
135 - // var input = $('#input').val() || '';  
136 - // var code = teacher.getValue();  
137 - // var compileData = {  
138 - // code: code,  
139 - // langid: 10,  
140 - // input: input  
141 - // }  
142 - // $.ajax({  
143 - // type: "post",  
144 - // url: gxb_api + "/submit/submitCode/api",  
145 - // data: JSON.stringify(compileData),  
146 - // dataType: "json",  
147 - // contentType: "application/json",  
148 - // success: function(data) {  
149 - // console.log(data);  
150 - // l.remove();  
151 - // compileResult(data);  
152 - // },  
153 - // error: function(){  
154 - // l.stop();  
155 - // alert('错误');  
156 - // }  
157 - // });  
158 - // })  
159 -  
160 -  
161 138
162 /** 139 /**
163 * 组合录入代码 140 * 组合录入代码
@@ -180,37 +157,5 @@ $(function(){ @@ -180,37 +157,5 @@ $(function(){
180 IDELive.record_startime = currenttime; //设定起始时间 157 IDELive.record_startime = currenttime; //设定起始时间
181 } 158 }
182 159
183 - // 编译结果  
184 - function compileResult(data){  
185 - if(data.result){  
186 -  
187 - $('#cmpinfo').html('<p class="text-warning">' + data.cmpinfo.replace(/\n/g, "<br />") + "</p>");  
188 - $('#stderr').html('<p class="text-danger">' + data.stderr.replace(/\n/g, "<br />") + "</p>");  
189 - $('#output').html('<p class="text-success">' + data.output.replace(/\n/g, "<br />") + "</p>");  
190 -  
191 - if(data.cmpinfo.length){  
192 - $('#cmprun-tabs a[href="#cmpinfo"]').tab('show');  
193 - }else if(data.stderr.length){  
194 - $('#cmprun-tabs a[href="#stderr"]').tab('show');  
195 - }else if(data.output.length){  
196 - $('#cmprun-tabs a[href="#output"]').tab('show');  
197 - }  
198 -  
199 - if(!data.cmpinfo.length){  
200 - $('#cmpinfo').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 编译已成功</p>');  
201 - }  
202 -  
203 - if(!data.stderr.length){  
204 - $('#stderr').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 无输出错误</p>');  
205 - }  
206 -  
207 - if(!data.output.length){  
208 - $('#output').prepend('<p class="alert alert-warning"><i class="glyphicon glyphicon-exclamation-sign"></i> 代码编译错误或者运行相关功能受限制</p>');  
209 - }  
210 -  
211 - }else{  
212 - $('#cmpinfo').html('<p class="alert alert-danger"><i class="glyphicon glyphicon-exclamation-sign"></i> 云端编译超时,请稍后重新尝试</p>');  
213 - $('#cmprun-tabs a[href="#cmpinfo"]').tab('show');  
214 - }  
215 - } 160 +
216 }) 161 })
217 \ No newline at end of file 162 \ No newline at end of file
src/live/js/student.js
1 -$(function(){ 1 +$(function() {
  2 + var teacherId = document.getElementById('teacher');
  3 + var studentId = document.getElementById('student');
  4 + var socket = io('http://localhost:3000');
2 5
3 - $('#CompileBtn').trigger('click'); 6 + var teacher = CodeMirror.fromTextArea(teacherId, {
  7 + value: '输入HTML代码',
  8 + mode: 'text/javascript',
  9 + readOnly: true,
  10 + lineNumbers: true,
  11 + smartIndent: false
  12 + });
4 13
5 - $('#CompileBtn').on('click', function(){ 14 + var student = CodeMirror.fromTextArea(studentId, {
  15 + value: '输入HTML代码',
  16 + mode: 'text/javascript',
  17 + lineNumbers: true,
  18 + smartIndent: false
  19 + });
  20 +
  21 +
  22 + socket.on('teacher.programming', function(msg) {
  23 + console.log(msg);
  24 + var msgObj = JSON.parse(msg)
  25 + // student.setValue(msg)
  26 + processChangeObject(teacher, msgObj);
  27 +
  28 + $('#messages').append($('<li>').text(msg));
  29 + window.scrollTo(0, document.body.scrollHeight);
  30 + });
  31 +
  32 + socket.on('programming.content', function(msg) {
  33 + console.log('programming.content ---- ' + msg);
  34 + teacher.setValue(msg);
  35 + // socket.emit('programming.content', teacher.getValue());
  36 + });
  37 +
  38 + socket.on('programming.compile', function(msg) {
  39 + console.log('-------------');
  40 + console.log(msg);
  41 + // $('#CompileBtn').trigger('click');
6 console.log('编译' + teacher.getValue()); 42 console.log('编译' + teacher.getValue());
7 var el = document.querySelector('#CompileBtn') 43 var el = document.querySelector('#CompileBtn')
8 var l = Ladda.create(el); 44 var l = Ladda.create(el);
@@ -31,41 +67,44 @@ $(function(){ @@ -31,41 +67,44 @@ $(function(){
31 alert('错误'); 67 alert('错误');
32 } 68 }
33 }); 69 });
34 - }) 70 + });
35 71
36 72
37 73
38 - // 编译结果  
39 - function compileResult(data){  
40 - if(data.result){  
41 74
42 - $('#cmpinfo').html('<p class="text-warning">' + data.cmpinfo.replace(/\n/g, "<br />") + "</p>");  
43 - $('#stderr').html('<p class="text-danger">' + data.stderr.replace(/\n/g, "<br />") + "</p>");  
44 - $('#output').html('<p class="text-success">' + data.output.replace(/\n/g, "<br />") + "</p>");  
45 -  
46 - if(data.cmpinfo.length){  
47 - $('#cmprun-tabs a[href="#cmpinfo"]').tab('show');  
48 - }else if(data.stderr.length){  
49 - $('#cmprun-tabs a[href="#stderr"]').tab('show');  
50 - }else if(data.output.length){  
51 - $('#cmprun-tabs a[href="#output"]').tab('show');  
52 - }  
53 -  
54 - if(!data.cmpinfo.length){  
55 - $('#cmpinfo').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 编译已成功</p>');  
56 - }  
57 -  
58 - if(!data.stderr.length){  
59 - $('#stderr').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 无输出错误</p>');  
60 - }  
61 -  
62 - if(!data.output.length){  
63 - $('#output').prepend('<p class="alert alert-warning"><i class="glyphicon glyphicon-exclamation-sign"></i> 代码编译错误或者运行相关功能受限制</p>');  
64 - }  
65 75
66 - }else{  
67 - $('#cmpinfo').html('<p class="alert alert-danger"><i class="glyphicon glyphicon-exclamation-sign"></i> 云端编译超时,请稍后重新尝试</p>');  
68 - $('#cmprun-tabs a[href="#cmpinfo"]').tab('show'); 76 +
  77 +
  78 + $('#CompileBtn').on('click', function(){
  79 + console.log('编译' + teacher.getValue());
  80 + var el = document.querySelector('#CompileBtn')
  81 + var l = Ladda.create(el);
  82 + l.start();
  83 +
  84 + var input = $('#input').val() || '';
  85 + var code = teacher.getValue();
  86 + var compileData = {
  87 + code: code,
  88 + langid: 10,
  89 + input: input
69 } 90 }
70 - }  
71 -})  
72 \ No newline at end of file 91 \ No newline at end of file
  92 + $.ajax({
  93 + type: "post",
  94 + url: gxb_api + "/submit/submitCode/api",
  95 + data: JSON.stringify(compileData),
  96 + dataType: "json",
  97 + contentType: "application/json",
  98 + success: function(data) {
  99 + console.log(data);
  100 + l.remove();
  101 + compileResult(data);
  102 + },
  103 + error: function(){
  104 + l.stop();
  105 + alert('错误');
  106 + }
  107 + });
  108 + })
  109 +
  110 +
  111 +});
73 \ No newline at end of file 112 \ No newline at end of file
src/live/js/teacher.js 0 → 100644
  1 +$(function(){
  2 + var teacherId = document.getElementById('teacher');
  3 + var socket = io('http://localhost:3000');
  4 +
  5 + // 初始化codemirror页面
  6 + var teacher = CodeMirror.fromTextArea(teacherId, {
  7 + value: '输入HTML代码',
  8 + mode: 'text/javascript',
  9 + lineNumbers: true,
  10 + smartIndent: false
  11 + });
  12 +
  13 + // 记录每次操作的变化
  14 + CodeMirror.on(teacher,"change", function(instance, changeObj) {
  15 + // console.log(instance);
  16 + // console.log(changeObj);
  17 + var changeObjStr = JSON.stringify(changeObj);
  18 +
  19 + //
  20 + socket.emit('teacher.programming', changeObjStr);
  21 +
  22 + socket.emit('programming.content', teacher.getValue());
  23 +
  24 + // 构建操作对象
  25 + buildOperate('teacher', changeObj);
  26 +
  27 + console.log(IDELive.operations);
  28 +
  29 + });
  30 +
  31 + // 链接时执行初始化代码
  32 + socket.on('programming.content', function(msg) {
  33 + // teacher.setValue(msg);
  34 + });
  35 +
  36 +
  37 +
  38 + var IDELive = {
  39 + operations: [] // 存储录制时的动作对象
  40 + }
  41 +
  42 +
  43 +
  44 +
  45 +
  46 + var LiveTeacher = {
  47 + init: function(){
  48 + LiveTeacher.events();
  49 + },
  50 + events: function(){
  51 + var _this = this;
  52 + $('#liveStart').on('click', function(){ liveStartFun(); });
  53 + $('#liveEnd').on('click', function(){ });
  54 +
  55 + $('#liveConfirm').on('click', function(){ liveConfirmFun(); });
  56 + $('#liveCancel').on('click', function(){ liveCancelFun() });
  57 +
  58 + $('#liveSave').on('click', function(){ });
  59 + $('#liveOut').on('click', function(){ liveOutFun(); });
  60 +
  61 + $('#CompileBtn').on('click', function(){ liveCompileFun(); });
  62 +
  63 + },
  64 + liveStartFun: function(){},
  65 + liveEndFun: function(){},
  66 +
  67 + liveConfirmFun: function(){},
  68 + liveCancelFun: function(){},
  69 +
  70 + liveSaveFun: function(){},
  71 + liveOutFun: function(){},
  72 +
  73 + liveCompileFun: function(){}
  74 + }
  75 +
  76 + // 禁止关闭浏览器
  77 + // window.onbeforeunload = function(){
  78 + // return ('你确定要结束教学吗?请确认保存内容');
  79 + // }
  80 +
  81 + LiveTeacher.init();
  82 +
  83 + // 开始录制
  84 + function liveStartFun(){
  85 + $('.tip-wrap').show();
  86 + }
  87 +
  88 + // 确认开始录制
  89 + function liveConfirmFun(){
  90 + $('.tip-wrap').hide();
  91 + IDELive.record_startime = new Date().getTime()
  92 + console.log(IDELive.record_startime);
  93 + }
  94 +
  95 + // 取消开始录制
  96 + function liveCancelFun(){
  97 + $('.tip-wrap').hide();
  98 + }
  99 +
  100 + // 编译
  101 + function liveCompileFun(){
  102 + console.log('编译' + teacher.getValue());
  103 +
  104 + socket.emit('programming.compile');
  105 +
  106 + var el = document.querySelector('#CompileBtn')
  107 + var l = Ladda.create(el);
  108 + l.start();
  109 +
  110 + var input = $('#input').val() || '';
  111 + var code = teacher.getValue();
  112 + var compileData = {
  113 + code: code,
  114 + langid: 10,
  115 + input: input
  116 + }
  117 + $.ajax({
  118 + type: "post",
  119 + url: gxb_api + "/submit/submitCode/api",
  120 + data: JSON.stringify(compileData),
  121 + dataType: "json",
  122 + contentType: "application/json",
  123 + success: function(data) {
  124 + console.log(data);
  125 + l.remove();
  126 + compileResult(data);
  127 + },
  128 + error: function(){
  129 + l.stop();
  130 + alert('错误');
  131 + }
  132 + });
  133 + }
  134 +
  135 + // 结束录制
  136 + function liveOutFun(){
  137 + // 课程结束时清楚服务端记录的数据
  138 + socket.emit('programming.clear', '');
  139 + teacher.setValue('');
  140 + console.log('programming.clear')
  141 +
  142 + // socket.on('programming.clear', function(msg) {
  143 + // console.log('programming.clear ---- ');
  144 + // content = '';
  145 + // io.emit('programming.content', msg);
  146 + // });
  147 +
  148 +
  149 + // window.onbeforeunload = function(){
  150 + // return ('你确定要结束教学吗?')
  151 + // }
  152 + }
  153 +
  154 +
  155 +
  156 +
  157 + /**
  158 + * 组合录入代码
  159 + * by Kira 2017-5-17
  160 + */
  161 + function buildOperate(editor, changeobj){
  162 + var intervaltime,
  163 + currenttime = new Date().getTime();
  164 + console.log(IDELive.record_startime);
  165 + var intervaltime = currenttime - IDELive.record_startime;
  166 +
  167 + var operateObj = {
  168 + intervaltime: intervaltime,
  169 + editor: editor,
  170 + changeobj: changeobj,
  171 + currenttime: currenttime,
  172 + trigger: 0
  173 + };
  174 + IDELive.operations.push( operateObj); // 添加每次输入对象
  175 + IDELive.record_startime = currenttime; //设定起始时间
  176 + }
  177 +
  178 +
  179 +})
  180 +
  181 +
  182 +
src/live/js/utils.js
1 -// 编译  
2 -function compileRun(l){  
3 - var l = Ladda.create(el);  
4 - l.start(); 1 +/**
  2 + * 通用方法
  3 + * by Kira 2017-5-19
  4 + */
5 5
  6 +// 往编辑器中写入代码
  7 +function processChangeObject(playbackcm, obj) {
6 8
  9 + for (var i = 0; i < obj.text.length; i++) {
  10 + /* 设置鼠标行标示 */
  11 + if (playbackcm.getTextArea().id === "HTMLplayer") {
  12 + if (htmlhlLine !== null) {
  13 + playbackcm.clearMarker(htmlhlLine);
  14 + }
  15 + htmlhlLine = playbackcm.setMarker(obj.from.line + i, '<span class="text-primary glyphicon glyphicon-pencil"></span>');
  16 + } else if (playbackcm.getTextArea().id === "CSSplayer") {
  17 + if (csshlLine !== null) {
  18 + playbackcm.clearMarker(csshlLine);
  19 + }
  20 + csshlLine = playbackcm.setMarker(obj.from.line + i, '<span class="text-primary glyphicon glyphicon-pencil"></span>');
  21 + } else if (playbackcm.getTextArea().id === "JSplayer") {
  22 + if (jshlLine !== null) {
  23 + playbackcm.clearMarker(jshlLine);
  24 + }
  25 + jshlLine = playbackcm.setMarker(obj.from.line + i, '<span class="text-primary glyphicon glyphicon-pencil"></span>');
  26 + }
7 27
8 - var code = (typeof GBCodePlayBack.htmleditor !=='undefined' && GBCodePlayBack.htmleditor.getValue())  
9 - || (typeof GBCodePlayBack.htmlplayereditor !=='undefined' && GBCodePlayBack.htmlplayereditor.getValue());  
10 - var langid = $('#htmlbutton').data("languageid");  
11 - var input = $('#input').val() || '';  
12 - var compileData = {  
13 - code: code,  
14 - langid: langid,  
15 - input: input  
16 - }  
17 - $.ajax({  
18 - type: "post",  
19 - url: gxb_api + "/submit/submitCode/api",  
20 - data: JSON.stringify(compileData),  
21 - dataType: "json",  
22 - contentType: "application/json",  
23 - success: function(data) {  
24 - compileResult(data)  
25 - l.stop(); 28 + /* 设置鼠标输入指针 */
  29 + playbackcm.setCursor({ line: obj.from.line + i, ch: obj.from.ch });
  30 +
  31 + //以下代码处理其他
  32 + if (obj.text.length === 3 && obj.text[1] !== '' && i === 1) {
  33 + playbackcm.setSelection({ line: obj.from.line + i, ch: 0 });
  34 + } else if (obj.text.length === 3 && obj.text[2] !== '' && i === 2) {
  35 + playbackcm.setSelection({ line: obj.from.line + i, ch: 0 });
  36 +
  37 + //以下代码处理文字块选择并回车的问题
  38 + } else if (obj.text.length === 2 && obj.text[i] === '' && i === 1) {
  39 + playbackcm.setSelection({ line: obj.from.line + i, ch: 0 });
26 40
27 - $('.compile-loading').hide();  
28 - $('.compile-reslut').show();  
29 - GBCodePlayBack.compileResultData = data;  
30 -  
31 - },  
32 - error: function(){  
33 - l.stop();  
34 - alert('错误'); 41 + //以下处理块选择并且粘贴多行问题
  42 + } else {
  43 + if (i == 0) {
  44 + playbackcm.setSelection({ line: obj.from.line + i, ch: obj.from.ch }, { line: obj.to.line + i, ch: obj.to.ch });
  45 + } else {
  46 + playbackcm.setSelection({ line: obj.from.line + i, ch: 0 }, { line: obj.from.line + i, ch: 0 });
  47 + }
35 } 48 }
36 - });  
37 -}  
38 49
39 -function compileMode(el, userId, languageId) {  
40 - var l = Ladda.create(el);  
41 - l.start();  
42 - // 获取标准输入值  
43 - var runtimeArgus = $('#runtimeArgus').val() || '';  
44 - var mainPath = Dir.mainPath;  
45 - var _fileList = Dir.getTreeData(); 50 + if (i !== obj.text.length - 1) {
  51 + playbackcm.replaceSelection(obj.text[i] + '\n');
  52 + } else {
  53 + playbackcm.replaceSelection(obj.text[i]);
  54 + }
  55 + }
46 56
47 - var compileData = {  
48 - "userId": userId,  
49 - "langId": languageId,  
50 - "mainPath": mainPath,  
51 - "mainArgus": "",  
52 - "runtimeArgus": runtimeArgus,  
53 - "rand": "123456",  
54 - "fileList": _fileList || [] 57 + if (obj.next) {
  58 + processChangeObject(playbackcm, obj.next);
55 } 59 }
56 - console.log(compileData);  
57 - $.ajax({  
58 - type: "POST",  
59 - url: gxb_api + "/gxb-web/programmingMulti/codeRun/api",  
60 - data: JSON.stringify(compileData),  
61 - dataType: "json",  
62 - contentType: "application/json",  
63 - success: function(data) {  
64 - console.log(data);  
65 - l.remove();  
66 - },  
67 - error: function(XMLHttpRequest, textStatus, errorThrown) {  
68 - l.remove();  
69 - alert('错误');  
70 - console.log(XMLHttpRequest);  
71 - },  
72 - });  
73 } 60 }
74 61
75 -function 62 +
  63 +// 编译结果
  64 +function compileResult(data){
  65 + if(data.result){
  66 +
  67 + $('#cmpinfo').html('<p class="text-warning">' + data.cmpinfo.replace(/\n/g, "<br />") + "</p>");
  68 + $('#stderr').html('<p class="text-danger">' + data.stderr.replace(/\n/g, "<br />") + "</p>");
  69 + $('#output').html('<p class="text-success">' + data.output.replace(/\n/g, "<br />") + "</p>");
  70 +
  71 + if(data.cmpinfo.length){
  72 + $('#cmprun-tabs a[href="#cmpinfo"]').tab('show');
  73 + }else if(data.stderr.length){
  74 + $('#cmprun-tabs a[href="#stderr"]').tab('show');
  75 + }else if(data.output.length){
  76 + $('#cmprun-tabs a[href="#output"]').tab('show');
  77 + }
  78 +
  79 + if(!data.cmpinfo.length){
  80 + $('#cmpinfo').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 编译已成功</p>');
  81 + }
  82 +
  83 + if(!data.stderr.length){
  84 + $('#stderr').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 无输出错误</p>');
  85 + }
  86 +
  87 + if(!data.output.length){
  88 + $('#output').prepend('<p class="alert alert-warning"><i class="glyphicon glyphicon-exclamation-sign"></i> 代码编译错误或者运行相关功能受限制</p>');
  89 + }
  90 +
  91 + }else{
  92 + $('#cmpinfo').html('<p class="alert alert-danger"><i class="glyphicon glyphicon-exclamation-sign"></i> 云端编译超时,请稍后重新尝试</p>');
  93 + $('#cmprun-tabs a[href="#cmpinfo"]').tab('show');
  94 + }
  95 +}
76 \ No newline at end of file 96 \ No newline at end of file
src/live/student.html
@@ -116,201 +116,10 @@ @@ -116,201 +116,10 @@
116 <script src="../js/bootstrap.js"></script> 116 <script src="../js/bootstrap.js"></script>
117 <script src="../js/ladda/spin.js"></script> 117 <script src="../js/ladda/spin.js"></script>
118 <script src="../js/ladda/ladda.js"></script> 118 <script src="../js/ladda/ladda.js"></script>
119 -<script src="./js/main.js"></script> 119 +<script src="./js/utils.js"></script>
  120 +<script src="./js/student.js"></script>
120 <script> 121 <script>
121 -$(function() {  
122 - var teacherId = document.getElementById('teacher');  
123 - var studentId = document.getElementById('student');  
124 - var socket = io('http://localhost:3000');  
125 122
126 - var teacher = CodeMirror.fromTextArea(teacherId, {  
127 - value: '输入HTML代码',  
128 - mode: 'text/javascript',  
129 - lineNumbers: true,  
130 - smartIndent: false  
131 - });  
132 -  
133 - var student = CodeMirror.fromTextArea(studentId, {  
134 - value: '输入HTML代码',  
135 - mode: 'text/javascript',  
136 - lineNumbers: true,  
137 - smartIndent: false  
138 - });  
139 -  
140 -  
141 - socket.on('teacher.programming', function(msg) {  
142 - console.log(msg);  
143 - var msgObj = JSON.parse(msg)  
144 - // student.setValue(msg)  
145 - processChangeObject(teacher, msgObj);  
146 -  
147 - $('#messages').append($('<li>').text(msg));  
148 - window.scrollTo(0, document.body.scrollHeight);  
149 - });  
150 -  
151 - socket.on('programming.compile', function(msg) {  
152 - console.log('-------------');  
153 - console.log(msg);  
154 - // $('#CompileBtn').trigger('click');  
155 - console.log('编译' + teacher.getValue());  
156 - var el = document.querySelector('#CompileBtn')  
157 - var l = Ladda.create(el);  
158 - l.start();  
159 -  
160 - var input = $('#input').val() || '';  
161 - var code = teacher.getValue();  
162 - var compileData = {  
163 - code: code,  
164 - langid: 10,  
165 - input: input  
166 - }  
167 - $.ajax({  
168 - type: "post",  
169 - url: gxb_api + "/submit/submitCode/api",  
170 - data: JSON.stringify(compileData),  
171 - dataType: "json",  
172 - contentType: "application/json",  
173 - success: function(data) {  
174 - console.log(data);  
175 - l.remove();  
176 - compileResult(data);  
177 - },  
178 - error: function(){  
179 - l.stop();  
180 - alert('错误');  
181 - }  
182 - });  
183 - });  
184 -  
185 -  
186 -  
187 -  
188 -  
189 - function processChangeObject(playbackcm, obj) {  
190 -  
191 - for (var i = 0; i < obj.text.length; i++) {  
192 - /* 设置鼠标行标示 */  
193 - if (playbackcm.getTextArea().id === "HTMLplayer") {  
194 - if (htmlhlLine !== null) {  
195 - playbackcm.clearMarker(htmlhlLine);  
196 - }  
197 - htmlhlLine = playbackcm.setMarker(obj.from.line + i, '<span class="text-primary glyphicon glyphicon-pencil"></span>');  
198 - } else if (playbackcm.getTextArea().id === "CSSplayer") {  
199 - if (csshlLine !== null) {  
200 - playbackcm.clearMarker(csshlLine);  
201 - }  
202 - csshlLine = playbackcm.setMarker(obj.from.line + i, '<span class="text-primary glyphicon glyphicon-pencil"></span>');  
203 - } else if (playbackcm.getTextArea().id === "JSplayer") {  
204 - if (jshlLine !== null) {  
205 - playbackcm.clearMarker(jshlLine);  
206 - }  
207 - jshlLine = playbackcm.setMarker(obj.from.line + i, '<span class="text-primary glyphicon glyphicon-pencil"></span>');  
208 - }  
209 -  
210 - /* 设置鼠标输入指针 */  
211 - playbackcm.setCursor({ line: obj.from.line + i, ch: obj.from.ch });  
212 -  
213 - //以下代码处理其他  
214 - if (obj.text.length === 3 && obj.text[1] !== '' && i === 1) {  
215 - playbackcm.setSelection({ line: obj.from.line + i, ch: 0 });  
216 - } else if (obj.text.length === 3 && obj.text[2] !== '' && i === 2) {  
217 - playbackcm.setSelection({ line: obj.from.line + i, ch: 0 });  
218 -  
219 - //以下代码处理文字块选择并回车的问题  
220 - } else if (obj.text.length === 2 && obj.text[i] === '' && i === 1) {  
221 - playbackcm.setSelection({ line: obj.from.line + i, ch: 0 });  
222 -  
223 - //以下处理块选择并且粘贴多行问题  
224 - } else {  
225 - if (i == 0) {  
226 - playbackcm.setSelection({ line: obj.from.line + i, ch: obj.from.ch }, { line: obj.to.line + i, ch: obj.to.ch });  
227 - } else {  
228 - playbackcm.setSelection({ line: obj.from.line + i, ch: 0 }, { line: obj.from.line + i, ch: 0 });  
229 - }  
230 - }  
231 -  
232 - if (i !== obj.text.length - 1) {  
233 - playbackcm.replaceSelection(obj.text[i] + '\n');  
234 - } else {  
235 - playbackcm.replaceSelection(obj.text[i]);  
236 - }  
237 - }  
238 -  
239 - if (obj.next) {  
240 - processChangeObject(playbackcm, obj.next);  
241 - }  
242 - }  
243 -  
244 -  
245 -  
246 - $('#CompileBtn').on('click', function(){  
247 - console.log('编译' + teacher.getValue());  
248 - var el = document.querySelector('#CompileBtn')  
249 - var l = Ladda.create(el);  
250 - l.start();  
251 -  
252 - var input = $('#input').val() || '';  
253 - var code = teacher.getValue();  
254 - var compileData = {  
255 - code: code,  
256 - langid: 10,  
257 - input: input  
258 - }  
259 - $.ajax({  
260 - type: "post",  
261 - url: gxb_api + "/submit/submitCode/api",  
262 - data: JSON.stringify(compileData),  
263 - dataType: "json",  
264 - contentType: "application/json",  
265 - success: function(data) {  
266 - console.log(data);  
267 - l.remove();  
268 - compileResult(data);  
269 - },  
270 - error: function(){  
271 - l.stop();  
272 - alert('错误');  
273 - }  
274 - });  
275 - })  
276 -  
277 -  
278 -  
279 - // 编译结果  
280 - function compileResult(data){  
281 - if(data.result){  
282 -  
283 - $('#cmpinfo').html('<p class="text-warning">' + data.cmpinfo.replace(/\n/g, "<br />") + "</p>");  
284 - $('#stderr').html('<p class="text-danger">' + data.stderr.replace(/\n/g, "<br />") + "</p>");  
285 - $('#output').html('<p class="text-success">' + data.output.replace(/\n/g, "<br />") + "</p>");  
286 -  
287 - if(data.cmpinfo.length){  
288 - $('#cmprun-tabs a[href="#cmpinfo"]').tab('show');  
289 - }else if(data.stderr.length){  
290 - $('#cmprun-tabs a[href="#stderr"]').tab('show');  
291 - }else if(data.output.length){  
292 - $('#cmprun-tabs a[href="#output"]').tab('show');  
293 - }  
294 -  
295 - if(!data.cmpinfo.length){  
296 - $('#cmpinfo').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 编译已成功</p>');  
297 - }  
298 -  
299 - if(!data.stderr.length){  
300 - $('#stderr').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 无输出错误</p>');  
301 - }  
302 -  
303 - if(!data.output.length){  
304 - $('#output').prepend('<p class="alert alert-warning"><i class="glyphicon glyphicon-exclamation-sign"></i> 代码编译错误或者运行相关功能受限制</p>');  
305 - }  
306 -  
307 - }else{  
308 - $('#cmpinfo').html('<p class="alert alert-danger"><i class="glyphicon glyphicon-exclamation-sign"></i> 云端编译超时,请稍后重新尝试</p>');  
309 - $('#cmprun-tabs a[href="#cmpinfo"]').tab('show');  
310 - }  
311 - }  
312 -  
313 -});  
314 </script> 123 </script>
315 124
316 </body> 125 </body>
src/live/style/main.css
@@ -101,6 +101,7 @@ button{ @@ -101,6 +101,7 @@ button{
101 101
102 #stdin { 102 #stdin {
103 position: absolute; 103 position: absolute;
  104 + left: 0;
104 width: 100%; 105 width: 100%;
105 } 106 }
106 107
src/live/teacher.html
@@ -103,7 +103,8 @@ @@ -103,7 +103,8 @@
103 <script src="../js/ladda/spin.js"></script> 103 <script src="../js/ladda/spin.js"></script>
104 <script src="../js/ladda/ladda.js"></script> 104 <script src="../js/ladda/ladda.js"></script>
105 <!-- <script src="./js/IDELive.js"></script> --> 105 <!-- <script src="./js/IDELive.js"></script> -->
106 -<script src="./js/main.js"></script> 106 +<script src="./js/utils.js"></script>
  107 +<script src="./js/teacher.js"></script>
107 108
108 </body> 109 </body>
109 110