@@ -65,7 +65,10 @@ function exec_cell(c_id) {
6565 if ( Array . isArray ( output ) ) {
6666 output = print_val ( output )
6767 } else {
68- output = JSON . stringify ( output )
68+ if ( typeof output === 'object' && output !== null ) {
69+ output = JSON . stringify ( output )
70+ }
71+
6972 }
7073 }
7174
@@ -272,6 +275,7 @@ function delete_cell(id) {
272275 } else {
273276 row_id = `cell-${ Number ( id ) } `
274277 var div_ele = document . getElementById ( row_id ) ;
278+ console . log ( row_id , $ ( `#${ row_id } ` ) . parent ( ) . id )
275279 div_ele . parentNode . removeChild ( div_ele ) ;
276280 __code_cell_count -= 1
277281 }
@@ -294,6 +298,7 @@ $(document).on("click", "button.run", function () {
294298
295299$ ( document ) . on ( "click" , "button.del" , function ( ) {
296300 let id = this . id . split ( "_" ) [ 1 ]
301+ console . log ( id , this . id , __code_cell_count )
297302 delete_cell ( id )
298303} )
299304
@@ -319,15 +324,15 @@ $(document).on("click", "button.add-text", function () {
319324 add_new_text_cell ( this . id , where )
320325} )
321326
322- $ ( document ) . on ( "dblclick" , "textarea.text-box" , function ( ) {
323- let id = this . id . split ( "_" ) [ 1 ]
324- show_md ( id , this . value )
327+ // $(document).on("dblclick", "textarea.text-box", function () {
328+ // let id = this.id.split("_")[1]
329+ // show_md(id, this.value)
325330
326- } )
331+ // })
327332
328333function show_md ( id , value ) {
329334 div_id = `text-div_${ id } `
330- // md_texts[div_id] = value //stores the markdown text for the corresponding div
335+ md_texts [ div_id ] = value //stores the markdown text for the corresponding div
331336 render_md = md . render ( value )
332337 $ ( `#out-text-div_${ id } ` ) . html ( render_md ) . show ( )
333338 document . getElementById ( div_id ) . style . display = "none"
@@ -357,6 +362,36 @@ function update_text_box_size() {
357362
358363
359364$ ( "#download" ) . click ( function ( ) {
360- let out = notebook_json ( vars_in_scope ) ;
361- console . log ( out ) ;
365+ let out = notebook_json ( vars_in_scope , md_texts ) ;
366+
367+ var blob = new Blob ( [ out ] , { "type" : "application/json" } ) ;
368+ var url = ( window . URL || window . webkitURL ) . createObjectURL ( blob ) ;
369+
370+ var link = document . createElement ( 'a' ) ;
371+ link . download = 'danfo_notebook.json' ;
372+ link . href = url ;
373+
374+ var link_pae = $ ( link ) ;
375+ $ ( "body" ) . append ( link_pae ) ; //maybe needed
376+ link . click ( ) ;
377+ link_pae . remove ( ) ;
362378} ) ;
379+
380+ $ ( "#uploadnb" ) . click ( function ( ) {
381+
382+ var files = $ ( "#import-notebook-file" ) [ 0 ] . files
383+ let json_content = null
384+ if ( files . length > 0 ) {
385+ var content = files [ 0 ] ;
386+ var reader = new FileReader ( ) ;
387+ reader . onload = function ( t ) {
388+ json_content = t . target . result ;
389+ let json = JSON . parse ( json_content )
390+
391+ $ ( ".content" ) . empty ( )
392+
393+ load_notebook ( json ) ;
394+ }
395+ reader . readAsText ( content ) ;
396+ }
397+ } )
0 commit comments