@@ -39,9 +39,11 @@ function exec_cell(c_id) {
3939 let output = ( "global" , eval ) ( vars_in_scope [ id ] . getValue ( ) )
4040 if ( Array . isArray ( output ) ) {
4141 output = print_val ( output )
42- } else if ( typeof output === 'object' && output !== null ) {
42+ }
43+ else if ( typeof output === 'object' && output !== null ) {
4344 output = JSON . stringify ( output )
44- } else if ( console ) {
45+ }
46+ else if ( console ) {
4547 //retreive value from the console funcction
4648 console . oldLog = console . log ;
4749 console . log = function ( value ) {
@@ -51,7 +53,10 @@ function exec_cell(c_id) {
5153 if ( Array . isArray ( output ) ) {
5254 output = print_val ( output )
5355 } else {
54- output = JSON . stringify ( output )
56+ if ( typeof output === 'object' && output !== null ) {
57+ output = JSON . stringify ( output )
58+ }
59+
5560 }
5661 }
5762
@@ -285,15 +290,15 @@ $(document).on("click", "button.add-text", function () {
285290 add_new_text_cell ( this . id , where )
286291} )
287292
288- $ ( document ) . on ( "dblclick" , "textarea.text-box" , function ( ) {
289- let id = this . id . split ( "_" ) [ 1 ]
290- show_md ( id , this . value )
293+ // $(document).on("dblclick", "textarea.text-box", function () {
294+ // let id = this.id.split("_")[1]
295+ // show_md(id, this.value)
291296
292- } )
297+ // })
293298
294299function show_md ( id , value ) {
295300 div_id = `text-div_${ id } `
296- // md_texts[div_id] = value //stores the markdown text for the corresponding div
301+ md_texts [ div_id ] = value //stores the markdown text for the corresponding div
297302 render_md = md . render ( value )
298303 $ ( `#out-text-div_${ id } ` ) . html ( render_md ) . show ( )
299304 document . getElementById ( div_id ) . style . display = "none"
@@ -322,6 +327,36 @@ function update_text_box_size() {
322327
323328
324329$ ( "#download" ) . click ( function ( ) {
325- let out = notebook_json ( vars_in_scope ) ;
326- console . log ( out ) ;
330+ let out = notebook_json ( vars_in_scope , md_texts ) ;
331+
332+ var blob = new Blob ( [ out ] , { "type" : "application/json" } ) ;
333+ var url = ( window . URL || window . webkitURL ) . createObjectURL ( blob ) ;
334+
335+ var link = document . createElement ( 'a' ) ;
336+ link . download = 'danfo_notebook.json' ;
337+ link . href = url ;
338+
339+ var link_pae = $ ( link ) ;
340+ $ ( "body" ) . append ( link_pae ) ; //maybe needed
341+ link . click ( ) ;
342+ link_pae . remove ( ) ;
327343} ) ;
344+
345+ $ ( "#uploadnb" ) . click ( function ( ) {
346+
347+ var files = $ ( "#import-notebook-file" ) [ 0 ] . files
348+ let json_content = null
349+ if ( files . length > 0 ) {
350+ var content = files [ 0 ] ;
351+ var reader = new FileReader ( ) ;
352+ reader . onload = function ( t ) {
353+ json_content = t . target . result ;
354+ let json = JSON . parse ( json_content )
355+
356+ $ ( ".content" ) . empty ( )
357+
358+ load_notebook ( json ) ;
359+ }
360+ reader . readAsText ( content ) ;
361+ }
362+ } )
0 commit comments