@@ -204,6 +204,7 @@ var helloEditor = {
204
204
$ ( "#shareButton" ) . click ( function ( ) {
205
205
helloEditor . confirmExit = false ;
206
206
helloEditor . createGist ( ) ;
207
+ //helloEditor.addToGallery();
207
208
} ) ;
208
209
209
210
$ ( "#resetExample" ) . click ( function ( ) {
@@ -620,38 +621,91 @@ var helloEditor = {
620
621
$ ( '#errorModalText' ) . html ( outputMessage ) ;
621
622
$ ( '#errorModal' ) . modal ( 'show' ) ;
622
623
} ,
624
+
623
625
/**
624
- * Creates a new Gist with editor contents and shows share modal
626
+ * Adds to the gallery hosted on Parse
627
+ */
628
+ addToGallery : function ( ) {
629
+
630
+ // Post to Parse
631
+
632
+ Parse . initialize ( "x8FmMInL8BbVeBqonPzgvS8WNKbPro65Li5DzTI0" , "Y7PPNnhLPhCdFMAKgw7amBxGerz67gAnG3UKb53s" ) ;
633
+
634
+ var processingSource = this . editor . getValue ( ) ;
635
+ if ( ! ( / s i z e \( \s * \d + \s * , \s * \d + \s * \) / . test ( processingSource ) ) ) {
636
+ processingSource = "size(500,400);\n\n" + processingSource ;
637
+ }
638
+
639
+ var processingCanvas = document . getElementById ( "editorCanvas" ) ,
640
+ uri = processingCanvas . toDataURL ( 'image/jpeg' ) ,
641
+ base64 = uri . slice ( uri . indexOf ( ',' ) + 1 ) ,
642
+ processingImage = new Parse . File ( "sketch.jpg" , { base64 : base64 } ) ;
643
+
644
+ var galleryData = {
645
+ source : processingSource
646
+ } ;
647
+
648
+ processingImage . save ( ) . then ( function ( ) {
649
+
650
+ var gallery = new Parse . Object ( "Gallery" ) ;
651
+ gallery . set ( "source" , processingSource ) ;
652
+ gallery . set ( "image" , processingImage ) ;
653
+ gallery . save ( galleryData ) . then ( function ( object ) {
654
+ var displayURL = "http://" + $ ( location ) . attr ( 'hostname' ) + ( ( $ ( location ) . attr ( 'port' ) !== "" ) ? ":" + $ ( location ) . attr ( 'port' ) : "" ) + "/display/#@" + object . id ;
655
+ helloEditor . showShare ( displayURL ) ;
656
+ } ) ;
657
+
658
+
659
+ } , function ( error ) {
660
+ console . log ( "Error saving gallery image" ) ;
661
+ } ) ;
662
+
663
+ // var GalleryObject = Parse.Object.extend("Gallery");
664
+ // var gallery = new GalleryObject();
665
+ // gallery.save(galleryData).then(function(object) {
666
+ // var displayURL = "http://" + $(location).attr('hostname') + (($(location).attr('port') !== "") ? ":" + $(location).attr('port') : "") + "/display/#@" + object.id;
667
+ // helloEditor.showShare(displayURL);
668
+ // });
669
+
670
+
671
+ } ,
672
+
673
+ /**
674
+ * Creates a new Gist with editor contents and shows the share modal
625
675
*/
626
676
createGist : function ( ) {
627
677
628
678
var processingSource = this . editor . getValue ( ) ,
629
679
postURL = "https://api.github.com/gists" ,
630
- postData = {
680
+ postData ;
681
+
682
+ if ( ! ( / s i z e \( \s * \d + \s * , \s * \d + \s * \) / . test ( processingSource ) ) ) {
683
+ processingSource = "size(500,400);\n\n" + processingSource ;
684
+ }
685
+
686
+ postData = {
631
687
"description" : "Save for Processing Hour of Code" ,
632
688
"public" : true ,
633
689
"files" : {
634
690
"demo.pde" : {
635
691
"content" : processingSource
636
692
}
637
693
}
638
- } ;
639
-
640
- if ( ! ( / s i z e \( \s * \d + \s * , \s * \d + \s * \) / . test ( processingSource ) ) ) {
641
- processingSource = "size(500,400);\n\n" + processingSource ;
642
- }
694
+ } ;
643
695
644
696
$ . post ( postURL , JSON . stringify ( postData ) )
645
697
. done ( function ( data ) {
646
- var gistID = data . id ,
647
- displayURL = "http://" + $ ( location ) . attr ( 'hostname' ) + ( ( $ ( location ) . attr ( 'port' ) !== "" ) ? ":" + $ ( location ) . attr ( 'port' ) : "" ) + "/display/#" + gistID ;
698
+ var displayURL = "http://" + $ ( location ) . attr ( 'hostname' ) + ( ( $ ( location ) . attr ( 'port' ) !== "" ) ? ":" + $ ( location ) . attr ( 'port' ) : "" ) + "/display/#" + data . id ;
699
+ helloEditor . showShare ( displayURL ) ;
700
+ } ) ;
648
701
649
- $ ( '#shareModal' ) . attr ( 'data-url' , displayURL ) ;
702
+ } ,
703
+ showShare : function ( displayURL ) {
650
704
651
- $ ( '#shareModalLink' ) . html ( $ ( "<a/>" ) . attr ( { 'href' : displayURL , target : "_blank" } ) . html ( displayURL ) ) ;
652
- $ ( '#shareModal' ) . modal ( 'show' ) ;
705
+ $ ( '#shareModal' ) . attr ( 'data-url' , displayURL ) ;
653
706
654
- } ) ;
707
+ $ ( '#shareModalLink' ) . html ( $ ( "<a/>" ) . attr ( { 'href' : displayURL , target : "_blank" } ) . html ( displayURL ) ) ;
708
+ $ ( '#shareModal' ) . modal ( 'show' ) ;
655
709
656
710
} ,
657
711
showRulers : function ( ) {
0 commit comments