Commit 918556f991b21c7817f06677285b4b4297cd1f49

Authored by ykxie
1 parent 6792eda2

修改编译结构

Showing 1 changed file with 130 additions and 104 deletions
src/js/gbreplayer.js
@@ -38,6 +38,7 @@ $(function(){ @@ -38,6 +38,7 @@ $(function(){
38 isgblibreplay: 0, 38 isgblibreplay: 0,
39 continue_recording: 0, //是否继续自动保`存的录制 39 continue_recording: 0, //是否继续自动保`存的录制
40 recording_status: 1, //当前是否在录制 40 recording_status: 1, //当前是否在录制
  41 + isRcording: 0, // 判断当前是否在录制 0:未录制 1:录制中
41 recordinit: function(codereplaytype, preload) { 42 recordinit: function(codereplaytype, preload) {
42 /* #STRAT:生成CodeMirror Editor for JS/CSS/HTML */ 43 /* #STRAT:生成CodeMirror Editor for JS/CSS/HTML */
43 var htmlid = document.getElementById('HTMLeditor'), 44 var htmlid = document.getElementById('HTMLeditor'),
@@ -984,109 +985,8 @@ $(function(){ @@ -984,109 +985,8 @@ $(function(){
984 GBCodePlayBack.replay_enhancement = !GBCodePlayBack.replay_enhancement; 985 GBCodePlayBack.replay_enhancement = !GBCodePlayBack.replay_enhancement;
985 }); 986 });
986 987
987 - // 使用服务端编译语言  
988 - $('#comprunbtngrp').unbind("click").on('click', '#comprun', function(event){  
989 - event.preventDefault();  
990 - var l = Ladda.create(this);  
991 - $('#comprun').find('ladda-spinner').remove();  
992 - l.start();  
993 - var runStatus = $("#comprun").data('run');  
994 -  
995 - if(runStatus == 1){  
996 - Hourglass.pauseTimer(); // 暂停计时器  
997 - recorder.pause(); // 音频暂停  
998 - }  
999 - $("#comprun").data('run', 0);  
1000 - // 暂停录制  
1001 - var pauseState = $('#pause').data('pause');  
1002 - if(pauseState == 1 && _role == 0){  
1003 - GBCodePlayBack.record_pause_time = new Date().getTime(); // 暂停的时间  
1004 - var recordobj = {  
1005 - intervaltime: GBCodePlayBack.record_pause_time - GBCodePlayBack.record_startime,  
1006 - editor: 'html',  
1007 - changeobj: {  
1008 - from:{  
1009 - ch: 0,  
1010 - line: 0,  
1011 - },  
1012 - text: '',  
1013 - to:{  
1014 - ch: 0,  
1015 - line: 0,  
1016 - }  
1017 - },  
1018 - trigger: 0,  
1019 - playTime: 0  
1020 - };  
1021 - GBCodePlayBack.records.push(recordobj);  
1022 -  
1023 - $('#pause').data('status', '1');  
1024 - $('#pause').data('pause', '0');  
1025 - $('#pause').removeClass('hidden').addClass('show');  
1026 - $('#start-recording').hide();  
1027 -  
1028 - $('.pause-shodow').removeClass('hidden').addClass('show');  
1029 -  
1030 - }  
1031 -  
1032 - var code = (typeof GBCodePlayBack.htmleditor !=='undefined' && GBCodePlayBack.htmleditor.getValue())  
1033 - || (typeof GBCodePlayBack.htmlplayereditor !=='undefined' && GBCodePlayBack.htmlplayereditor.getValue());  
1034 - var langid = $('#htmlbutton').data("languageid");  
1035 - var input = $('#input').val() || '';  
1036 - var compileData = {  
1037 - code: code,  
1038 - langid: langid,  
1039 - input: input  
1040 - }  
1041 - $.ajax({  
1042 - type: "post",  
1043 - url: gxb_api + "/submit/submitCode/api",  
1044 - data: JSON.stringify(compileData),  
1045 - dataType: "json",  
1046 - contentType: "application/json",  
1047 - success: function(data) {  
1048 - compileResult(data)  
1049 - l.stop();  
1050 -  
1051 - $('.compile-loading').hide();  
1052 - $('.compile-reslut').show();  
1053 - GBCodePlayBack.compileResultData = data;  
1054 -  
1055 - },  
1056 - error: function(){  
1057 - l.stop();  
1058 - alert('错误');  
1059 - }  
1060 - });  
1061 - });  
1062 988
1063 989
1064 - // 保存编译结果  
1065 - $('#save_compile').unbind("click").click(function(){  
1066 - var length = GBCodePlayBack.records.length - 1;  
1067 - Hourglass.pauseTimer();  
1068 - $("#comprun").data('run', 1);  
1069 - GBCodePlayBack.records[length].compile = GBCodePlayBack.compileResultData;  
1070 -  
1071 - GBCodePlayBack.records[length].output = GBCodePlayBack.compileResultData.output;  
1072 - GBCodePlayBack.records[length].stderr = GBCodePlayBack.compileResultData.stderr;  
1073 - GBCodePlayBack.records[length].cmpinfo = GBCodePlayBack.compileResultData.cmpinfo;  
1074 - GBCodePlayBack.records[length].result = GBCodePlayBack.compileResultData.result;  
1075 -  
1076 - GBCodePlayBack.record_continue_time = new Date().getTime();  
1077 -  
1078 - contrlPause();  
1079 -  
1080 - })  
1081 -  
1082 - // 不保存编译结果  
1083 - $('#cancel_compile').unbind('click').click(function(){  
1084 - Hourglass.pauseTimer();  
1085 - $("#comprun").data('run', 1);  
1086 - contrlPause()  
1087 - GBCodePlayBack.record_continue_time = new Date().getTime();  
1088 - })  
1089 -  
1090 // 进度条滚动控制播放进度 990 // 进度条滚动控制播放进度
1091 var $sliderpropress = $(".replayprogress"); 991 var $sliderpropress = $(".replayprogress");
1092 $sliderpropress.slider({}).slider( "option", "disabled", true ); 992 $sliderpropress.slider({}).slider( "option", "disabled", true );
@@ -1360,7 +1260,6 @@ $(function(){ @@ -1360,7 +1260,6 @@ $(function(){
1360 $('#pause').data('status', '0'); 1260 $('#pause').data('status', '0');
1361 } 1261 }
1362 1262
1363 -  
1364 var recordobj = { 1263 var recordobj = {
1365 intervaltime: intervaltime, 1264 intervaltime: intervaltime,
1366 editor: editor, 1265 editor: editor,
@@ -1371,6 +1270,7 @@ $(function(){ @@ -1371,6 +1270,7 @@ $(function(){
1371 }; 1270 };
1372 GBCodePlayBack.records.push(recordobj); 1271 GBCodePlayBack.records.push(recordobj);
1373 GBCodePlayBack.record_startime = currenttime; //设定起始时间 1272 GBCodePlayBack.record_startime = currenttime; //设定起始时间
  1273 + console.log(GBCodePlayBack.records);
1374 }, 1274 },
1375 changeValueCallback: function(record, replay_type, offset) { 1275 changeValueCallback: function(record, replay_type, offset) {
1376 var obj = record.changeobj, 1276 var obj = record.changeobj,
@@ -1525,7 +1425,8 @@ $(function(){ @@ -1525,7 +1425,8 @@ $(function(){
1525 1425
1526 // 开始录制 1426 // 开始录制
1527 $('#start-recording').click(function(){ 1427 $('#start-recording').click(function(){
1528 - // 编译状态 1428 + GBCodePlayBack.isRcording = 1;
  1429 + // 编译状态
1529 var data = $(this).attr('data'); 1430 var data = $(this).attr('data');
1530 var seconds = 0; 1431 var seconds = 0;
1531 $("#countdown").show(); 1432 $("#countdown").show();
@@ -1589,6 +1490,131 @@ $(function(){ @@ -1589,6 +1490,131 @@ $(function(){
1589 }); 1490 });
1590 1491
1591 1492
  1493 +
  1494 + // 使用服务端编译语言
  1495 + $('#comprunbtngrp').unbind("click").on('click', '#comprun', function(event){
  1496 + event.preventDefault();
  1497 + var l = Ladda.create(this);
  1498 + $('#comprun').find('ladda-spinner').remove();
  1499 + l.start();
  1500 +
  1501 + // 是否在录制录制
  1502 + if(!GBCodePlayBack.isRcording){
  1503 + compileRun(l);
  1504 + }else{
  1505 + timerRecord();
  1506 + pushRecords();
  1507 + compileRun(l);
  1508 + }
  1509 +
  1510 + });
  1511 +
  1512 +
  1513 + // 保存编译结果
  1514 + $('#save_compile').unbind("click").click(function(){
  1515 + var length = GBCodePlayBack.records.length - 1;
  1516 + Hourglass.pauseTimer();
  1517 + $("#comprun").data('run', 1);
  1518 + GBCodePlayBack.records[length].compile = GBCodePlayBack.compileResultData;
  1519 +
  1520 + GBCodePlayBack.records[length].output = GBCodePlayBack.compileResultData.output;
  1521 + GBCodePlayBack.records[length].stderr = GBCodePlayBack.compileResultData.stderr;
  1522 + GBCodePlayBack.records[length].cmpinfo = GBCodePlayBack.compileResultData.cmpinfo;
  1523 + GBCodePlayBack.records[length].result = GBCodePlayBack.compileResultData.result;
  1524 +
  1525 + GBCodePlayBack.record_continue_time = new Date().getTime();
  1526 +
  1527 + contrlPause();
  1528 +
  1529 + })
  1530 +
  1531 + // 不保存编译结果
  1532 + $('#cancel_compile').unbind('click').click(function(){
  1533 + Hourglass.pauseTimer();
  1534 + $("#comprun").data('run', 1);
  1535 + contrlPause()
  1536 + GBCodePlayBack.record_continue_time = new Date().getTime();
  1537 + })
  1538 +
  1539 + // 暂停计时、暂停录音
  1540 + function timerRecord(){
  1541 + var runStatus = $("#comprun").data('run');
  1542 + if(runStatus == 1){
  1543 + Hourglass.pauseTimer(); // 暂停计时器
  1544 + recorder.pause(); // 音频暂停
  1545 + }
  1546 + }
  1547 +
  1548 + // 禁止编写代码,添加遮罩
  1549 + function showMask(){
  1550 + $('#pause').data('status', '1');
  1551 + $('#pause').data('pause', '0');
  1552 + $('#pause').removeClass('hidden').addClass('show');
  1553 + $('#start-recording').hide();
  1554 +
  1555 + $('.pause-shodow').removeClass('hidden').addClass('show');
  1556 + }
  1557 +
  1558 + // 给数组插入一个元素
  1559 + function pushRecords(){
  1560 + // 暂停录制
  1561 + var pauseState = $('#pause').data('pause');
  1562 + if(pauseState == 1 && _role == 0){
  1563 + GBCodePlayBack.record_pause_time = new Date().getTime(); // 暂停的时间
  1564 + var recordobj = {
  1565 + intervaltime: GBCodePlayBack.record_pause_time - GBCodePlayBack.record_startime,
  1566 + editor: 'html',
  1567 + changeobj: {
  1568 + from:{
  1569 + ch: 0,
  1570 + line: 0,
  1571 + },
  1572 + text: '',
  1573 + to:{
  1574 + ch: 0,
  1575 + line: 0,
  1576 + }
  1577 + },
  1578 + trigger: 0,
  1579 + playTime: 0
  1580 + };
  1581 + GBCodePlayBack.records.push(recordobj);
  1582 + showMask();
  1583 + }
  1584 + }
  1585 +
  1586 + // 编译
  1587 + function compileRun(l){
  1588 + var code = (typeof GBCodePlayBack.htmleditor !=='undefined' && GBCodePlayBack.htmleditor.getValue()) || (typeof GBCodePlayBack.htmlplayereditor !=='undefined' && GBCodePlayBack.htmlplayereditor.getValue());
  1589 + var langid = $('#htmlbutton').data("languageid");
  1590 + var input = $('#input').val() || '';
  1591 + var compileData = {
  1592 + code: code,
  1593 + langid: langid,
  1594 + input: input
  1595 + }
  1596 + $.ajax({
  1597 + type: "post",
  1598 + url: gxb_api + "/submit/submitCode/api",
  1599 + data: JSON.stringify(compileData),
  1600 + dataType: "json",
  1601 + contentType: "application/json",
  1602 + success: function(data) {
  1603 + compileResult(data)
  1604 + l.stop();
  1605 +
  1606 + $('.compile-loading').hide();
  1607 + $('.compile-reslut').show();
  1608 + GBCodePlayBack.compileResultData = data;
  1609 +
  1610 + },
  1611 + error: function(){
  1612 + l.stop();
  1613 + alert('错误');
  1614 + }
  1615 + });
  1616 + }
  1617 +
1592 // 切换自动/手动运行代码 1618 // 切换自动/手动运行代码
1593 function autoRun(autorun){ 1619 function autoRun(autorun){
1594 if(autorun===1){ 1620 if(autorun===1){
@@ -1743,7 +1769,7 @@ $(function(){ @@ -1743,7 +1769,7 @@ $(function(){
1743 // $('#comprunbtngrp').html('<button id="runnow" type="button" data-style="expand-right" class="btn" title="运行代码">&nbsp; 运行</button>'); 1769 // $('#comprunbtngrp').html('<button id="runnow" type="button" data-style="expand-right" class="btn" title="运行代码">&nbsp; 运行</button>');
1744 }else{ 1770 }else{
1745 $('#fontendrun').addClass('hidden'); 1771 $('#fontendrun').addClass('hidden');
1746 - $('#comprunbtngrp').html('<button id="comprun" type="button" data-run="1" data-style="expand-right" class="btn" title="编译并运行代码">&nbsp;编译&运行</button>'); 1772 + $('#comprunbtngrp').html('<button id="comprun" type="button" data-run="1" data-style="expand-right" class="btn comprun" title="编译并运行代码">&nbsp;编译&运行</button>');
1747 1773
1748 $('#ifrcontainer').addClass('hidden'); 1774 $('#ifrcontainer').addClass('hidden');
1749 $('#cmprun-output').removeClass('hidden'); 1775 $('#cmprun-output').removeClass('hidden');