@@ -324,4 +324,53 @@ $(document).mouseup(function (e) {
324324} ) ;
325325$module_container . bind ( 'DOMMouseScroll mousewheel' , function ( e ) {
326326 _tracer . mousewheel ( e ) ;
327- } ) ;
327+ } ) ;
328+
329+ // Share scratch paper
330+
331+ var getParameterByName = function ( name ) {
332+ url = window . location . href ;
333+ name = name . replace ( / [ \[ \] ] / g, "\\$&" ) ;
334+ var regex = new RegExp ( "[?&]" + name + "(=([^&#]*)|&|#|$)" ) ,
335+ results = regex . exec ( url ) ;
336+ if ( ! results ) return null ;
337+ if ( ! results [ 2 ] ) return '' ;
338+ return decodeURIComponent ( results [ 2 ] . replace ( / \+ / g, " " ) ) ;
339+ }
340+
341+
342+ $ ( document ) . ready ( function ( ) {
343+ if ( / [ ? & ] s c r a t c h - p a p e r = / . test ( location . search ) ) {
344+ var gistID = getParameterByName ( 'scratch-paper' ) ;
345+ console . log ( gistID ) ;
346+ loadScratchPaper ( gistID ) ;
347+ }
348+ } ) ;
349+
350+ var shareScratchPaper = function ( ) {
351+ var json = {
352+ "data" : dataEditor . getValue ( ) ,
353+ "code" : codeEditor . getValue ( )
354+ } ;
355+ var gist = {
356+ "description" : "Shared scratch paper" ,
357+ "public" : true ,
358+ "files" : {
359+ "scratch-paper.json" : {
360+ "content" : JSON . stringify ( json )
361+ }
362+ }
363+ } ;
364+ $ . post ( "https://api.github.com/gists" , JSON . stringify ( gist ) , function ( res ) {
365+ var data = JSON . parse ( res ) ;
366+ console . log ( window . location . origin + "\/?scratch-paper=" + data . id ) ;
367+ } ) ;
368+ } ;
369+
370+ var loadScratchPaper = function ( gistID ) {
371+ $ . get ( "https://api.github.com/gists/" + gistID , function ( res ) {
372+ var data = JSON . parse ( res ) ;
373+ var content = data . files [ "scratch-paper.json" ] . content ;
374+ console . log ( content ) ;
375+ } ) ;
376+ } ;
0 commit comments