Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 1797a8b

Browse files
committed
add comments to selectone.js
1 parent de09b1e commit 1797a8b

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

runestone/selectquestion/js/selectone.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ export default class SelectOne extends RunestoneBase {
128128
if (data.toggle) {
129129
var toggleQuestions = this.questions.split(", ");
130130
var toggleUI = "";
131+
// check so that only the first toggle select question on the assignments page has a preview panel created, then all toggle select previews use this same panel
131132
if (!document.getElementById("component-preview")) {
132133
toggleUI +=
133134
'<div id="component-preview" class="col-md-6 toggle-preview" style="z-index: 999;">' +
134135
'<div id="toggle-buttons"></div>' +
135136
'<div id="toggle-preview"></div>' +
136137
'</div>';
137138
}
139+
// dropdown menu containing the question options
138140
toggleUI +=
139141
'<label for="' +
140142
selectorId +
@@ -236,6 +238,7 @@ export default class SelectOne extends RunestoneBase {
236238
return response;
237239
}
238240

241+
// retrieve html source of a question, for use in various toggle functionalities
239242
async getToggleSrc(toggleQuestionID) {
240243
let request = new Request(
241244
"/runestone/admin/htmlsrc?acid=" + toggleQuestionID,
@@ -248,6 +251,7 @@ export default class SelectOne extends RunestoneBase {
248251
return htmlsrc;
249252
}
250253

254+
// on changing the value of toggle select dropdown, render selected question in preview panel, add appropriate buttons, then make preview panel visible
251255
async togglePreview(parentID, toggleOptions) {
252256
var parentDiv = document.getElementById(parentID);
253257
var toggleQuestionSelect = parentDiv.getElementsByTagName("select")[0];
@@ -259,9 +263,8 @@ export default class SelectOne extends RunestoneBase {
259263
selector_id: "toggle-preview",
260264
useRunestoneServices: true,
261265
});
262-
// let pd = document.getElementById(preview_div);
263-
// pd.appendChild(renderGradingComponents(sid, selectedQuestion));
264266

267+
// add "Close Preview" button to the preview panel
265268
let closeButton = document.createElement("button");
266269
$(closeButton).text("Close Preview");
267270
$(closeButton).addClass("btn btn-default");
@@ -275,6 +278,7 @@ export default class SelectOne extends RunestoneBase {
275278
});
276279
$("#toggle-buttons").append(closeButton);
277280

281+
// if "lock" is not in toggle options, then allow adding more buttons to the preview panel
278282
if (!(toggleOptions.includes("lock"))) {
279283
let setButton = document.createElement("button");
280284
$(setButton).text("Select this Problem");
@@ -287,6 +291,7 @@ export default class SelectOne extends RunestoneBase {
287291
);
288292
$("#toggle-buttons").append(setButton);
289293

294+
// if "transfer" in toggle options, and if current question type is Parsons and selected question type is active code, then add "Transfer" button to preview panel
290295
if (toggleOptions.includes("transfer")) {
291296
var optionText;
292297
var currentType;
@@ -317,6 +322,7 @@ export default class SelectOne extends RunestoneBase {
317322
$("#component-preview").show();
318323
}
319324

325+
// on clicking "Select this Problem" button, close preview panel, replace current question in assignments page with selected question, and send request to update grading database
320326
async toggleSet(parentID, selectedQuestion, htmlsrc) {
321327
var selectorId = parentID + "-toggleSelectedQuestion";
322328
document.getElementById(selectorId).innerHTML = ""; // need to check whether this is even necessary
@@ -337,7 +343,9 @@ export default class SelectOne extends RunestoneBase {
337343
$("#" + parentID).data("toggle_current", selectedQuestion);
338344
}
339345

346+
// on clicking "Transfer" button, extract the current text and indentation of the Parsons blocks in the answer space, then paste that into the selected active code question
340347
async toggleTransfer(parentID, selectedQuestion, htmlsrc) {
348+
// retrieve all Parsons lines within the answer space and loop through this list
341349
var currentParsons = document.getElementById(parentID + "-toggleSelectedQuestion").querySelectorAll("div[class^='answer']")[0].getElementsByClassName("prettyprint lang-py");
342350
var currentParsonsClass;
343351
var currentBlockIndent;
@@ -349,23 +357,26 @@ export default class SelectOne extends RunestoneBase {
349357
for (var p = 0; p < currentParsons.length; p++) {
350358
indentCount = 0;
351359
indent = "";
360+
// for Parsons blocks that have built-in indentation in their lines
352361
currentParsonsClass = currentParsons[p].classList[2];
353362
if (currentParsonsClass) {
354363
if (currentParsonsClass.includes("indent")) {
355364
indentCount = parseInt(indentCount) + parseInt(currentParsonsClass.substring(6,currentParsonsClass.length));
356365
}
357366
}
367+
// for Parsons answer spaces with vertical lines that allow student to define their own line indentation
358368
currentBlockIndent = currentParsons[p].parentElement.parentElement.style.left;
359369
if (currentBlockIndent) {
360370
indentCount = parseInt(indentCount) + parseInt(currentBlockIndent.substring(0,currentBlockIndent.indexOf("px")) / 30);
361371
}
362372
for (var d = 0; d < indentCount; d++) {
363373
indent += " ";
364374
}
375+
// retrieve each text snippet of each Parsons line and loop through this list
365376
parsonsLine = currentParsons[p].getElementsByTagName("span");
366377
count = 0;
367378
for (var l = 0; l < parsonsLine.length; l++) {
368-
if (parsonsLine[l].childNodes[0].nodeName == "#text") { // parsons blocks have differing amounts of hierarchy levels (spans within spans)
379+
if (parsonsLine[l].childNodes[0].nodeName == "#text") { // Parsons blocks have differing amounts of hierarchy levels (spans within spans)
369380
if ((p == 0) && (count == 0)) { // need different check than l == 0 because the l numbering doesn't align with location within line due to inconsistent span heirarchy
370381
parsonsLines += indent + parsonsLine[l].innerHTML;
371382
count++;
@@ -383,6 +394,7 @@ export default class SelectOne extends RunestoneBase {
383394
}
384395
}
385396
}
397+
// replace all existing code within selected active code question with extracted Parsons text
386398
var htmlsrcFormer = htmlsrc.substring(0, htmlsrc.indexOf("<textarea") + htmlsrc.split("<textarea")[1].indexOf(">") + 10);
387399
var htmlsrcLatter = htmlsrc.substring(htmlsrc.indexOf("</textarea>"), htmlsrc.length);
388400
htmlsrc = htmlsrcFormer + parsonsLines + htmlsrcLatter;

0 commit comments

Comments
 (0)