@@ -21,8 +21,13 @@ var helloDisplay = {
21
21
// Get the gistID from the URL and display it
22
22
23
23
if ( document . URL . indexOf ( '#' ) >= 0 ) {
24
- var gistID = document . URL . split ( '#' ) [ 1 ] ;
25
- this . displayGist ( gistID ) ;
24
+ var sketchID = document . URL . split ( '#' ) [ 1 ] ;
25
+
26
+ if ( sketchID [ 0 ] == "@" ) {
27
+ this . displayGallery ( sketchID . substr ( 1 ) ) ;
28
+ } else {
29
+ this . displayGist ( sketchID ) ;
30
+ }
26
31
}
27
32
28
33
$ ( "#displayCode" ) . click ( function ( ) {
@@ -66,37 +71,66 @@ var helloDisplay = {
66
71
67
72
var gistFiles = data . responseJSON . files ,
68
73
gistFile = gistFiles [ Object . keys ( gistFiles ) [ 0 ] ] ,
69
- gistSource = gistFile . content ,
70
- processingCanvas ,
71
- processingInstance ,
72
- displayHeight ,
73
- displayWidth ;
74
-
75
- helloDisplay . processingSource = gistSource ;
76
- helloDisplay . editor . setValue ( gistSource , - 1 ) ;
77
-
78
- try {
79
- processingCanvas = document . getElementById ( "displayCanvas" ) ;
80
- processingInstance = new Processing ( processingCanvas , gistSource ) ;
81
-
82
- displayHeight = 400 ;
83
- displayWidth = ( processingInstance . width / processingInstance . height ) * displayHeight ;
84
-
85
- $ ( "#displayCanvas" ) . css ( {
86
- width : displayWidth ,
87
- height : displayHeight
88
- } ) ;
89
-
90
- $ ( "#displayCanvasBox" ) . css ( {
91
- width : displayWidth + ( $ ( "#displayInfo" ) . outerWidth ( ) + 10 ) ,
92
- height : displayHeight ,
93
- marginTop : displayHeight / - 2 ,
94
- marginLeft : ( displayWidth + $ ( "#displayInfo" ) . outerWidth ( ) + 10 ) / - 2
95
- } ) ;
96
- } catch ( e ) {
97
- console . log ( "ERROR! " + e . toString ( ) ) ;
98
- }
74
+ gistSource = gistFile . content ;
75
+
76
+ helloDisplay . showSketch ( gistSource ) ;
99
77
}
100
78
} ) ;
79
+ } ,
80
+ /**
81
+ * Fetch sketch code Parse
82
+ */
83
+ displayGallery : function ( parseID ) {
84
+
85
+ Parse . initialize ( "x8FmMInL8BbVeBqonPzgvS8WNKbPro65Li5DzTI0" , "Y7PPNnhLPhCdFMAKgw7amBxGerz67gAnG3UKb53s" ) ;
86
+
87
+ var GalleryObject = Parse . Object . extend ( "Gallery" ) ;
88
+ var query = new Parse . Query ( GalleryObject ) ;
89
+ query . get ( parseID , {
90
+ success : function ( gallery ) {
91
+ helloDisplay . showSketch ( gallery . get ( "source" ) ) ;
92
+ } ,
93
+ error : function ( object , error ) {
94
+ // The object was not retrieved successfully.
95
+ // error is a Parse.Error with an error code and message.
96
+ }
97
+ } ) ;
98
+
99
+ } ,
100
+ /**
101
+ * Feed sourceto Processing.js
102
+ */
103
+ showSketch : function ( source ) {
104
+
105
+ var processingCanvas ,
106
+ processingInstance ,
107
+ displayHeight ,
108
+ displayWidth ;
109
+
110
+ helloDisplay . processingSource = source ;
111
+ helloDisplay . editor . setValue ( source , - 1 ) ;
112
+
113
+ try {
114
+ processingCanvas = document . getElementById ( "displayCanvas" ) ;
115
+ processingInstance = new Processing ( processingCanvas , source ) ;
116
+
117
+ displayHeight = 400 ;
118
+ displayWidth = ( processingInstance . width / processingInstance . height ) * displayHeight ;
119
+
120
+ $ ( "#displayCanvas" ) . css ( {
121
+ width : displayWidth ,
122
+ height : displayHeight
123
+ } ) ;
124
+
125
+ $ ( "#displayCanvasBox" ) . css ( {
126
+ width : displayWidth + ( $ ( "#displayInfo" ) . outerWidth ( ) + 10 ) ,
127
+ height : displayHeight ,
128
+ marginTop : displayHeight / - 2 ,
129
+ marginLeft : ( displayWidth + $ ( "#displayInfo" ) . outerWidth ( ) + 10 ) / - 2
130
+ } ) ;
131
+ } catch ( e ) {
132
+ console . log ( "ERROR! " + e . toString ( ) ) ;
133
+ }
134
+
101
135
}
102
136
} ;
0 commit comments