Skip to content

Commit 4b09553

Browse files
committed
add docstrings
1 parent f5c9316 commit 4b09553

File tree

2 files changed

+123
-142
lines changed

2 files changed

+123
-142
lines changed

dnotebook/src/public/javascripts/index.js

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
1+
//first editor cell
12
const editor = CodeMirror(document.getElementById('div-1'), {
23
lineNumbers: true,
34
tabSize: 4,
45
mode: 'javascript',
56
theme: 'monokai',
67
value: '',
78
extraKeys: { "Ctrl-Space": "autocomplete" },
8-
autoCloseBrackets: true
9+
autoCloseBrackets: true,
10+
matchBrackets: true
911
});
1012

11-
//run first cell on CTRL ENTER Pressed
13+
//Run first cell on CTRL ENTER Pressed
1214
$(`#div-1`).keydown(function (e) {
1315
if ((e.ctrlKey || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
14-
// document.getElementById("cell_spinner-1").style.display = "block"
15-
// document.getElementById("cell_num-1").style.display = "none"
1616
exec_cell(`run_div-1`);
1717

1818
}
1919
});
2020

2121

22-
23-
var md = new Remarkable()
24-
//Global Params
25-
let vars_in_scope = {
26-
"div-1": editor
27-
}
28-
29-
let cells_order = ["div-1"] // store the cells order
30-
var md_texts = {} //stores markdown text and corresponding div name
31-
var __code_cell_count = 1
32-
33-
3422
$("#div-1")
3523
.mouseover(function () {
3624
$("#btn-actions-1").show()
@@ -41,26 +29,25 @@ $("#div-1")
4129

4230

4331

44-
// function clear_cell() {
45-
// document.getElementById("log-container").style.display = "none"
46-
// $(`#log`).html("")
47-
32+
var md = new Remarkable()
33+
34+
//Global Params
35+
var vars_in_scope = { "div-1": editor }
36+
var cells_order = ["div-1"] // store the cells in order of creation
37+
var md_texts = {} //stores markdown text and corresponding div name
38+
var __code_cell_count = 1 //stores cell count
4839

49-
// }
5040

41+
42+
/**
43+
* Executes a code cell
44+
* @param {String} c_id Id of the code cell
45+
*/
5146
function exec_cell(c_id) {
52-
// document.getElementById("log-container").style.display = "block"
5347
let id = c_id.split("_")[1]
5448
let count = c_id.split("-")[1]
5549
window.current_cell = id;
5650
$(`#out_${id}`).html("")
57-
// console.log(id);
58-
// logger(`log-${id.split("-")[1]}`, `log_container-${id.split("-")[1]}`, true)
59-
60-
61-
// let command = vars_in_scope[id].getValue()
62-
// console.log(command);
63-
// logger(`log-container-${id.split("-")[1]}`, `log-${id.split("-")[1]}`)
6451

6552
try {
6653
let output = ("global", eval)(vars_in_scope[id].getValue())
@@ -73,7 +60,7 @@ function exec_cell(c_id) {
7360
output = ""
7461
}
7562
} else if (command.includes("console.log(")) {
76-
//retreive value from the console funcction
63+
//retreive value from the console function
7764
console.oldLog = console.log;
7865
console.log = function (value) {
7966
return value;
@@ -95,14 +82,9 @@ function exec_cell(c_id) {
9582

9683
}
9784

98-
// $(`#out_${id}`).empty()
99-
// let command = vars_in_scope[id].getValue()
100-
if (command.includes("table") || command.includes("plot") || command.includes("console.log(")){
101-
// $(`#out_${id}`).html("")
102-
$(`#out_${id}`).html(output);
103-
}
104-
// document.getElementById("cell_spinner-1").style.display = "none"
105-
// document.getElementById("cell_num-1").style.display = "block"
85+
if (command.includes("table") || command.includes("plot") || command.includes("console.log(")) {
86+
$(`#out_${id}`).html(output);
87+
}
10688

10789
count = parseInt(count) + 1
10890
let div_count = `div-${count}`
@@ -112,13 +94,16 @@ function exec_cell(c_id) {
11294
$(`#out_${id}`).html("")
11395
$(`#out_${id}`).html(error)
11496
console.log(error)
115-
// document.getElementById("cell_spinner-1").style.display = "none"
116-
// document.getElementById("cell_num-1").style.display = "block"
11797

11898
}
11999
}
120100

121101

102+
/**
103+
* Creates a new cell in specified position
104+
* @param {String} c_id ID of the current cell
105+
* @param {String} where Position to place the cell. (up/down)
106+
*/
122107
function add_new_code_cell(c_id, where) {
123108
__code_cell_count += 1
124109
let last_scope_id = parseInt(Object.keys(vars_in_scope).pop().split("-")[1])
@@ -192,7 +177,8 @@ function add_new_code_cell(c_id, where) {
192177
theme: 'monokai',
193178
value: '',
194179
extraKeys: { "Ctrl-Space": "autocomplete" },
195-
autoCloseBrackets: true
180+
autoCloseBrackets: true,
181+
matchBrackets: true
196182
});
197183
vars_in_scope[`div-${new_id}`] = editor
198184

@@ -208,15 +194,18 @@ function add_new_code_cell(c_id, where) {
208194
//run cell on CTRL-ENTER Pressed
209195
$(`#div-${new_id}`).keydown(function (e) {
210196
if ((e.ctrlKey || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
211-
// document.getElementById("cell_spinner-1").style.display = "block"
212-
// document.getElementById("cell_num-1").style.display = "none"
213197
exec_cell(`run_div-${new_id}`);
214198

215199
}
216200
});
217201

218202
}
219203

204+
/**
205+
* Creates a new text cell in specified position
206+
* @param {String} c_id ID of the current cell
207+
* @param {String} where Position to place the cell. (up/down)
208+
*/
220209
function add_new_text_cell(c_id, where) {
221210
__code_cell_count += 1
222211
let last_scope_id = parseInt(Object.keys(vars_in_scope).pop().split("-")[1])
@@ -287,7 +276,7 @@ function add_new_text_cell(c_id, where) {
287276
cells_order[new_id - 1] = `div_text-${new_id}`
288277
}
289278

290-
console.log(cells_order)
279+
// console.log(cells_order)
291280
vars_in_scope[`div_text-${new_id}`] = ""
292281

293282
update_text_box_size()
@@ -303,13 +292,17 @@ function add_new_text_cell(c_id, where) {
303292

304293
}
305294

295+
/**
296+
* Deletes a cell by specified ID
297+
* @param {*} id
298+
*/
306299
function delete_cell(id) {
307300
if (__code_cell_count == 1) {
308301
document.getElementsByClassName("del").disable = true
309302
} else {
310303
row_id = `cell-${Number(id)}`
311304
var div_ele = document.getElementById(row_id);
312-
console.log(row_id, $(`#${row_id}`).parent().id)
305+
// console.log(row_id, $(`#${row_id}`).parent().id)
313306
div_ele.parentNode.removeChild(div_ele);
314307
__code_cell_count -= 1
315308
}
@@ -323,8 +316,6 @@ $(document).on("click", "button.run", function () {
323316
let val = document.getElementById(`text-box_${id}`).value
324317
show_md(id, val)
325318
} else {
326-
// document.getElementById("cell_spinner-1").style.display = "block"
327-
// document.getElementById("cell_num-1").style.display = "none"
328319
exec_cell(this.id);
329320
}
330321
})

0 commit comments

Comments
 (0)