Skip to content

Commit 88d60e9

Browse files
committed
Display page updates for gallery per #64
1 parent 093dade commit 88d60e9

File tree

2 files changed

+69
-32
lines changed

2 files changed

+69
-32
lines changed

display/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ <h4 class="modal-title" id="codeModalTitle">Processing Code</h4>
6868
</div><!-- /.modal -->
6969

7070
<!-- End Modal Code Window -->
71+
72+
<script src="//www.parsecdn.com/js/parse-1.3.1.min.js"></script>
73+
7174
<script src="/js/vendor/ace/ace.js" type="text/javascript" charset="utf-8"></script>
7275
<script src="/js/vendor/FileSaver.min.js" type="text/javascript"></script>
7376

js/display.js

Lines changed: 66 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ var helloDisplay = {
2121
// Get the gistID from the URL and display it
2222

2323
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+
}
2631
}
2732

2833
$("#displayCode").click(function () {
@@ -66,37 +71,66 @@ var helloDisplay = {
6671

6772
var gistFiles = data.responseJSON.files,
6873
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);
9977
}
10078
});
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+
101135
}
102136
};

0 commit comments

Comments
 (0)