@@ -351,4 +351,53 @@ $(document).mouseup(function (e) {
351351} ) ;
352352$module_container . on ( 'DOMMouseScroll mousewheel' , '.module_wrapper' , function ( e ) {
353353 tm . findOwner ( this ) . mousewheel ( e ) ;
354- } ) ;
354+ } ) ;
355+
356+ // Share scratch paper
357+
358+ var getParameterByName = function ( name ) {
359+ url = window . location . href ;
360+ name = name . replace ( / [ \[ \] ] / g, "\\$&" ) ;
361+ var regex = new RegExp ( "[?&]" + name + "(=([^&#]*)|&|#|$)" ) ,
362+ results = regex . exec ( url ) ;
363+ if ( ! results ) return null ;
364+ if ( ! results [ 2 ] ) return '' ;
365+ return decodeURIComponent ( results [ 2 ] . replace ( / \+ / g, " " ) ) ;
366+ } ;
367+
368+
369+ $ ( document ) . ready ( function ( ) {
370+ if ( / [ ? & ] s c r a t c h - p a p e r = / . test ( location . search ) ) {
371+ var gistID = getParameterByName ( 'scratch-paper' ) ;
372+ console . log ( gistID ) ;
373+ loadScratchPaper ( gistID ) ;
374+ }
375+ } ) ;
376+
377+ var shareScratchPaper = function ( ) {
378+ var json = {
379+ "data" : dataEditor . getValue ( ) ,
380+ "code" : codeEditor . getValue ( )
381+ } ;
382+ var gist = {
383+ "description" : "Shared scratch paper" ,
384+ "public" : true ,
385+ "files" : {
386+ "scratch-paper.json" : {
387+ "content" : JSON . stringify ( json )
388+ }
389+ }
390+ } ;
391+ $ . post ( "https://api.github.com/gists" , JSON . stringify ( gist ) , function ( res ) {
392+ var data = JSON . parse ( res ) ;
393+ console . log ( window . location . origin + "\/?scratch-paper=" + data . id ) ;
394+ } ) ;
395+ } ;
396+
397+ var loadScratchPaper = function ( gistID ) {
398+ $ . get ( "https://api.github.com/gists/" + gistID , function ( res ) {
399+ var data = JSON . parse ( res ) ;
400+ var content = data . files [ "scratch-paper.json" ] . content ;
401+ console . log ( content ) ;
402+ } ) ;
403+ } ;
0 commit comments