You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 7, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: runestone/activecode/js/activecode.js
+75-51Lines changed: 75 additions & 51 deletions
Original file line number
Diff line number
Diff line change
@@ -36,19 +36,19 @@ import embed from "vega-embed";
36
36
window.vegaEmbed=embed;
37
37
38
38
varisMouseDown=false;
39
-
document.onmousedown=function(){
39
+
document.onmousedown=function(){
40
40
isMouseDown=true;
41
41
};
42
42
43
-
document.onmouseup=function(){
43
+
document.onmouseup=function(){
44
44
isMouseDown=false;
45
45
};
46
46
window.edList={};
47
47
48
48
varsocket,connection,doc;
49
49
varchatcodesServer="chat.codes";
50
50
51
-
CodeMirror.commands.autocomplete=function(cm){
51
+
CodeMirror.commands.autocomplete=function(cm){
52
52
cm.showHint({hint: CodeMirror.hint.anyword});
53
53
};
54
54
@@ -135,7 +135,7 @@ export class ActiveCode extends RunestoneBase {
135
135
}
136
136
this.addCaption("runestone");
137
137
setTimeout(
138
-
function(){
138
+
function(){
139
139
this.editor.refresh();
140
140
}.bind(this),
141
141
1000
@@ -145,6 +145,9 @@ export class ActiveCode extends RunestoneBase {
145
145
$(this.runButtonHandler.bind(this));
146
146
}
147
147
this.indicate_component_ready();
148
+
if(typeofPrism!=="undefined"){
149
+
Prism.highlightElement(this.containerDiv);
150
+
}
148
151
}
149
152
150
153
createEditor(index){
@@ -190,15 +193,15 @@ export class ActiveCode extends RunestoneBase {
190
193
});
191
194
// Make the editor resizable
192
195
$(editor.getWrapperElement()).resizable({
193
-
resize: function(){
196
+
resize: function(){
194
197
editor.setSize($(this).width(),$(this).height());
195
198
editor.refresh();
196
199
},
197
200
});
198
201
// give the user a visual cue that they have changed but not saved
199
202
editor.on(
200
203
"change",
201
-
function(ev){
204
+
function(ev){
202
205
if(
203
206
editor.acEditEvent==false||
204
207
editor.acEditEvent===undefined
@@ -207,8 +210,10 @@ export class ActiveCode extends RunestoneBase {
207
210
// this avoids unneccsary log events and updates to the activity counter
208
211
// offsetParent === null means that the element is not on the screen and so can't change
209
212
// this.controlDiv.offsetParent
210
-
if(this.origText===editor.getValue()||
211
-
this.addingScrubber){
213
+
if(
214
+
this.origText===editor.getValue()||
215
+
this.addingScrubber
216
+
){
212
217
console.log("Fake change event, skipping the log");
213
218
return;
214
219
}
@@ -232,16 +237,16 @@ export class ActiveCode extends RunestoneBase {
232
237
}.bind(this)
233
238
);// use bind to preserve *this* inside the on handler.
234
239
//Solving Keyboard Trap of ActiveCode: If user use tab for navigation outside of ActiveCode, then change tab behavior in ActiveCode to enable tab user to tab out of the textarea
235
-
$(window).keydown(function(e){
240
+
$(window).keydown(function(e){
236
241
varcode=e.keyCode ? e.keyCode : e.which;
237
242
if(code==9&&$("textarea:focus").length===0){
238
243
editor.setOption("extraKeys",{
239
-
Tab: function(cm){
244
+
Tab: function(cm){
240
245
$(document.activeElement)
241
246
.closest(".tab-content")
242
247
.nextSibling.focus();
243
248
},
244
-
"Shift-Tab": function(cm){
249
+
"Shift-Tab": function(cm){
245
250
$(document.activeElement)
246
251
.closest(".tab-content")
247
252
.previousSibling.focus();
@@ -361,7 +366,7 @@ export class ActiveCode extends RunestoneBase {
361
366
this.showHideButt=butt;
362
367
ctrlDiv.appendChild(butt);
363
368
$(butt).click(
364
-
function(){
369
+
function(){
365
370
$(this.codeDiv).toggle();
366
371
if(this.historyScrubber==null){
367
372
this.addHistoryScrubber(true);
@@ -407,7 +412,7 @@ export class ActiveCode extends RunestoneBase {
407
412
this.atButton=butt;
408
413
ctrlDiv.appendChild(butt);
409
414
$(butt).click(
410
-
function(){
415
+
function(){
411
416
newAudioTour(
412
417
this.divid,
413
418
this.code,
@@ -426,7 +431,7 @@ export class ActiveCode extends RunestoneBase {
426
431
this.shareButt=butt;
427
432
ctrlDiv.appendChild(butt);
428
433
$(butt).click(
429
-
asyncfunction(){
434
+
asyncfunction(){
430
435
if(
431
436
!confirm(
432
437
"You are about to share this code with ALL of your students. Are you sure you want to continue?"
@@ -440,7 +445,8 @@ export class ActiveCode extends RunestoneBase {
440
445
lang: this.language,
441
446
};
442
447
letrequest=newRequest(
443
-
eBookConfig.ajaxURL+"broadcast_code.json",{
448
+
eBookConfig.ajaxURL+"broadcast_code.json",
449
+
{
444
450
method: "POST",
445
451
headers: this.jsonHeaders,
446
452
body: JSON.stringify(data),
@@ -467,7 +473,7 @@ export class ActiveCode extends RunestoneBase {
467
473
$(plabel).text("Pair?");
468
474
ctrlDiv.appendChild(plabel);
469
475
$(checkPartner).click(
470
-
function(){
476
+
function(){
471
477
if(this.partner){
472
478
this.partner=false;
473
479
$(partnerTextBox).hide();
@@ -479,8 +485,8 @@ export class ActiveCode extends RunestoneBase {
479
485
if(!didAgree){
480
486
didAgree=confirm(
481
487
"Pair Programming should only be used with the consent of your instructor."+
482
-
"Your partner must be a registered member of the class and have agreed to pair with you."+
483
-
"By clicking OK you certify that both of these conditions have been met."
488
+
"Your partner must be a registered member of the class and have agreed to pair with you."+
489
+
"By clicking OK you certify that both of these conditions have been met."
484
490
);
485
491
if(didAgree){
486
492
localStorage.setItem("partnerAgree","true");
@@ -499,7 +505,7 @@ export class ActiveCode extends RunestoneBase {
499
505
ctrlDiv.appendChild(partnerTextBox);
500
506
$(partnerTextBox).hide();
501
507
$(partnerTextBox).change(
502
-
function(){
508
+
function(){
503
509
this.partner=partnerTextBox.value;
504
510
}.bind(this)
505
511
);
@@ -523,21 +529,21 @@ export class ActiveCode extends RunestoneBase {
523
529
$(butt).attr(
524
530
"href",
525
531
"http://"+
526
-
chatcodesServer+
527
-
"/new?"+
528
-
$.param({
529
-
topic: window.location.host+"-"+this.divid,
530
-
code: this.editor.getValue(),
531
-
lang: "Python",
532
-
})
532
+
chatcodesServer+
533
+
"/new?"+
534
+
$.param({
535
+
topic: window.location.host+"-"+this.divid,
536
+
code: this.editor.getValue(),
537
+
lang: "Python",
538
+
})
533
539
);
534
540
this.chatButton=butt;
535
541
chatBar.appendChild(butt);
536
-
varupdateChatCodesChannels=function(){
542
+
varupdateChatCodesChannels=function(){
537
543
vardata=doc.data;
538
544
vari=1;
539
545
$(channels).html("");
540
-
data["channels"].forEach(function(channel){
546
+
data["channels"].forEach(function(channel){
541
547
if(!channel.archived&&topic===channel.topic){
542
548
varlink=$("<a />");
543
549
varhref=
@@ -580,14 +586,16 @@ export class ActiveCode extends RunestoneBase {
0 commit comments