@@ -112,7 +112,11 @@ var executeDataAndCode = function () {
112112 } ) . fail ( onFail ) ;
113113 } ) . fail ( onFail ) ;
114114 }
115- setPath ( category , algorithm , isScratchPaper ( category ) ? null : file ) ;
115+ if ( isScratchPaper ( category ) ) {
116+ setPath ( category , loadedScratch ) ;
117+ } else {
118+ setPath ( category , algorithm , file ) ;
119+ }
116120 } ;
117121 var checkLoading = function ( ) {
118122 if ( loading ) {
@@ -265,14 +269,13 @@ var executeDataAndCode = function () {
265269 setPath ( category , algorithm ) ;
266270 } ;
267271 var list = { } ;
268- var anyOpened = false ;
269272 $ . getJSON ( './algorithm/category.json' , function ( data ) {
270273 var path = getPath ( ) ;
271274 var requestedCategory = path [ 'category' ] ,
272275 requestedAlgorithm = path [ 'algorithm' ] ,
273276 requestedFile = path [ 'file' ] ;
274- var anyRequested = requestedCategory && requestedAlgorithm ;
275- anyOpened = false ;
277+ var anyRequested = requestedCategory ;
278+ var anyOpened = false ;
276279 var $selectedCategory = null , $selectedAlgorithm = null ;
277280
278281 list = data ;
@@ -318,8 +321,12 @@ var executeDataAndCode = function () {
318321 if ( anyOpened ) {
319322 $selectedCategory . click ( ) ;
320323 $selectedAlgorithm . click ( ) ;
321- } else if ( anyRequested && isScratchPaper ( requestedCategory ) ) {
322- loadScratchPaper ( requestedAlgorithm ) ;
324+ } else if ( isScratchPaper ( requestedCategory ) ) {
325+ if ( requestedAlgorithm ) {
326+ loadScratchPaper ( requestedAlgorithm ) ;
327+ } else {
328+ loadAlgorithm ( 'scratch' ) ;
329+ }
323330 } else {
324331 showErrorToast ( 'Oops! This link appears to be broken.' ) ;
325332 $ ( '#scratch-paper' ) . click ( ) ;
@@ -607,8 +614,10 @@ var executeDataAndCode = function () {
607614 } ;
608615 $ . post ( 'https://api.github.com/gists' , JSON . stringify ( gist ) , function ( res ) {
609616 var data = JSON . parse ( res ) ;
610- setPath ( 'scratch' , data . id ) ;
617+ loadedScratch = data . id ;
618+ setPath ( 'scratch' , loadedScratch ) ;
611619 if ( callback ) callback ( location . href ) ;
620+ $ ( '#algorithm' ) . html ( 'Shared' ) ;
612621 } ) ;
613622 } ;
614623
0 commit comments