@@ -302,14 +302,16 @@ function delete_cell(id) {
302302 } else {
303303 row_id = `cell-${ Number ( id ) } `
304304 var div_ele = document . getElementById ( row_id ) ;
305- // console.log(row_id, $(`#${row_id}`).parent().id)
306305 div_ele . parentNode . removeChild ( div_ele ) ;
307306 __code_cell_count -= 1
308307 }
309308
310309}
311310
312311
312+ /**
313+ * Executes a cell on button run click
314+ */
313315$ ( document ) . on ( "click" , "button.run" , function ( ) {
314316 if ( this . id . split ( "_" ) . includes ( "md" ) ) {
315317 let id = this . id . split ( "-" ) [ 1 ]
@@ -320,6 +322,10 @@ $(document).on("click", "button.run", function () {
320322 }
321323} )
322324
325+
326+ /**
327+ * Deletes a cell on button delete click
328+ */
323329$ ( document ) . on ( "click" , "button.del" , function ( ) {
324330 let id_split = this . id . split ( "_" )
325331 let id = id_split [ 1 ]
@@ -346,6 +352,9 @@ $(document).on("click", "button.del", function () {
346352} )
347353
348354
355+ /**
356+ * Adds a code cell on button add-code click
357+ */
349358$ ( document ) . on ( "click" , "button.add-code" , function ( ) {
350359 let where ;
351360 if ( this . id . split ( "_" ) . includes ( "down" ) ) {
@@ -356,23 +365,32 @@ $(document).on("click", "button.add-code", function () {
356365 add_new_code_cell ( this . id , where )
357366} )
358367
368+ /**
369+ * Adds a markdown cell on button add-text click
370+ */
359371$ ( document ) . on ( "click" , "button.add-text" , function ( ) {
360372 let where ;
361373 if ( this . id . split ( "_" ) . includes ( "down" ) ) {
362374 where = "down"
363375 } else {
364376 where = "up"
365377 }
366- // console.log(this.id);
367378 add_new_text_cell ( this . id , where )
368379} )
369380
381+
382+ /**
383+ * Displays text box on double click of a text
384+ */
370385$ ( document ) . on ( "dblclick" , "textarea.text-box" , function ( ) {
371386 let id = this . id . split ( "_" ) [ 1 ]
372387 show_md ( id , this . value )
373388
374389} )
375390
391+ /**
392+ * Displays rendered Markdown text
393+ */
376394function show_md ( id , value ) {
377395 div_id = `text-div_${ id } `
378396 md_texts [ div_id ] = value //stores the markdown text for the corresponding div
@@ -381,18 +399,23 @@ function show_md(id, value) {
381399 document . getElementById ( div_id ) . style . display = "none"
382400}
383401
402+ /**
403+ * Displays rendered Markdown on double click
404+ */
384405$ ( document ) . on ( "dblclick" , "div.text-out-box" , function ( ) {
385406 let id = this . id . split ( "_" ) [ 1 ]
386407 md_id = `text-div_${ id } `
387408 out_id = `out-text-div_${ id } `
388- // md_txt = md_texts[md_id]
389-
390409 document . getElementById ( md_id ) . style . display = "block"
391410 document . getElementById ( out_id ) . style . display = "none"
392411
393412} )
394413
395414
415+
416+ /**
417+ * Helper function to update text box size dynamically
418+ */
396419function update_text_box_size ( ) {
397420 $ ( 'textarea' ) . each ( function ( ) {
398421 this . setAttribute ( 'style' , 'height:' + ( this . scrollHeight ) + 'px;overflow-y:hidden;' ) ;
@@ -403,6 +426,9 @@ function update_text_box_size() {
403426}
404427
405428
429+ /**
430+ * Initiates download function for Notebook
431+ */
406432$ ( "#download" ) . click ( function ( ) {
407433 let out = notebook_json ( cells_order , vars_in_scope , md_texts ) ;
408434
@@ -421,7 +447,9 @@ $("#download").click(function () {
421447} ) ;
422448
423449
424-
450+ /**
451+ * Internal function to import new Notebook
452+ */
425453$ ( "#import-notebook-file" ) . change ( ( ) => {
426454
427455 let files = $ ( "#import-notebook-file" ) [ 0 ] . files
@@ -439,68 +467,18 @@ $("#import-notebook-file").change(() => {
439467 }
440468 reader . readAsText ( content ) ;
441469 }
442- // $("#uploadNoteModal").modal('hide');
470+ $ ( "#uploadNoteModal" ) . modal ( 'hide' ) ;
443471} )
444472
445- // $("#uploadnb").click(function () {
446-
447- // var files = $("#import-notebook-file")[0].files
448- // let json_content = null
449- // if (files.length > 0) {
450- // var content = files[0];
451- // var reader = new FileReader();
452- // reader.onload = function (t) {
453- // json_content = t.target.result;
454- // let json = JSON.parse(json_content)
455-
456- // $(".content").empty()
457-
458- // load_notebook(json);
459- // }
460- // reader.readAsText(content);
461- // }
462- // })
463-
464-
465- // rewireLoggingToElement(
466- // () => document.getElementById("log"),
467- // () => document.getElementById("log-container"), true);
468-
469- // function rewireLoggingToElement(eleLocator, eleOverflowLocator, autoScroll) {
470- // fixLoggingFunc('log');
471- // fixLoggingFunc('debug');
472- // fixLoggingFunc('warn');
473- // fixLoggingFunc('error');
474- // fixLoggingFunc('info');
475-
476-
477- // function fixLoggingFunc(name) {
478- // console['old' + name] = console[name];
479- // console[name] = function (...arguments) {
480- // const output = produceOutput(name, arguments);
481- // const eleLog = eleLocator();
482-
483- // if (autoScroll) {
484- // const eleContainerLog = eleOverflowLocator();
485- // const isScrolledToBottom = eleContainerLog.scrollHeight - eleContainerLog.clientHeight <= eleContainerLog.scrollTop + 1;
486- // eleLog.innerHTML += output + "<br>";
487- // if (isScrolledToBottom) {
488- // eleContainerLog.scrollTop = eleContainerLog.scrollHeight - eleContainerLog.clientHeight;
489- // }
490- // } else {
491- // eleLog.innerHTML += output + "<br>";
492- // }
493-
494- // console['old' + name].apply(undefined, arguments);
495- // };
496- // }
497-
498- // function produceOutput(name, args) {
499- // return args.reduce((output, arg) => {
500- // return output +
501- // "<span class=\"log-" + (typeof arg) + " log-" + name + "\">" +
502- // (typeof arg === "object" && (JSON || {}).stringify ? JSON.stringify(arg) : arg) +
503- // "</span> ";
504- // }, '');
505- // }
506- // }
473+
474+ /**
475+ * Helper function to update text box size dynamically
476+ */
477+ function update_text_box_size ( ) {
478+ $ ( 'textarea' ) . each ( function ( ) {
479+ this . setAttribute ( 'style' , 'height:' + ( this . scrollHeight ) + 'px;overflow-y:hidden;' ) ;
480+ } ) . on ( 'input' , function ( ) {
481+ this . style . height = 'auto' ;
482+ this . style . height = ( this . scrollHeight ) + 'px' ;
483+ } ) ;
484+ }
0 commit comments