|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +/** |
| 4 | + * Singleton for gallery page |
| 5 | + */ |
| 6 | +var helloGallery = { |
| 7 | + pageNumber: 0, |
| 8 | + itemsPerPage: 16, |
| 9 | + /** |
| 10 | + * Initialize gallery page |
| 11 | + */ |
| 12 | + init: function () { |
| 13 | + |
| 14 | + // Get the gistID from the URL and display it |
| 15 | + |
| 16 | + if (document.URL.indexOf('#') >= 0) { |
| 17 | + helloGallery.pageNumber = document.URL.split('#')[1]; |
| 18 | + } |
| 19 | + |
| 20 | + Parse.initialize("x8FmMInL8BbVeBqonPzgvS8WNKbPro65Li5DzTI0", "Y7PPNnhLPhCdFMAKgw7amBxGerz67gAnG3UKb53s"); |
| 21 | + |
| 22 | + var GalleryObject = Parse.Object.extend("Gallery"); |
| 23 | + var query = new Parse.Query(GalleryObject); |
| 24 | + query.limit(helloGallery.itemsPerPage); |
| 25 | + query.skip(helloGallery.pageNumber * helloGallery.itemsPerPage); |
| 26 | + query.descending("createdAt"); |
| 27 | + |
| 28 | + query.find({ |
| 29 | + success: function(results) { |
| 30 | + //alert("Successfully retrieved " + results.length + " scores."); |
| 31 | + // Do something with the returned Parse.Object values |
| 32 | + for (var i = 0; i < results.length; i++) { |
| 33 | + var object = results[i]; |
| 34 | + //alert(object.id + ' - ' + object.get('playerName')); |
| 35 | + |
| 36 | + var data = { |
| 37 | + link: "http://" + $(location).attr('hostname') + (($(location).attr('port') !== "") ? ":" + $(location).attr('port') : "") + "/display/#@" + object.id, |
| 38 | + image: object.get("image").url() |
| 39 | + } |
| 40 | + |
| 41 | + var template = $('#template').html(); |
| 42 | + Mustache.parse(template); |
| 43 | + var rendered = Mustache.render(template, data); |
| 44 | + $('#galleryView').append(rendered); |
| 45 | + |
| 46 | + |
| 47 | + } |
| 48 | + }, |
| 49 | + error: function(error) { |
| 50 | + //alert("Error: " + error.code + " " + error.message); |
| 51 | + } |
| 52 | + }); |
| 53 | + |
| 54 | + |
| 55 | + } |
| 56 | +}; |
0 commit comments