@@ -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,13 +322,19 @@ $(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 = this . id . split ( "_" ) [ 1 ]
325- console . log ( id , this . id , __code_cell_count )
326331 delete_cell ( id )
327332} )
328333
329334
335+ /**
336+ * Adds a code cell on button add-code click
337+ */
330338$ ( document ) . on ( "click" , "button.add-code" , function ( ) {
331339 let where ;
332340 if ( this . id . split ( "_" ) . includes ( "down" ) ) {
@@ -337,23 +345,32 @@ $(document).on("click", "button.add-code", function () {
337345 add_new_code_cell ( this . id , where )
338346} )
339347
348+ /**
349+ * Adds a markdown cell on button add-text click
350+ */
340351$ ( document ) . on ( "click" , "button.add-text" , function ( ) {
341352 let where ;
342353 if ( this . id . split ( "_" ) . includes ( "down" ) ) {
343354 where = "down"
344355 } else {
345356 where = "up"
346357 }
347- // console.log(this.id);
348358 add_new_text_cell ( this . id , where )
349359} )
350360
361+
362+ /**
363+ * Displays text box on double click of a text
364+ */
351365$ ( document ) . on ( "dblclick" , "textarea.text-box" , function ( ) {
352366 let id = this . id . split ( "_" ) [ 1 ]
353367 show_md ( id , this . value )
354368
355369} )
356370
371+ /**
372+ * Displays rendered Markdown text
373+ */
357374function show_md ( id , value ) {
358375 div_id = `text-div_${ id } `
359376 md_texts [ div_id ] = value //stores the markdown text for the corresponding div
@@ -362,18 +379,23 @@ function show_md(id, value) {
362379 document . getElementById ( div_id ) . style . display = "none"
363380}
364381
382+ /**
383+ * Displays rendered Markdown on double click
384+ */
365385$ ( document ) . on ( "dblclick" , "div.text-out-box" , function ( ) {
366386 let id = this . id . split ( "_" ) [ 1 ]
367387 md_id = `text-div_${ id } `
368388 out_id = `out-text-div_${ id } `
369- // md_txt = md_texts[md_id]
370-
371389 document . getElementById ( md_id ) . style . display = "block"
372390 document . getElementById ( out_id ) . style . display = "none"
373391
374392} )
375393
376394
395+
396+ /**
397+ * Helper function to update text box size dynamically
398+ */
377399function update_text_box_size ( ) {
378400 $ ( 'textarea' ) . each ( function ( ) {
379401 this . setAttribute ( 'style' , 'height:' + ( this . scrollHeight ) + 'px;overflow-y:hidden;' ) ;
@@ -384,6 +406,9 @@ function update_text_box_size() {
384406}
385407
386408
409+ /**
410+ * Initiates download function for Notebook
411+ */
387412$ ( "#download" ) . click ( function ( ) {
388413 let out = notebook_json ( cells_order , vars_in_scope , md_texts ) ;
389414
@@ -402,7 +427,9 @@ $("#download").click(function () {
402427} ) ;
403428
404429
405-
430+ /**
431+ * Internal function to import new Notebook
432+ */
406433$ ( "#import-notebook-file" ) . change ( ( ) => {
407434
408435 let files = $ ( "#import-notebook-file" ) [ 0 ] . files
@@ -420,68 +447,18 @@ $("#import-notebook-file").change(() => {
420447 }
421448 reader . readAsText ( content ) ;
422449 }
423- // $("#uploadNoteModal").modal('hide');
450+ $ ( "#uploadNoteModal" ) . modal ( 'hide' ) ;
424451} )
425452
426- // $("#uploadnb").click(function () {
427-
428- // var files = $("#import-notebook-file")[0].files
429- // let json_content = null
430- // if (files.length > 0) {
431- // var content = files[0];
432- // var reader = new FileReader();
433- // reader.onload = function (t) {
434- // json_content = t.target.result;
435- // let json = JSON.parse(json_content)
436-
437- // $(".content").empty()
438-
439- // load_notebook(json);
440- // }
441- // reader.readAsText(content);
442- // }
443- // })
444-
445-
446- // rewireLoggingToElement(
447- // () => document.getElementById("log"),
448- // () => document.getElementById("log-container"), true);
449-
450- // function rewireLoggingToElement(eleLocator, eleOverflowLocator, autoScroll) {
451- // fixLoggingFunc('log');
452- // fixLoggingFunc('debug');
453- // fixLoggingFunc('warn');
454- // fixLoggingFunc('error');
455- // fixLoggingFunc('info');
456-
457-
458- // function fixLoggingFunc(name) {
459- // console['old' + name] = console[name];
460- // console[name] = function (...arguments) {
461- // const output = produceOutput(name, arguments);
462- // const eleLog = eleLocator();
463-
464- // if (autoScroll) {
465- // const eleContainerLog = eleOverflowLocator();
466- // const isScrolledToBottom = eleContainerLog.scrollHeight - eleContainerLog.clientHeight <= eleContainerLog.scrollTop + 1;
467- // eleLog.innerHTML += output + "<br>";
468- // if (isScrolledToBottom) {
469- // eleContainerLog.scrollTop = eleContainerLog.scrollHeight - eleContainerLog.clientHeight;
470- // }
471- // } else {
472- // eleLog.innerHTML += output + "<br>";
473- // }
474-
475- // console['old' + name].apply(undefined, arguments);
476- // };
477- // }
478-
479- // function produceOutput(name, args) {
480- // return args.reduce((output, arg) => {
481- // return output +
482- // "<span class=\"log-" + (typeof arg) + " log-" + name + "\">" +
483- // (typeof arg === "object" && (JSON || {}).stringify ? JSON.stringify(arg) : arg) +
484- // "</span> ";
485- // }, '');
486- // }
487- // }
453+
454+ /**
455+ * Helper function to update text box size dynamically
456+ */
457+ function update_text_box_size ( ) {
458+ $ ( 'textarea' ) . each ( function ( ) {
459+ this . setAttribute ( 'style' , 'height:' + ( this . scrollHeight ) + 'px;overflow-y:hidden;' ) ;
460+ } ) . on ( 'input' , function ( ) {
461+ this . style . height = 'auto' ;
462+ this . style . height = ( this . scrollHeight ) + 'px' ;
463+ } ) ;
464+ }
0 commit comments