Commit fc1e371bf47bec5118bd2c71c949a37835abb912

Authored by ykxie
1 parent 7869a178

add function

src/live/js/main.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 + socket.emit('teacher.programming', changeObjStr);
  20 +
  21 + socket.emit('programming.content', teacher.getValue());
  22 +
  23 + buildOperate('teacher', changeObj);
  24 +
  25 + console.log(IDELive.operations);
  26 +
  27 + });
  28 +
  29 + // 链接时执行初始化代码
  30 + socket.on('programming.content', function(msg) {
  31 + console.log('programming.content ---- ' + msg);
  32 + teacher.setValue(msg);
  33 + });
  34 +
  35 + var IDELive = {
  36 + operations: [] // 存储录制时的动作对象
  37 + }
  38 +
  39 +
  40 +
  41 +
  42 +
  43 + $('#CompileBtn').on('click', function(){
  44 + console.log('编译' + teacher.getValue());
  45 + var el = document.querySelector('#CompileBtn')
  46 + var l = Ladda.create(el);
  47 + l.start();
  48 +
  49 + var input = $('#input').val() || '';
  50 + var code = teacher.getValue();
  51 + var compileData = {
  52 + code: code,
  53 + langid: 10,
  54 + input: input
  55 + }
  56 + $.ajax({
  57 + type: "post",
  58 + url: gxb_api + "/submit/submitCode/api",
  59 + data: JSON.stringify(compileData),
  60 + dataType: "json",
  61 + contentType: "application/json",
  62 + success: function(data) {
  63 + console.log(data);
  64 + l.remove();
  65 + compileResult(data);
  66 + },
  67 + error: function(){
  68 + l.stop();
  69 + alert('错误');
  70 + }
  71 + });
  72 + })
  73 +
  74 +
  75 +
  76 + /**
  77 + * 组合录入代码
  78 + * by Kira 2017-5-17
  79 + */
  80 + function buildOperate(editor, changeobj){
  81 + var intervaltime,
  82 + currenttime = new Date().getTime();
  83 +
  84 + var intervaltime = currenttime - IDELive.record_startime;
  85 +
  86 + var operateObj = {
  87 + intervaltime: intervaltime,
  88 + editor: editor,
  89 + changeobj: changeobj,
  90 + currenttime: currenttime,
  91 + trigger: 0
  92 + };
  93 + IDELive.operations.push( operateObj); // 添加每次输入对象
  94 + IDELive.record_startime = currenttime; //设定起始时间
  95 + }
  96 +
  97 + // 编译结果
  98 + function compileResult(data){
  99 + if(data.result){
  100 +
  101 + $('#cmpinfo').html('<p class="text-warning">' + data.cmpinfo.replace(/\n/g, "<br />") + "</p>");
  102 + $('#stderr').html('<p class="text-danger">' + data.stderr.replace(/\n/g, "<br />") + "</p>");
  103 + $('#output').html('<p class="text-success">' + data.output.replace(/\n/g, "<br />") + "</p>");
  104 +
  105 + if(data.cmpinfo.length){
  106 + $('#cmprun-tabs a[href="#cmpinfo"]').tab('show');
  107 + }else if(data.stderr.length){
  108 + $('#cmprun-tabs a[href="#stderr"]').tab('show');
  109 + }else if(data.output.length){
  110 + $('#cmprun-tabs a[href="#output"]').tab('show');
  111 + }
  112 +
  113 + if(!data.cmpinfo.length){
  114 + $('#cmpinfo').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 编译已成功</p>');
  115 + }
  116 +
  117 + if(!data.stderr.length){
  118 + $('#stderr').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 无输出错误</p>');
  119 + }
  120 +
  121 + if(!data.output.length){
  122 + $('#output').prepend('<p class="alert alert-warning"><i class="glyphicon glyphicon-exclamation-sign"></i> 代码编译错误或者运行相关功能受限制</p>');
  123 + }
  124 +
  125 + }else{
  126 + $('#cmpinfo').html('<p class="alert alert-danger"><i class="glyphicon glyphicon-exclamation-sign"></i> 云端编译超时,请稍后重新尝试</p>');
  127 + $('#cmprun-tabs a[href="#cmpinfo"]').tab('show');
  128 + }
  129 + }
  130 +})
0 \ No newline at end of file 131 \ No newline at end of file
src/live/js/utils.js 0 → 100644
src/live/style/main.css
@@ -148,14 +148,18 @@ body { @@ -148,14 +148,18 @@ body {
148 } 148 }
149 149
150 .compile-btn { 150 .compile-btn {
151 - background: #FFF;  
152 - border: 1px solid #3ad5f5;  
153 - color: #1FB6FF;  
154 border-radius: 24px; 151 border-radius: 24px;
  152 + color: #FFF;
  153 + background-image: -webkit-linear-gradient(left, #1FB6FF 0%, #62DCF5 100%);
  154 + background-image: linear-gradient(to right, #1FB6FF 0%, #62DCF5 100%);
  155 + -webkit-transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) all !important;
  156 + transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) all !important;
  157 + box-shadow: 0px 0px 2px 0px #B3E5FF;
  158 + border: none;
155 } 159 }
156 160
157 .btn { 161 .btn {
158 - padding: 3px 18px; 162 + padding: 5px 18px;
159 } 163 }
160 164
161 .fb { 165 .fb {
@@ -171,6 +175,7 @@ body { @@ -171,6 +175,7 @@ body {
171 .live-ctrl { 175 .live-ctrl {
172 width: 100%; 176 width: 100%;
173 height: 60px; 177 height: 60px;
  178 + line-height: 60px;
174 position: absolute; 179 position: absolute;
175 bottom: 0; 180 bottom: 0;
176 z-index: 999; 181 z-index: 999;
@@ -178,3 +183,24 @@ body { @@ -178,3 +183,24 @@ body {
178 background-color: #23383f; 183 background-color: #23383f;
179 box-sizing: border-box; 184 box-sizing: border-box;
180 } 185 }
  186 +
  187 +#resultoutput{
  188 + padding: 10px 16px;
  189 +}
  190 +
  191 +.ladda-button[data-style=expand-right] .ladda-spinner{
  192 + right: 4px;
  193 +}
  194 +.ladda-button[data-style=expand-right][data-loading]{
  195 + padding-right: 40px;
  196 +}
  197 +.ladda-button .ladda-spinner{
  198 + top: 0;
  199 +}
  200 +
  201 +.start-end{
  202 + float: left;
  203 +}
  204 +.save-cancel{
  205 + float: right;
  206 +}
src/live/teacher.html
@@ -7,139 +7,12 @@ @@ -7,139 +7,12 @@
7 <link href="../css/reset.css" rel="stylesheet"> 7 <link href="../css/reset.css" rel="stylesheet">
8 <link rel="stylesheet" href="../css/responsive/css/bootstrap.min.css"> 8 <link rel="stylesheet" href="../css/responsive/css/bootstrap.min.css">
9 <link rel="stylesheet" href="../js/codemirror-5.25.0/lib/codemirror.css"> 9 <link rel="stylesheet" href="../js/codemirror-5.25.0/lib/codemirror.css">
  10 + <link rel="stylesheet" href="../js/ladda/ladda-themeless.min.css">
  11 + <link rel="stylesheet" href="style/main.css">
10 12
11 - <style>  
12 - * {  
13 - margin: 0;  
14 - padding: 0;  
15 - box-sizing: border-box;  
16 - }  
17 -  
18 - body {  
19 - font: 13px Helvetica, Arial;  
20 - }  
21 - .live-wrap{  
22 - position: absolute;  
23 - width: 100%;  
24 - height: 100%;  
25 - overflow: hidden;  
26 - }  
27 - .header{  
28 - text-align: center;  
29 - border-bottom: 1px solid #c1c1c1;  
30 - padding: 8px 0;  
31 - }  
32 - .header h1{  
33 - font-size: 18px;  
34 - margin: 0;  
35 - }  
36 - .live-code{  
37 - position: relative;  
38 - width: 100%;  
39 - height: 100%;  
40 - padding-bottom: 296px;  
41 - }  
42 - .live-code .CodeMirror{  
43 - height: 100%;  
44 - }  
45 - .live-console-wrap{  
46 - width: 100%;  
47 - background-color: #FFF;  
48 - height: 200px;  
49 - position: absolute;  
50 - bottom: 60px;  
51 - z-index: 999;  
52 - overflow: hidden;  
53 - }  
54 - #toolbar{  
55 - width: 100%;  
56 - height: 40px;  
57 - overflow: hidden;  
58 - background-color: #F4F6F9;  
59 - padding: 0 36px;  
60 - }  
61 - .result-tabs{  
62 - overflow: hidden;  
63 - margin: 5px 10px;  
64 - color: #fff;  
65 - }  
66 - .text{  
67 - color: #1FB6FF;  
68 - }  
69 - .result-tabs>li.active>a, .result-tabs>li.active>a:hover, .result-tabs>li>a:hover, .result-tabs>li.active>a:focus{  
70 - color: #FFF;  
71 - background-image: -webkit-linear-gradient(left, #1FB6FF 0%, #62DCF5 100%);  
72 - background-image: linear-gradient(to right, #1FB6FF 0%, #62DCF5 100%);  
73 - -webkit-transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) all !important;  
74 - transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) all !important;  
75 - box-shadow: 0px 0px 2px 0px #B3E5FF;  
76 - border: none;  
77 - }  
78 - .result-tabs>li>a, .result-tabs>li.active>a:hover{  
79 - padding: 4px 21px;  
80 - border: none;  
81 - margin: 1px;  
82 - border-radius: 15px;  
83 - font-size: 14px;  
84 - transition: all 0.1s ease;  
85 - }  
86 - .func{  
87 - height: 36px;  
88 - padding-top: 5px;  
89 - }  
90 - .stdin-wrap {  
91 - margin: 0 48px;  
92 - position: relative;  
93 - }  
94 - #stdin {  
95 - position: absolute;  
96 - width: 100%;  
97 - }  
98 - #stdin :focus{outline: none;}  
99 -  
100 - #stdin input[type="text"]{font: 15px/24px "Lato", Arial, sans-serif; color: #333; width: 100%; box-sizing: border-box; letter-spacing: 1px;padding-left: 12px;}  
101 -  
102 - #stdin .effect-2{border: 0; padding: 12px 0 1px; border-bottom: 1px solid #ccc;}  
103 - #stdin .effect-2 ~ .focus-border{position: absolute; bottom: 0; left: 50%; width: 0; height: 2px; background-color: #62DCF5; transition: 1s;}  
104 - #stdin .effect-2:focus ~ .focus-border{width: 100%; transition: 1s; left: 0;}  
105 - .nav-tabs {  
106 - border: none;  
107 - float: left;  
108 - border-bottom: 0;  
109 - }  
110 - .panel-body{  
111 - padding: 0;  
112 - }  
113 -  
114 - .compile-btn {  
115 - background: #FFF;  
116 - border: 1px solid #3ad5f5;  
117 - color: #1FB6FF;  
118 - border-radius: 24px;  
119 - }  
120 - .btn {  
121 - padding: 3px 18px;  
122 - }  
123 - .fb {  
124 - float: right;  
125 - margin: 0 16px;  
126 - cursor: pointer;  
127 - }  
128 - .fb img {  
129 - width: 32px;  
130 - }  
131 -  
132 - .live-ctrl{  
133 - width: 100%;  
134 - height: 60px;  
135 - position: absolute;  
136 - bottom: 0;  
137 - z-index: 999;  
138 - padding: 0 136px;  
139 - background-color: #23383f;  
140 - box-sizing: border-box;  
141 - }  
142 - </style> 13 + <script>
  14 + var gxb_api = "https://restful.gaoxiaobang.com";
  15 + </script>
143 </head> 16 </head>
144 17
145 <body> 18 <body>
@@ -191,14 +64,18 @@ @@ -191,14 +64,18 @@
191 <div class="tab-pane padall15" id="stderr"></div> 64 <div class="tab-pane padall15" id="stderr"></div>
192 <div class="tab-pane padall15" id="output"></div> 65 <div class="tab-pane padall15" id="output"></div>
193 </div> 66 </div>
194 - <div class="panel-body no-compile" id="ifrcontainer">  
195 - <iframe id="resultiframe" frameBorder="0" width="100%"></iframe>  
196 - </div>  
197 </div> 67 </div>
198 68
199 <!-- 录制控制区 --> 69 <!-- 录制控制区 -->
200 <div class="live-ctrl"> 70 <div class="live-ctrl">
201 - 71 + <div class="start-end">
  72 + <button class="btn compile-btn" id="">开始</button>
  73 + <button class="btn compile-btn" id="">结束</button>
  74 + </div>
  75 + <div class="save-cancel">
  76 + <button class="btn compile-btn" id="">保存</button>
  77 + <button class="btn compile-btn" id="">关闭</button>
  78 + </div>
202 </div> 79 </div>
203 </div> 80 </div>
204 81
@@ -207,39 +84,10 @@ @@ -207,39 +84,10 @@
207 <script src="https://code.jquery.com/jquery-1.11.1.js"></script> 84 <script src="https://code.jquery.com/jquery-1.11.1.js"></script>
208 <script src="../js/codemirror-5.25.0/lib/codemirror.js"></script> 85 <script src="../js/codemirror-5.25.0/lib/codemirror.js"></script>
209 <script src="../js/bootstrap.js"></script> 86 <script src="../js/bootstrap.js"></script>
210 -<script>  
211 - $(function() {  
212 - var teacherId = document.getElementById('teacher');  
213 - var socket = io('http://localhost:3000');  
214 -  
215 - // 初始化codemirror页面  
216 - var teacher = CodeMirror.fromTextArea(teacherId, {  
217 - value: '输入HTML代码',  
218 - mode: 'text/javascript',  
219 - lineNumbers: true,  
220 - smartIndent: false  
221 - });  
222 -  
223 - // 记录每次操作的变化  
224 - CodeMirror.on(teacher,"change", function(instance, changeObj) {  
225 - console.log(instance);  
226 - console.log(changeObj);  
227 - var changeObjStr = JSON.stringify(changeObj);  
228 -  
229 - socket.emit('teacher.programming', changeObjStr);  
230 -  
231 - socket.emit('programming.content', teacher.getValue());  
232 -  
233 - });  
234 -  
235 - // 链接时执行初始化代码  
236 - socket.on('programming.content', function(msg) {  
237 - console.log('programming.content ---- ' + msg);  
238 - teacher.setValue(msg);  
239 - }); 87 +<script src="../js/ladda/spin.js"></script>
  88 +<script src="../js/ladda/ladda.js"></script>
  89 +<script src="./js/main.js"></script>
240 90
241 - });  
242 -</script>  
243 </body> 91 </body>
244 92
245 </html> 93 </html>